Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
time85 opened this issue May 19, 2021 · 2 comments
Open

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

time85 opened this issue May 19, 2021 · 2 comments

Comments

@time85
Copy link

time85 commented May 19, 2021

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>
@goetas
Copy link
Member

goetas commented May 21, 2021

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?

@time85
Copy link
Author

time85 commented May 23, 2021

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants