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

XmlContext allows for more than one text node per model #246

Closed
tefra opened this issue Sep 3, 2020 · 0 comments · Fixed by #251
Closed

XmlContext allows for more than one text node per model #246

tefra opened this issue Sep 3, 2020 · 0 comments · Fixed by #251
Labels
enhancement New feature or request

Comments

@tefra
Copy link
Owner

tefra commented Sep 3, 2020

The XmlContent expects dataclasses fields metadata to include the xml type parameter with one of Element | Attribute | Wildcard | Attributes otherwise defaults to Text.

There are currently no sanity checks like multiple text nodes in the same model.
The builder should detect these cases and revert to all Elements.

@dataclass
class Example:
    bool: bool
    int: int
    union: Union[int, bool]

result = list(self.ctx.get_type_hints(Example, None))
expected = [
    XmlText(name="bool", qname="bool", types=[bool]),
    XmlText(name="int", qname="int", types=[int]),
    XmlText(name="union", qname="union", types=[bool, int]),
]

Which of course is impossible, the correct output should be

expected = [
    XmlElement(name="bool", qname="bool", types=[bool]),
    XmlElement(name="int", qname="int", types=[int]),
    XmlElement(name="union", qname="union", types=[bool, int]),
]

Another example should be

@dataclass
class Example:
    bool: bool
    int: int
    union: Union[int, bool]
    text: str = field(metadata=dict(type="Text"))


result = list(self.ctx.get_type_hints(Example, None))
expected = [
    XmlText(name="bool", qname="bool", types=[bool]),
    XmlText(name="int", qname="int", types=[int]),
    XmlText(name="union", qname="union", types=[bool, int]),
]

This will also make writing the models manually a little easier and might also allow the generator to cut down on declarations a little bit.

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

Successfully merging a pull request may close this issue.

1 participant