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
Expand Up @@ -723,11 +723,11 @@ public CodegenModel fromModel(String name, Schema sc) {
// 1. no default exists
// schema does not contain default
// cm.defaultValue unset, cm.hasRequired = true
// 2. server has a default
// 2. spec has a default
// schema contains default
// cm.defaultValue set, cm.hasRequired = true
// cm.defaultValue set, cm.hasRequired = false
// different value here to differentiate between use case 3 below
// This defaultValue is used in the client docs only and is not sent to the server
// This defaultValue is used when a consumer (client or server) lacks the input argument, defaultValue will be used
// 3. only one value is allowed in an enum
// schema does not contain default
// cm.defaultValue set, cm.hasRequired = false
Expand All @@ -738,7 +738,7 @@ public CodegenModel fromModel(String name, Schema sc) {
cm.hasRequired = true;
} else if (sc.getDefault() != null) {
cm.defaultValue = defaultValue;
cm.hasRequired = true;
cm.hasRequired = false;
} else if (defaultValue != null && cm.defaultValue == null) {
cm.defaultValue = defaultValue;
cm.hasRequired = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,37 @@
])

@convert_js_args_to_python_args
def __init__(self{{#hasRequired}}, value{{/hasRequired}}, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""{{classname}} - a model defined in OpenAPI

{{#hasRequired}}
Note that value can be passed either in args or in kwargs, but not in both.

Args:
value ({{{dataType}}}):{{#description}} {{description}}.{{/description}}{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}}{{#allowableValues}}, must be one of [{{#enumVars}}{{{value}}}, {{/enumVars}}]{{/allowableValues}} # noqa: E501
args[0] ({{{dataType}}}):{{#description}} {{description}}.{{/description}}{{#defaultValue}} if omitted defaults to {{{defaultValue}}}{{/defaultValue}}{{#allowableValues}}, must be one of [{{#enumVars}}{{{value}}}, {{/enumVars}}]{{/allowableValues}} # noqa: E501

{{/hasRequired}}
Keyword Args:
{{^hasRequired}}
value ({{{dataType}}}):{{#description}} {{description}}.{{/description}}{{#defaultValue}} defaults to {{{defaultValue}}}{{/defaultValue}}{{#allowableValues}}, must be one of [{{#enumVars}}{{{value}}}, {{/enumVars}}]{{/allowableValues}} # noqa: E501
{{/hasRequired}}
value ({{{dataType}}}):{{#description}} {{description}}.{{/description}}{{#defaultValue}} if omitted defaults to {{{defaultValue}}}{{/defaultValue}}{{#allowableValues}}, must be one of [{{#enumVars}}{{{value}}}, {{/enumVars}}]{{/allowableValues}} # noqa: E501
{{> python-experimental/model_templates/docstring_init_required_kwargs }}
"""

{{^hasRequired}}
if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
{{#defaultValue}}
else:
value = {{{defaultValue}}}
{{/hasRequired}}
{{/defaultValue}}
{{^defaultValue}}
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)
{{/defaultValue}}

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void defaultSettingInPrimitiveModelWithValidations() {

final CodegenModel hasDefaultModel = codegen.fromModel("hasDefaultModel", hasDefault);
Assert.assertEquals(hasDefaultModel.defaultValue, "15.0");
Assert.assertEquals(hasDefaultModel.hasRequired, true);
Assert.assertEquals(hasDefaultModel.hasRequired, false);

final CodegenModel noDefaultEumLengthOneModel = codegen.fromModel("noDefaultEumLengthOneModel", noDefaultEumLengthOne);
Assert.assertEquals(noDefaultEumLengthOneModel.defaultValue, "15.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | if omitted the server will use the default value of "-efg", must be one of ["_abc", "-efg", "(xyz)", ]
**value** | **str** | | defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""AnimalFarm - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value ([Animal]): # noqa: E501
args[0] ([Animal]): # noqa: E501

Keyword Args:
value ([Animal]): # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,18 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""EnumClass - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value (str): if omitted the server will use the default value of "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501
args[0] (str): if omitted defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501

Keyword Args:
value (str): if omitted defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,14 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
value = "-efg"

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""NumberWithValidations - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value (float): # noqa: E501
args[0] (float): # noqa: E501

Keyword Args:
value (float): # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -137,6 +140,18 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""StringEnum - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value (str):, must be one of ["placed", "approved", "delivered", ] # noqa: E501
args[0] (str):, must be one of ["placed", "approved", "delivered", ] # noqa: E501

Keyword Args:
value (str):, must be one of ["placed", "approved", "delivered", ] # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,18 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | if omitted the server will use the default value of "-efg", must be one of ["_abc", "-efg", "(xyz)", ]
**value** | **str** | | defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **int** | | if omitted the server will use the default value of 0, must be one of [0, 1, 2, ]
**value** | **int** | | defaults to 0, must be one of [0, 1, 2, ]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | if omitted the server will use the default value of "placed", must be one of ["placed", "approved", "delivered", ]
**value** | **str** | | defaults to "placed", must be one of ["placed", "approved", "delivered", ]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""AnimalFarm - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value ([Animal]): # noqa: E501
args[0] ([Animal]): # noqa: E501

Keyword Args:
value ([Animal]): # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,18 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""ArrayOfEnums - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value ([StringEnum]): # noqa: E501
args[0] ([StringEnum]): # noqa: E501

Keyword Args:
value ([StringEnum]): # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,18 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
raise ApiTypeError(
"value is required, but not passed in args or kwargs and doesn't have default",
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def discriminator():
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""EnumClass - a model defined in OpenAPI

Note that value can be passed either in args or in kwargs, but not in both.

Args:
value (str): if omitted the server will use the default value of "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501
args[0] (str): if omitted defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501

Keyword Args:
value (str): if omitted defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ] # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Expand Down Expand Up @@ -138,6 +141,14 @@ def __init__(self, value, *args, **kwargs):
_visited_composed_classes = (Animal,)
"""

if 'value' in kwargs:
value = kwargs.pop('value')
elif args:
args = list(args)
value = args.pop(0)
else:
value = "-efg"

_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
Expand Down
Loading