Skip to content

Commit

Permalink
fix: syntax error in generated code using enumerations.
Browse files Browse the repository at this point in the history
Fixes #117.
  • Loading branch information
ngnpope committed Aug 28, 2018
1 parent 0eed4dc commit 4a86c94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion soapfish/templates/lib.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class {{ class_name|capitalize }}(xsd.ComplexType):
{%- if element.simpleType %}
{{ element.name|fix_keyword }} = xsd.Element({{ element.simpleType.restriction|type(known_types) }}(
{%- if element.simpleType.restriction.enumerations -%}
enumeration=[{% for enum in element.simpleType.restriction.enumerations %}'{{ enum.value }}'{% if not loop.last %}, {% endif %}{% endfor %}]
enumeration=[{% for enum in element.simpleType.restriction.enumerations %}'{{ enum.value }}'{% if not loop.last %}, {% endif %}{% endfor %}],
{%- endif %}
{%- if element.name in keywords %}tagname='{{ element.name }}',{% endif %}
{%- if element.simpleType.restriction.minInclusive %}minInclusive={{ element.simpleType.restriction.minInclusive.value }},{% endif %}
Expand Down
17 changes: 17 additions & 0 deletions tests/assets/generation/enumeration2.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://example.com">
<xsd:complexType name="ComplexType">
<xsd:sequence>
<xsd:element name="Grade">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
<xsd:length value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
11 changes: 11 additions & 0 deletions tests/generation/code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def test_schema_xsd_include(self):
code = code.decode()
assert_contains('Schema1_Element', code)

def test_schema_xsd_enumeration(self):
xml = utils.open_document('tests/assets/generation/enumeration2.xsd')
code = xsd2py.generate_code_from_xsd(xml)
if six.PY3:
code = code.decode()
m = {}
try:
self._exec(code, m)
except SyntaxError as e:
self.fail('%s: %s' % (e.__class__.__name__, e))

def test_schema_xsd_restriction(self):
xml = utils.open_document('tests/assets/generation/restriction.xsd')
code = xsd2py.generate_code_from_xsd(xml)
Expand Down

0 comments on commit 4a86c94

Please sign in to comment.