Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing map_content when generating schema by Lutaml::Model::Schema::XmlCompiler.to_models(schema) #260

Closed
kwkwan opened this issue Jan 21, 2025 · 0 comments · Fixed by #261
Assignees

Comments

@kwkwan
Copy link
Contributor

kwkwan commented Jan 21, 2025

Consider we have address schema like:

schema = <<XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified">
  <xs:element name="Address" type="Address"/>
  <xs:complexType name="Address" mixed="true">
    <xs:sequence>
      <xs:element name="City" type="xs:string" minOccurs="0"/>
      <xs:element name="ZIP" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
XSD

and address content looks like:

address = <<~ADD
<Address>
  Oxford Street
  <City>London</City>
  <ZIP>E1 6AN</ZIP>
</Address>
ADD

When the class definition is generated by Shale::Schema.from_xml([schema]) using the above mentioned schema, the class will look like:

class Address < Shale::Mapper
  attribute :content, Shale::Type::String
  attribute :city, Shale::Type::String
  attribute :zip, Shale::Type::String

  xml do
    root 'Address'

    map_content to: :content
    map_element 'City', to: :city
    map_element 'ZIP', to: :zip
  end
end

However, when the class definition is generated by Lutaml::Model::Schema::XmlCompiler.to_models(schema) using the same schema, the class will look like:

class Address < Lutaml::Model::Serializable
  attribute :city, String, collection: true
  attribute :zip, String, collection: true

  xml do
    root "Address", mixed: true

    map_element :City, to: :city
    map_element :ZIP, to: :zip
  end
end

When we use the class definition generated by Lutaml::Model to parse the address:

Address.from_xml(address).to_xml
=> "<Address><City>London</City><ZIP>E1 6AN</ZIP></Address>"

The content "Oxford Street" will be missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants