Skip to content

Commit

Permalink
change xsd array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jun 5, 2024
1 parent 4172bc8 commit 26cb1b2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
49 changes: 42 additions & 7 deletions templates/xml-schema.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,58 @@
#}
{%- macro create_element(attribute) -%}
{%- if attribute.dtypes | length == 1 %}
{%- if attribute.dtypes[0] in object_names or attribute.dtypes[0] in enum_names -%}
{%- if attribute.dtypes[0] in object_names -%}

{%- if attribute.multiple is true -%}
<xs:element name="{{attribute.name}}">
<xs:complexType>
<xs:sequence>
<xs:element name="{{attribute.dtypes[0]}}" type="{{attribute.dtypes[0]}}Type" {{ is_multiple(attribute) }}/>
</xs:sequence>
</xs:complexType>
</xs:element>
{%- else -%}
<xs:element name="{{attribute.name}}" type="{{attribute.dtypes[0]}}Type" {{ is_multiple(attribute) }}/>
{%- endif -%}

{%- elif attribute.dtypes[0] in enum_names -%}

<xs:element name="{{attribute.name}}" type="{{attribute.dtypes[0]}}Type" {{ is_multiple(attribute) }}/>

{%- else -%}

<xs:element name="{{attribute.name}}" type="xs:{{attribute.dtypes[0]}}" {{ is_multiple(attribute) }}/>

{%- endif -%}
{%- else -%}
<xs:element name="{{attribute.name}}" {{ is_multiple(attribute) }}/>
<xs:complexType>
<xs:sequence>
{%- for dtype in attribute.dtypes %}
{%- if dtype in object_names or dtype in enum_names %}
<xs:element name="{{dtype}}" type="{{dtype}}" {{ is_multiple(attribute) }}/>
{%- else %}
<xs:element name="{{dtype}}" type="xs:{{dtype}}" {{ is_multiple(attribute) }}/>
{%- endif %}
{%- if dtype in object_names -%}

{%- if attribute.multiple is true -%}
<xs:element name="{{attribute.name}}">
<xs:complexType>
<xs:sequence>
<xs:element name="{{dtype}}" type="{{dtype}}Type" {{ is_multiple(attribute) }}/>
</xs:sequence>
</xs:complexType>
</xs:element>
{%- else -%}
<xs:element name="{{attribute.name}}" type="{{dtype}}Type" {{ is_multiple(attribute) }}/>
{%- endif -%}

{%- elif dtype in enum_names -%}

<xs:element name="{{attribute.name}}" type="{{dtype}}Type" {{ is_multiple(attribute) }}/>

{%- else -%}

<xs:element name="{{attribute.name}}" type="xs:{{dtype}}" {{ is_multiple(attribute) }}/>

{%- endif -%}
{%- endfor %}
{{ enum_names }}
</xs:sequence>
</xs:complexType>
{%- endif %}
Expand Down
8 changes: 7 additions & 1 deletion tests/data/expected_xml_schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<!-- Test Definition -->
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="test2" type="Test2Type" maxOccurs="unbounded"/>
<xs:element name="test2">
<xs:complexType>
<xs:sequence>
<xs:element name="Test2" type="Test2Type" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ontology" type="OntologyType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
Expand Down

0 comments on commit 26cb1b2

Please sign in to comment.