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 312 forks source link

Support for custom SOAP-ENC types #567

Closed kkroo closed 4 years ago

kkroo commented 6 years ago

My goal is to parse the following for a TR-069 Server:

              <Event xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="cwmp:EventStruct[1]">
                <EventStruct>
                  <EventCode>0 BOOTSTRAP</EventCode>
                  <CommandKey></CommandKey>
                </EventStruct>
              </Event>

My models look like:

class EventStruct(ComplexModel):
    __namespace__ = 'urn:dslforum-org:cwmp-1-0'
    _type_info = odict()
    _type_info["EventCode"] = String(max_length=64)
    _type_info["CommandKey"] = String(max_length=32)

class EventList(ComplexModel):
    __namespace__ = 'urn:dslforum-org:cwmp-1-0'
    _type_info = odict()
    _type_info["EventStruct"] = EventStruct.customize(max_occurs='unbounded')
    _type_info["arrayType"] = XmlAttribute(String, ns='http://schemas.xmlsoap.org/soap/encoding/)

Unfortunately the model doesn't validate and I get the error: spyne.error.ValidationError: Fault(Client.ValidationError: 'The value "\'SOAP-ENC:Array\'" could not be validated.')

How do I add support in my model for SOAP-ENC namespace attributes?

plq commented 6 years ago

please send a pull request that contains a test that replicates this issue so I can have a look

I'm not sure whether this is a defect or an enhancement yet

ps: this is what you should use for _type_info: https://github.com/arskom/spyne/blob/049b7899b6498346a3a1d74e58fa55b7cfe24abc/spyne/model/complex.py#L75

kkroo commented 6 years ago

Thanks for the feedback, still learning the library!

I've seen similar feedback here about inability to support soap:enc attrs https://stackoverflow.com/questions/23949379/spyne-how-to-get-element-from-soap

plq commented 6 years ago

it doesnt, i was more concerned with: 'The value "\'SOAP-ENC:Array\'" could not be validated.'

kkroo commented 6 years ago

thought the issue may have been related. update: the issue with validation is suppressed when I extend the Soap11 protocol as following:

class Tr069Soap11(Soap11):

    def __init__(self, *args, **kwargs):
        super(Tr069Soap11, self).__init__(*args, **kwargs)
        self.parse_xsi_type = False

Not a real fix unfortunately, but hopefully helpful