arskom / spyne

A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
http://spyne.io
Other
1.13k stars 313 forks source link

spyne generating invalid schema #618

Closed divick closed 5 years ago

divick commented 5 years ago

Here is a sample test which reproduces the error with master branch and with python3 .

class currency(ComplexModel):                                                   
    data = XmlData(Decimal)                                                     

class mntCurrency(currency):                                                    
    code = XmlAttribute(String)                                                 

class CreditLmt(ComplexModel):                                                  
    curr = mntCurrency

spyne complains with error:

lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}extension': The content is not valid. Expected is (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))., line 16

Generated schema is:

 <xs:complexType name="mntCurrency">                                           
    <xs:complexContent>                                                         
      <xs:extension base="tns:currency">                                        
        <xs:simpleContent>                                                      
          <xs:extension base="xs:decimal">                                      
            <xs:attribute name="code" type="xs:string"/>                        
          </xs:extension>                                                       
        </xs:simpleContent>                                                     
        <xs:sequence>                                                           
          <xs:element name="test" type="xs:token" minOccurs="0" nillable="true"/>
        </xs:sequence>                                                          
      </xs:extension>                                                           
    </xs:complexContent>                                                        
  </xs:complexType>

My goal is to have a tag inside CreditLmt which looks like this:

<tns:currency code="826">10.0</tns:currency>

divick commented 5 years ago

@plq I am happy to contribute to a model generator from wsdl for spyne but I am facing some issues with generation of models as listed above. I will be happy to contribute the code for generator.

plq commented 5 years ago

Hey,

Thanks for the offer, but this error is coming directly from libxml. It is essentially saying that the Xml Schema standard doesn't allow lone XmlData entries in a ComplexModel subclass. If you think this is an error, you must complain to the Xml Schema working group.

Note that this error has nothing to do with the WSDL standard. WSDL uses Xml Schema for object definitions and tries to fill other gaps in the domain of service discovery.

If you want to contribute to other areas of Spyne, have a look at other issues in the issue tracker. Eg. issue #616 is a good start.

Best,