Skip to content

Add additional property support by subscripting model #252

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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a96621d
Add additional property support by subscripting model
packyg Nov 25, 2020
f8ca735
Update e2e golden records
packyg Nov 25, 2020
62fad1e
Add models with additionalProperties to golden record
packyg Nov 25, 2020
f6028d3
PR Feedback: Set additional properties directly
packyg Nov 30, 2020
4c0fbd0
PR Feedback: Just make additionalProperties public
packyg Nov 30, 2020
b13d282
Handle edge cases of additionalProperties to interpret per the spec
packyg Nov 30, 2020
7b72c9a
Update golden record's spec to specify no additional props on existin…
packyg Nov 30, 2020
3a827f1
Support modeled additionalProperties
packyg Dec 1, 2020
78015fc
Typing fixes for model properties
packyg Dec 3, 2020
e3e0fb4
Add ModelWithPrimitiveAdditionalProperties to e2e test spec
packyg Dec 3, 2020
45ce82b
Regen golden records
packyg Dec 3, 2020
b2285cd
Merge branch 'main' into additionalProperties-support
packyg Dec 3, 2020
0d175c0
Update templates to not attempt to pop the same attr multiple times
packyg Dec 3, 2020
1f38a05
Update golden record
packyg Dec 3, 2020
da0bc8e
Typing fixes for additional_properties when building model prop
packyg Dec 3, 2020
827d367
Remove unused import from model_property
packyg Dec 3, 2020
daf9628
Update existing tests to account for additional_properties
packyg Dec 3, 2020
036f372
Parametrize test_build_model_property to test various additional_prop…
packyg Dec 4, 2020
e1ef9a7
Rename AdditionalProperties models to AdditionalProperty as each one …
packyg Dec 4, 2020
0cbe2de
Add test for bad additionalProperties schema
packyg Dec 4, 2020
6ccdde4
uncomment part of test
packyg Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
{% if property.required %}
{{ property.python_name }} = {{ property.reference.class_name }}.from_dict({{ source }})
{% else %}
{% if initial_value != None %}
{{ property.python_name }} = {{ initial_value }}
if {{ source }} is not None:
{{ property.python_name }} = {{ property.reference.class_name }}.from_dict(cast(Dict[str, Any], {{ source }}))
{% elif property.nullable %}
{{ property.python_name }} = None
{% else %}
{{ property.python_name }} = UNSET
{% endif %}
Comment on lines +5 to +11
Copy link
Contributor Author

@packyg packyg Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addresses what I think was a bug before

(Below has to do with the fact we are now poping the dict values)

_{{ property.python_name }} = {{source}}
if _{{ property.python_name }} is not None and not isinstance({{ property.python_name }}, Unset):
{{ property.python_name }} = {{ property.reference.class_name }}.from_dict(cast(Dict[str, Any], _{{ property.python_name }}))
{% endif %}
{% endmacro %}

Expand All @@ -16,7 +23,7 @@ if {{ source }} is not None:
{{ destination }} = {{ source }}.to_dict()
{% endif %}
{% else %}
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
{{ destination }}{% if declare_type %}: Union[{% if property.nullable %}None, {% endif %}Unset, Dict[str, Any]]{% endif %} = UNSET
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - the type was wrong here

if not isinstance({{ source }}, Unset):
{% if property.nullable %}
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
Expand Down