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

Make simplifying lists of simple elements optional #24

Closed
jayvdg opened this issue Mar 23, 2017 · 9 comments
Closed

Make simplifying lists of simple elements optional #24

jayvdg opened this issue Mar 23, 2017 · 9 comments

Comments

@jayvdg
Copy link

jayvdg commented Mar 23, 2017

Whenever I have an element without any attributes that is a list of elements of only 1 type, the generator simplifies this into an array of that nested element. This makes sense, but in some cases I need the list element to be present in the serialized XML, even if it's empty.
An empty array won't be serialized, but an empty element will. I suggest making the "simplifying" of this type of list optional.

I'm not entirely sure how to describe this properly, so let's do it by example.

Given this schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="MainElement">
        <xs:sequence>
            <xs:element name="ElementList">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="NestedElement" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

The current output would be (simplified):

MainElementType:
    properties:
        ElementList:
            expose: true
            access_type: public_method
            serialized_name: ElementList
            type: array<integer>
            xml_list:
                inline: false
                entry_name: NestedElement

While in some cases I need this to be:

MainElementType:
    properties:
        ElementList:
            expose: true
            access_type: public_method
            serialized_name: ElementList
            type: MainElementType\ElementListAType

The same goes for the generated PHP code. The "ElementListAType" class is already always generated, but MainElement::setElementList() expects the array, and not the object.

I propose to add a configuration option that enables or disables this "simplifying", with the default still being enabled. I'm already working on a PR for this and will link it shortly.

@goetas
Copy link
Member

goetas commented Mar 23, 2017

@jayvdg
Copy link
Author

jayvdg commented Mar 23, 2017

I guess that's an option, but this would mean I have to edit all of the generated metadata. And it would still never use the available ElementListAType, even though that code was generated.

Do you know if it's possible to make not skipping empty lists the default in the serializer?

@goetas
Copy link
Member

goetas commented Mar 23, 2017

I guess that's an option, but this would mean I have to edit all of the generated metadata.

metadata are meant be be overwritten each time. are you editing them manually?

And it would still never use the available ElementListAType, even though that code was generated.

isn't the only the propose of this element to have tue list element present in the serialized XML? if you manage to do it via skipWhenEmpty = false, everything should work fine, is it?

Do you know if it's possible to make not skipping empty lists the default in the serializer?

not possible for now

@jayvdg
Copy link
Author

jayvdg commented Mar 23, 2017

I'm not editing the metadata, that's actually exactly what I'm trying to avoid.
How can I apply skipWhenEmpty to the property without editing the metadata?

And yes, currently the only purpose of the element is to have it present in the serialized XML. That, and it feels like it makes "sense" in some cases to use the element instead of a plain array.

@jayvdg
Copy link
Author

jayvdg commented Mar 23, 2017

Actually, I realise that since the ElementList has a implicit minOccurs of 1 it makes more sense to have the generator add the skip_when_empty: false to any list that should occur at least once.

Maybe it's better to focus on that.

@goetas
Copy link
Member

goetas commented Mar 23, 2017

yes!

@jayvdg
Copy link
Author

jayvdg commented Mar 23, 2017

I will look into that and create a seperate issue / PR for it.

I still feel like this option has it's use cases so I'll leave the branch for now.

@goetas
Copy link
Member

goetas commented Mar 24, 2017

@jeroenvandergeer is this solved by #27 ?

@jayvdg
Copy link
Author

jayvdg commented Mar 24, 2017

It's not really the same thing, but it solves the same problem for me. I think this can be closed.

@goetas goetas closed this as completed Mar 24, 2017
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