Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{! A full copy of the upstream python-prior v6.6.0 partial plus the _primitive_oneof_types marker. Reconcile it with the upstream partial on every generator upgrade. }}
class {{classname}}(ModelNormal):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

Do not edit the class manually.

Attributes:
{{> model_templates/docstring_allowed }}
attribute_map (dict): The key is attribute name
and the value is json key in definition.
discriminator_value_class_map (dict): A dict to go from the discriminator
variable value to the discriminator class name.
{{> model_templates/docstring_openapi_validations }}
"""

{{> model_templates/classvars }}

attribute_map = {
{{#requiredVars}}
'{{name}}': '{{baseName}}', # noqa: E501
{{/requiredVars}}
{{#optionalVars}}
'{{name}}': '{{baseName}}', # noqa: E501
{{/optionalVars}}
}

read_only_vars = {
{{#requiredVars}}
{{#isReadOnly}}
'{{name}}', # noqa: E501
{{/isReadOnly}}
{{/requiredVars}}
{{#optionalVars}}
{{#isReadOnly}}
'{{name}}', # noqa: E501
{{/isReadOnly}}
{{/optionalVars}}
}

_composed_schemas = {}

{{#oneOf}}
{{#-first}}
# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
{{/-first}}
{{{.}}},
{{#-last}}
)

{{/-last}}
{{/oneOf}}
{{> model_templates/method_from_openapi_data_normal}}

{{> model_templates/method_init_normal}}
14 changes: 13 additions & 1 deletion .openapi-generator/custom_templates/model_utils.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,12 @@ def get_discriminated_classes(cls):
def get_possible_classes(cls, from_server_context):
# TODO: lru_cache this
possible_classes = [cls]
primitive_oneof_types = getattr(cls, '_primitive_oneof_types', None)
if primitive_oneof_types:
# an OpenAPI number also admits integers
if float in primitive_oneof_types and int not in primitive_oneof_types:
return [int, *primitive_oneof_types]
return list(primitive_oneof_types)
if from_server_context:
return possible_classes
if hasattr(cls, 'discriminator') and cls.discriminator is not None:
Expand Down Expand Up @@ -1340,7 +1346,13 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
key_type=False)

# input_value's type is in valid_classes
if len(valid_classes) > 1 and configuration:
# A value that already matches a primitive oneOf member is kept as it is,
# so an int on a number|string union is not upconverted to a float. This
# also skips every other conversion for such a union: a future union with
# a `format: date` string member would keep its value a str, not a date.
is_primitive_union = any(
getattr(t, '_primitive_oneof_types', None) for t in required_types_mixed if inspect.isclass(t))
if len(valid_classes) > 1 and configuration and not is_primitive_union:
# there are valid classes which are not the current class
valid_classes_coercible = remove_uncoercible(
valid_classes, input_value, spec_property_naming, must_convert=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
float,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
int,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
float,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
bool,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
float,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
float,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def discriminator():

_composed_schemas = {}

# A oneOf of primitive members only: values are validated against these
# types and kept as plain values, this class is never instantiated.
_primitive_oneof_types = (
float,
str,
)

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
Expand Down
14 changes: 13 additions & 1 deletion gooddata-api-client/gooddata_api_client/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,12 @@ def get_discriminated_classes(cls):
def get_possible_classes(cls, from_server_context):
# TODO: lru_cache this
possible_classes = [cls]
primitive_oneof_types = getattr(cls, '_primitive_oneof_types', None)
if primitive_oneof_types:
# an OpenAPI number also admits integers
if float in primitive_oneof_types and int not in primitive_oneof_types:
return [int, *primitive_oneof_types]
return list(primitive_oneof_types)
if from_server_context:
return possible_classes
if hasattr(cls, 'discriminator') and cls.discriminator is not None:
Expand Down Expand Up @@ -1682,7 +1688,13 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
key_type=False)

# input_value's type is in valid_classes
if len(valid_classes) > 1 and configuration:
# A value that already matches a primitive oneOf member is kept as it is,
# so an int on a number|string union is not upconverted to a float. This
# also skips every other conversion for such a union: a future union with
# a `format: date` string member would keep its value a str, not a date.
is_primitive_union = any(
getattr(t, '_primitive_oneof_types', None) for t in required_types_mixed if inspect.isclass(t))
if len(valid_classes) > 1 and configuration and not is_primitive_union:
# there are valid classes which are not the current class
valid_classes_coercible = remove_uncoercible(
valid_classes, input_value, spec_property_naming, must_convert=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
{
"id": "p1",
"kind": "content",
"layout": {"type": "row", "children": [{"type": "text", "id": "t1", "markdown": "Hello"}]}
"style": {"gap": 20},
"layout": {
"type": "row",
"style": {"padding": "{theme.spacing.padding.normal}", "borderRadius": 4.5},
"children": [
{"type": "text", "id": "t1", "markdown": "Hello"},
{"type": "visualization", "id": "v1", "display": {"dataLabels": {"visible": "auto"}}}
]
}
}
]
},
Expand Down
Loading
Loading