-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
For unions the types are more elegant #992
Comments
I don't follow @skinkie 🥲 |
scheduled_stop_point_ref becomes FareScheduledStopPointRef | ScheduledStopPointRef I would like to see onward_timing_link_ref as TimingLinkRef. I don't see what in the XML Schema causes this distinction. Why wouldn't scheduled_stop_point_ref become FareScheduledStopPointRefStructure | ScheduledStopPointRefStructure? |
I don't understand the comparison, in both cases the generator behaves exactly the same, which is avoid flattening global types (root level elements and complex types.)
The
|
So you say that if
would be replaced by:
It would make TimingLinkRef (as type) out of it? My ideal would be that the TimingLinkRef is used, I noticed that also xmlspy and likes take the RefStructure, so it is likely something in the schema. The user must use TimingLinkRef (and not TimingLinkRefStructure) as type. (I corrected some typo's in this post) |
No I didn't say that 😄 xsdata can't go around flattening global types, that's what it does in both cases. We can't replace the child types with parent types just because, technically we could, but that would force the serializer to add the xsi:type to reveal the real type in order to pass schema validations. The whole structure is maddening, all that for no good reason, the restriction basically does nothing, except creating a lot of clones.
|
But in this case TimingLinkRefStructure is the parent of TimingLinkRef? The problem is indeed that if the user wrongfully uses TimingLinkRefStructure (like xsdata suggests) it ends up with the xsi:type (so it is also to avoid user error).
I think the only reason the structure does this, is to create an unique IdType. |
from xsdata.formats.dataclass.serializers import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
from netex import StopPointInJourneyPattern, TimingLinkRefStructure
spijp = StopPointInJourneyPattern(onward_timing_link_ref=TimingLinkRefStructure(ref="test")) # This is based on type hinting in PyCharm.
ns_map={'': 'http://www.netex.org.uk/netex', 'gml': 'http://www.opengis.net/gml/3.2'}
serializer_config = SerializerConfig(ignore_default_attributes=True)
serializer_config.pretty_print = True
serializer_config.ignore_default_attributes = True
serializer = XmlSerializer(serializer_config)
print(serializer.render(spijp, ns_map)) It is not that bad in Python it seems :-)
But considering that we want people to use TimingLinkRef (and not TimingLinkRefStructure) the question is: what to do? |
I would say no? @dataclass(kw_only=True)
class TimingLinkRef(TimingLinkRefStructure):
class Meta:
namespace = "http://www.netex.org.uk/netex" |
I am sorry I was comparing this
I don't know 😄, update the schema? I can't help with that, why do you even want that, to generate the xsi:type? |
I don't want to have the xsi:type. I would like to see the typehint TimingLinkRef. So someone would naively do this: spijp = StopPointInJourneyPattern(onward_timing_link_ref=TimingLinkRef(ref="test")) |
Ok so you want all the children of the
Understandable, but very difficult to accomplice @skinkie as far as I know no-other schema code generator does this... |
It is clear you look at least 3 steps ahead of my question.
To be fair. xsData is the best schema generator ever built. I wonder why it took 20 years to appear ;-) |
I think for this specific question the OnwardTimingLink is not a 'substitution group kind of thing', and it should not do what I ask. I'll come back with a specific example iff there exists one. |
Consider the following generated code: https://github.com/tefra/xsdata-samples/blob/main/netex/models/stop_point_in_journey_pattern_versioned_child_structure.py#L39
The scheduled_stop_point_ref gets a very pretty type FareScheduledStopPointRef | ScheduledStopPointRef.
What is the reason onward_timing_link_ref gets the 'RefStructure' (type) variant? Is there a possibility to get the pretty variant for the ordinary elements as well?
The text was updated successfully, but these errors were encountered: