-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Implement discriminators knowledge in code generation BNCH-30443 #87
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
Changes from 2 commits
1d4fa96
0632dff
fd1f32b
bd5a1bf
ad3ed2a
0195d84
03c3dc2
32d7c19
4b0275a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,17 @@ def _parse_{{ property.python_name }}(data: {{ property.get_type_string(json=Tru | |
| if isinstance(data, Unset): | ||
| return data | ||
| {% endif %} | ||
| {% if property.discriminator_property != None %} | ||
|
||
| discriminator_value: str = data.get("{{property.discriminator_property}}") | ||
| if discriminator_value is not None: | ||
| {% for discriminated_by, inner_property in property.discriminator_mappings.items() %} | ||
| if discriminator_value == "{{discriminated_by}}": | ||
| {% from "property_templates/" + inner_property.template import construct %} | ||
| {{ construct(inner_property, "data", initial_value="UNSET") | indent(8) }} | ||
| return {{ property.python_name }} | ||
| {% endfor %} | ||
|
|
||
| {% endif %} | ||
|
||
| {% for inner_property in property.inner_properties_with_template() %} | ||
| {% if not loop.last or property.has_properties_without_templates %} | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AD: Check for existence, error if so, but we might want to support that case in the future (several mapped names can reference the same type, e.g. for deprecation purposes)