xsd2php icon indicating copy to clipboard operation
xsd2php copied to clipboard

Attribute with NMTOKENS restriction generates array

Open bcremer opened this issue 5 years ago • 2 comments

This is a regression in https://github.com/goetas-webservices/xsd2php/pull/96.

Given the following XSD:

<xs:schema targetNamespace="http://www.example.com"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:complexType name="ExampleType">
            <xs:attribute name="ExampleAttribute">
                <xs:simpleType>
                    <xs:restriction base="xs:NMTOKENS">
                        <xs:enumeration value="Master"/>
                        <xs:enumeration value="Arrival"/>
                        <xs:enumeration value="Departure"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
</xs:schema>

Die restriction on the ExampleAttribute of type NMTOKENS is treated as an list/array.
The following PHP Code get generated:

    /**
     * Gets as exampleAttribute
     *
     * @return string[]
     */
    public function getExampleAttribute()
    {
        return $this->exampleAttribute;
    }

    /**
     * Sets a new exampleAttribute
     *
     * @param string $exampleAttribute
     * @return self
     */
    public function setExampleAttribute(array $exampleAttribute)
    {
        $this->exampleAttribute = $exampleAttribute;
        return $this;
    }

When using the almost exact xsd with xs:restriction base="xs:string" the attribute is treated a scalar:

<xs:schema targetNamespace="http://www.example.com"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:complexType name="ExampleType">
            <xs:attribute name="ExampleAttribute">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="Master"/>
                        <xs:enumeration value="Arrival"/>
                        <xs:enumeration value="Departure"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
</xs:schema>
    /**
     * Gets as exampleAttribute
     *
     * @return string
     */
    public function getExampleAttribute()
    {
        return $this->exampleAttribute;
    }

    /**
     * Sets a new exampleAttribute
     *
     * @param string $exampleAttribute
     * @return self
     */
    public function setExampleAttribute($exampleAttribute)
    {
        $this->exampleAttribute = $exampleAttribute;
        return $this;
    }

bcremer avatar May 26 '20 11:05 bcremer

Hmm, right! that should be fixed!

goetas avatar May 27 '20 07:05 goetas

@bcremer are you interested in providing a fix for this?

goetas avatar Jan 24 '21 14:01 goetas