1

I'm ok with Spyne's hello world examples, but when it comes to something more complex I faced with lack of documentation and advanced examples. In my case I have a service method which accepts body like this

<OTA_HotelAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" TimeStamp="2005-08-01T09:30:47+02:00" EchoToken="fb57388d" AvailRatesOnly="true">
  <AvailRequestSegments>
    <AvailRequestSegment AvailReqType="Room">
      <HotelSearchCriteria>
        <Criterion>
          <HotelRef HotelCode="HOTEL1"/>
        </Criterion>
      </HotelSearchCriteria>
    </AvailRequestSegment>
  </AvailRequestSegments>
</OTA_HotelAvailRQ>

Can you help me to implement a service that accepts this kind of request?

Anton Egorov
  • 1,174
  • 1
  • 11
  • 21

1 Answers1

4

Off the top of my head:

class HotelReference(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    HotelCode = XmlAttribute(Unicode)

class Criterion(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    HotelRef = HotelReference

class AvailRequestSegment(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    AvailReqType = XmlAttribute(Unicode(values=["Room", "House", "Condo", "Castle"]))
    HotelSearchCriteria = Criterion.customize(max_occurs='unbounded')

class HotelAvailRQ(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    Version = XmlAttribute(Unicode)
    TimeStamp = XmlAttribute(DateTime)
    EchoToken = XmlAttribute(ByteArray)
    AvailRatesOnly XmlAttribute(Boolean)

    AvailRequestSegments = Array(AvailRequestSegment)
Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
  • 1
    Ok, I got it. Now it seems clear with request definition, except of one thing. `The OTA_HotelAvailRQ` attributes are mandatory. I described them as `XmlAttribute(Mandatory.Unicode)`. But when I post a request without these arguments validation unexpectedly passed. – Anton Egorov Oct 22 '13 at 14:25
  • 2
    This is most probably a bug. Please send a pull request at http://github.com/arskom/spyne with a test case that checks for the expected xml schema output. – Burak Arslan Oct 23 '13 at 06:59
  • 1
    Here is my pull request with tests to illustrate the problem https://github.com/arskom/spyne/pull/297 – Anton Egorov Oct 23 '13 at 11:39
  • 2
    The bug is fixed. The workaround is to use ``XmlAttribute(..., use='required')`` – Burak Arslan Oct 24 '13 at 12:07
  • could you help with this, plz http://stackoverflow.com/questions/19536282/i-dont-want-spyne-to-wrap-my-response – Anton Egorov Oct 24 '13 at 12:14