Search code examples
pythonsoapwsdlspyne

Spyne: array of 1 or more integers


I have this service:

class CategoryService(ServiceBase):

    @rpc(Array(Integer(min_occurs=1, max_occurs='unbounded', nillable=False), **MANDATORY),
         _returns=Iterable(Category, **MANDATORY))
    def get_subcategories_by_path(ctx, category_path):
        ...

This is shown in WSDL as:

<xs:complexType name="get_subcategories_by_path">
  <xs:sequence>
    <xs:element name="category_path" type="tns:integerArray"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="integerArray">
  <xs:sequence>
    <xs:element name="integer" type="xs:integer" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
  </xs:sequence>
</xs:complexType>

I want category_path argument to be an array of 1 or more integers, but Array(Integer(min_occurs=1, max_occurs='unbounded', nillable=False) does not work for me.


Solution

  • Array is for wrapped array types. To get simple ones, you should use the type markers directly. The following should do the trick:

    class CategoryService(ServiceBase):
        @rpc(Integer(min_occurs=1, max_occurs='unbounded', nillable=False)),
                                            _returns=Iterable(Category, **MANDATORY))
        def get_subcategories_by_path(ctx, category_path):
            # (...)