arskom/spyne — pull request #313 by rstuart (2013-11-18 07:20:20+00:00)
Title: Programmer control of sequence declaration in WSDL

I have been bitten once again by me changing something apparently innocuous in my type definitions (adding a nillable I think), and then breaking every client that generates compiled code from the WSDL. (This means just about everyone who doesn't use python-suds).

We have discussed before: https://github.com/arskom/spyne/issues/233#issuecomment-18737172

So, here is a patch that fixes it - at the expense of breaking all existing servers in this way one final time, of course.

The patch works by automagically assigning every subclass of ModelBase a unique number called __declare_order__. The number is incremented each time a new subclass is created.

ComplexModelBase inserts fields into _type_info in ascending order of __declare_order__. The WSDL already generated it's sequence in the order things were put into _type_info, so if you create a new type for every field in a ComplexModel like this:

```python
class MyStruct(ComplexModel):
y = Unicode()
x = Double()
```

Then the WSDL generated by Spyne will match the declared order of the fields in Python (ie y will be declared then x) - like just about every other SOAP implementation on the planet.

If you don't generate new types then the fallback is to use the names. So in this case in the WSDL x would be declared before y, because that is the sort order of the names. Not perfect, but it will be stable across revisions of Spyne, and python.