WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
418 stars 73 forks source link

sequence Tag min/maxOccurs attribute is ignored #268

Closed Shaqundalond closed 2 years ago

Shaqundalond commented 2 years ago

Describe the bug When parsing the Complex Type "ValueListTyp", the resulting php class ignores the attributes of the sequence tag

    <simpleType name="LongName">
        <restriction base="string">
            <maxLength value="256"/>
        </restriction>
    </simpleType>
...
<complexType name="ValueListType">
        <sequence minOccurs="0" maxOccurs="unbounded">
            <element ref="tns:Value"/>
        </sequence>
 </complexType>
...
 <element name="Value" type="tns:LongName"/>

The resulting Class only accepts a String for $Value instead of an array of \StructType\Value. Furthermore no \StructType Value is created.

class ValueListType extends AbstractStructBase
{
    /**
     * The Value
     * Meta information extracted from the WSDL
     * - base: string
     * - maxLength: 256
     * - ref: tns:Value
     * @var string|null
     */
    protected ?string $Value = null;
    /**
     * Constructor method for ValueListType
     * @uses ValueListType::setValue()
     * @param string $value
     */
    public function __construct(?string $value = null)
    {
        $this
            ->setValue($value);
    }
...
}

To Reproduce Generate the Classes for the following WSDL

<wsaw:UsingAddressing` wsdl:required="true"/>

needs to be set to false

Expected behavior A Result more similar to this

class ValueListType extends AbstractStructBase
{
    /**
     * The Value
     * Meta information extracted from the WSDL
     * - base: string
     * - maxLength: 256
     * - ref: tns:Value
     * @var \StructType\Value[]|null
     */
    protected ?array $Value = null;
    /**
     * Constructor method for ValueListType
     * @uses ValueListType::setValue()
     * @param string $value
     */
    public function __construct(?array $value = null)
    {
        $this
            ->setValue($value);
    }
...
}

Creation of a Value Class

Additional context One of the Reasons there might be no Value class is that there is another xsd included which also defines the element Value.

mikaelcom commented 2 years ago

Actually, the base ValueListType Struct element is returned by the SoapClient::__getTypes method such as:

[12] => struct ValueListType {
    LongName Value;
}

And from what I understand, the Value is of type LongName which is mainly a string, so it would not be valid to create a class for it.

Concerning the sequence tag, I would agree that the Value property could be an array of string.

Do you have a valid XML request that contains and demonstrates the correct ValueListType definition?

Thanks

Shaqundalond commented 2 years ago

Thank you for your fast Response .

Here is a snippet from a valid XML Request

    <lcm:SubmitObjectsRequest>
        <rim:RegistryObjectList>
            <rim:ExtrinsicObject id="Document01"
                                 mimeType="text/xml"
                                 objectType="urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1">
                <rim:Slot name="creationTime">
                    <rim:ValueList>
                        <rim:Value>20051224</rim:Value>
                    </rim:ValueList>
                </rim:Slot>
                <rim:Slot name="sourcePatientInfo">
                    <rim:ValueList>
                        <rim:Value>PID-3|ST-1000^^^&amp;1.3.6.1.4.1.21367.2003.3.9&amp;ISO</rim:Value>
                        <rim:Value>PID-5|Doe^John^^^</rim:Value>
                        <rim:Value>PID-7|19560527</rim:Value>
                        <rim:Value>PID-8|M</rim:Value>
                        <rim:Value>PID-11|100 Main St^^Metropolis^Il^44130^USA</rim:Value>
                    </rim:ValueList>
                </rim:Slot>
...

As you can see a ValueList can hold multiple Value Elements. My assumption from php and Soapclient was that every element gets turned into a Class. Therefore there should be a Value Class or rather a Longname Class.

mikaelcom commented 2 years ago

Ok, thanks for the sample, it clarifies the need to mark the Value as an array.

But not every element is mapped to a class because the PHP class is turned to an XML tag so it has to the a simple property for the deepest/final string/int/float/etc. values :wink:.

I'll let you know as soon as I could find a proper way to handle this without breaking everything :smile: