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

Implementing the xs:all tag #584

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Implementing the xs:all tag #584

wants to merge 2 commits into from

Conversation

Artanys
Copy link

@Artanys Artanys commented Oct 10, 2018

No description provided.

@plq
Copy link
Member

plq commented Oct 10, 2018

jenkins, run tests

@plq
Copy link
Member

plq commented Oct 10, 2018

hey, thanks for the patch!

one of your tests are failing, can you have a look?

@plq
Copy link
Member

plq commented Oct 10, 2018

What's the point of having a group name for the xs:all tag? What happens when you pass different values to xml_all_group ?

@Artanys
Copy link
Author

Artanys commented Oct 10, 2018

Will fix tests, pushed this out a bit late last night :)

I modeled the group name after the implementation of xs:choice, with the addition that xs:all is a direct subelement of complexType instead of in a sequence. I will add an additional failure case for when you specify two "all groups" in the same element

@Artanys
Copy link
Author

Artanys commented Oct 10, 2018

  <xs:complexType name="AbcAll">
    <xs:all>
      <xs:element name="abc" type="xs:string"/>
      <xs:element name="bcd" type="xs:string" minOccurs="0"/>
    </xs:all>
    <xs:all>
      <xs:element name="cde" type="xs:string" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

gets generated if I specify something like

class AbcAll(ComplexModel):
    abc = Unicode(xml_all_group="all1", min_occurs=1)
    bcd = Unicode(xml_all_group="all1")
    cde = Unicode(xml_all_group="all2")

This then fails lxml schema validation in

Traceback (most recent call last):
  File "/home/artanys/dev/dvenv/spyne/spyne/interface/xml_schema/_base.py", line 223, in build_validation_schema
    self.validation_schema = etree.XMLSchema(etree.parse(f))
  File "src/lxml/xmlschema.pxi", line 86, in lxml.etree.XMLSchema.__init__

I can add an explicit check for this in the code and throw a reasonable error

@plq
Copy link
Member

plq commented Oct 11, 2018

It's been some time since I looked at the xml schema spec so please correct me if I'm wrong here.

xsd:choice was implemented that way because there can be multiple choice tags. this is not the case for the xsd:all tag (is it?).

Instead of throwing an error, we have two options depending on whether you can have both <xsd:all> and <xsd:sequence> inside one complexType element.

If it's possible, we could change xml_all_group:str to xml_main_group:exactly_one_of('all', 'sequence') so you eliminate the source of the error in its root.

so your example becomes:

class AbcAll(ComplexModel):
    abc = Unicode(xml_main_group='all', min_occurs=1)
    bcd = Unicode(xml_main_group='all')
    cde = Unicode(xml_main_group='sequence')
    def = Unicode(xml_main_group='sequence')

which would generate:

  <xs:complexType name="AbcAll">
    <xs:all>
      <xs:element name="abc" type="xs:string"/>
      <xs:element name="bcd" type="xs:string" minOccurs="0"/>
    </xs:all>
    <xs:sequence>
      <xs:element name="cde" type="xs:string" minOccurs="0"/>
      <xs:element name="def" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

If having both all and sequence elements inside the complexType is not possible, then the main group should be implemented as a class attribute rather than an element attribute. So your example would become:

class AbcAll(ComplexModel):
    class Attributes(ComplexModel.Attributes):
        xml_main_group='all'

    abc = Unicode(min_occurs=1)
    bcd = Unicode
    cde = Unicode

which would generate

  <xs:complexType name="AbcAll">
    <xs:all>
      <xs:element name="abc" type="xs:string"/>
      <xs:element name="bcd" type="xs:string" minOccurs="0"/>
      <xs:element name="cde" type="xs:string" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

It seems both could be implemented with minor modifications to your current patch.

So, what does the spec say?

@Artanys
Copy link
Author

Artanys commented Oct 11, 2018

Schema says they cannot coexist. Will look into making it a class attribute

@plq plq added the Enhancement label Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants