mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 578 forks source link

Enumeration: how to get available values #1305

Open danaki opened 2 years ago

danaki commented 2 years ago

Hello,

Spend a time learning from code to get the complete list of values described in enumeration but didnt find. Having this scheme:

schema = xsd.Schema(
    load_xml(
        """
    <?xml version="1.0"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            targetNamespace="http://tests.python-zeep.org/"
            elementFormDefault="qualified">
        <simpleType name="CountryNameType">
        <list>
            <simpleType>
            <restriction base="string">
                <enumeration value="None"/>
                <enumeration value="AlternateName"/>
                <enumeration value="City"/>
                <enumeration value="Code"/>
                <enumeration value="Country"/>
            </restriction>
            </simpleType>
        </list>
        </simpleType>
        <element name="something" type="tns:CountryNameType"/>
    </schema>
"""
    )
)

How do I get the list ['None', 'AlternateName', 'City', 'Code', 'Country']?

>>> element_cls = schema.get_element("{http://tests.python-zeep.org/}something")
>>> element_cls
<Element(name='something', type=<zeep.xsd.types.collection.ListType object at 0x7fb056073ac0>)>

Which is a ListType of strings with possible values that should be exposed I guess.