goetas-webservices/xsd-reader

loadElement xs:choice $element->setMin(0)

time85 opened this issue · 2 comments

Hi,
i'm currently working on a project with OpenTravel-Data called Alpinebits.

(Sorry, i'm not 100% sure, if i am in the correct project because it could also fit better in the xsd2php project).

I am using xsd2php to generate the classes and the JMS-Metadata.

The problem is that a property has the skip_when_empty: true-Flag in the metadata-file und therefore the property is not serialized.

i checked it and found out that the minOccurs was set to 0 in this if-block:

if ($xp->query('ancestor::xs:choice', $node)->length) {
$element->setMin(0);
}

i think the xpath-query should only check the first anchestor (parent) or am i wrong?

method-schema

<xs:element name="OTA_ResRetrieveRS">
    <xs:complexType>

      <xs:choice>
        <!-- choice: Errors {1} -->
        <xs:element name="Errors">
          <xs:complexType>
            ...
          </xs:complexType>
        </xs:element>

        <!-- choice: Success {1} + Warnings {0,1} + ReservationsList {1} -->
        <xs:sequence>
          <xs:element name="Success"/>
          <xs:element name="Warnings" minOccurs="0">
            <xs:complexType>
             ...
            </xs:complexType>
          </xs:element>
          <xs:element name="ReservationsList">
            <xs:complexType>
              <xs:sequence>
                <!-- HotelReservation {0,} -->
                <xs:element name="HotelReservation" maxOccurs="unbounded" minOccurs="0">
                   ...
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>

        </xs:sequence>

      </xs:choice>

    </xs:complexType>
  </xs:element>

method-response

<?xml version="1.0" encoding="UTF-8"?>
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.00">
  <Success><![CDATA[1]]></Success>
</OTA_ResRetrieveRS>

How skip_when_empty is related to $element->setMin(0) ? TBH i forgot where it was set, however OTA was one of the main usecases i had when developing this library, thus most of the common situations should be handled.

can you describe what is the expected behavior? how metadata look and how would you like them to look?

in the metadata-generation, the min param get's checked to determine the skip_when_emptyparam

https://github.com/goetas-webservices/xsd2php/blob/794abcaf09b91c63a8f3df36620349b27c7f7c24/src/Jms/YamlConverter.php#L523

imho: the xpath-query should be restricted to the "direct" anchestor.
e.g. in the schema sample above the choice should only be valid for
<xs:element name="Errors"> or <xs:sequence>

and not for the element <xs:element name="ReservationsList"> cause this element is a "sub/sub-child"