xsd2php
xsd2php copied to clipboard
Attribute with NMTOKENS restriction generates array
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;
}
Hmm, right! that should be fixed!
@bcremer are you interested in providing a fix for this?