Search code examples
web-servicespython-2.7spyne

Python Spyne change the name of _return values


I'm using python 2.7 and Spyne for creating some web services in Django. I'm not able to change the name of the returned values, for example: Given this code:

class Consumer(ServiceBase):
   @rpc(Integer,Integer, _returns = [Integer,Integer])
   def addConsumer(ctx, topic_id, consumer_id):
   ...
   ...

The response in my wsdl looks like:

<xs:sequence>
  <xs:element name="addConsumerResult0" type="xs:integer" minOccurs="0" nillable="true"/>
  <xs:element name="addConsumerResult1" type="xs:integer" minOccurs="0" nillable="true"/>
</xs:sequence>

I am looking for something that allow me to change name="addConsumerResult0" to name="whateverXYZ"


Solution

  • You can use _out_variable_names to change return type names.

    e.g.

    class Consumer(ServiceBase):
       @rpc(Integer,Integer, _returns = [Integer,Integer], 
                                          _out_variable_names=["whateverXYZ", "foo"])
       def addConsumer(ctx, topic_id, consumer_id):
       ...
       ...