goetas-webservices / xsd2php

Convert XSD into PHP classes and JMS serializer definitions
MIT License
238 stars 93 forks source link

Improper PHP code form choice element #138

Closed tomasz-kusy closed 3 years ago

tomasz-kusy commented 3 years ago

Hi. When we have something like that:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/" elementFormDefault="qualified">
    <xs:complexType name="MyType">
        <xs:attribute name="id" use="required" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="Complex.Type">
        <xs:choice>
            <xs:element name="option1" type="MyType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="option2" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:choice>
    </xs:complexType>
</xs:schema>

Generated method setOption1() of Php class ComplexType should allow to pass null parameter, not only MyType. It's necessary when working with serializer. Ex.

public function setOption1(?MyType $option1)

I have ready fix and I can create PR if you wish.

tomasz-kusy commented 3 years ago

https://github.com/goetas-webservices/xsd2php/pull/139

goetas commented 3 years ago

solved by https://github.com/goetas-webservices/xsd2php/pull/139