Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Merge upstream/main
  • Loading branch information
forest-benchling committed Jun 28, 2021
commit 4be4790b7d07fa07d52a2a78717d9772cb9b7f99
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ isoparse({{ source }}).date()

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% if property.required %}
{{ destination }} = {{ source }}.isoformat() {% if property.nullable %}if {{ source }} else None {%endif%}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ isoparse({{ source }})

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% if property.required %}
{% if property.nullable %}
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, {{ property.value_type.__name__ }}){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% set transformed = source + ".value" %}
{% set type_string = property.get_type_string(json=True) %}
{% if stringify %}
{% set transformed = "(None, str(" + transformed + "), 'text/plain')" %}
{% set type_string = "Union[Unset, Tuple[None, str, str]]" %}
{% endif %}
{% if property.required %}
{% if property.nullable %}
{{ destination }} = {{ transformed }} if {{ source }} else None
{% else %}
{{ destination }} = {{ transformed }}
{% endif %}
{% else %}
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
{% if property.nullable %}
{{ destination }} = {{ transformed }} if {{ source }} else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ File(

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, bytes){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% if property.required %}
{% if property.nullable %}
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for {{ inner_source }} in {{ source }}:

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, list){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% set inner_property = property.inner_property %}
{% if stringify %}
{% set type_string = "Union[Unset, Tuple[None, str, str]]" %}
Expand All @@ -57,7 +57,7 @@ else:
{{ _transform(property, source, destination, stringify) }}
{% endif %}
{% else %}
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
{% if property.nullable %}
if {{ source }} is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, dict){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, transform_method="to_dict", query_param=False) %}
{% set transformed = source + "." + transform_method + "()" %}
{% if stringify %}
{% set transformed = "(None, json.dumps(" + transformed + "), 'application/json')" %}
{% set type_string = "Union[Unset, Tuple[None, str, str]]" %}
{% else %}
{% set type_string = property.get_type_string(json=True) %}
{% endif %}
{% if property.required %}
{% if property.nullable %}
{{ destination }} = {{ transformed }} if {{ source }} else None
{% else %}
{{ destination }} = {{ transformed }}
{% endif %}
{% else %}
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
{% if property.nullable %}
{{ destination }} = {{ transformed }} if {{ source }} else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

{% macro check_type_for_construct(property, source) %}{{ source }} is None{% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{{ destination }} = None
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri
{# For now we assume there will be no unions of unions #}
{% macro check_type_for_construct(property, source) %}True{% endmacro %}

{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
{% macro transform(property, source, destination, declare_type=True, stringify=False, query_param=False) %}
{% if not property.required or property.nullable %}
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.