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
2 changes: 1 addition & 1 deletion bin/openapi3/python-experimental-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
#yaml="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"
yaml="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml"
yaml="modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml"
ags="generate -t modules/openapi-generator/src/main/resources/python -i $yaml -g python-experimental -o samples/openapi3/client/petstore/python-experimental/ --additional-properties packageName=petstore_api $@"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ from {{packageName}}.model_utils import ( # noqa: F401
ModelComposed,
ModelNormal,
ModelSimple,
cached_property,
change_keys_js_to_python,
convert_js_args_to_python_args,
date,
datetime,
file_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

additional_properties_type = {{#additionalPropertiesType}}({{{additionalPropertiesType}}},) # noqa: E501{{/additionalPropertiesType}}{{^additionalPropertiesType}}None{{/additionalPropertiesType}}

@staticmethod
@cached_property
def openapi_types():
"""
This must be a class method so a model may have properties that are
Expand All @@ -113,7 +113,7 @@
{{/optionalVars}}
}

@staticmethod
@cached_property
def discriminator():
{{^discriminator}}return None{{/discriminator}}{{#discriminator}}val = {
{{#mappedModels}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@classmethod
def get_discriminator_class(cls, from_server, data):
def get_discriminator_class(cls, data):
"""Returns the child class specified by the discriminator"""
discriminator = cls.discriminator()
discriminator = cls.discriminator
discr_propertyname_py = list(discriminator.keys())[0]
discr_propertyname_js = cls.attribute_map[discr_propertyname_py]
if from_server:
if discr_propertyname_js in data:
class_name = data[discr_propertyname_js]
else:
class_name = data[discr_propertyname_py]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'_from_server',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
'_composed_instances',
'_var_name_to_model_instances',
'_additional_properties_model_instances',
Expand All @@ -16,6 +17,7 @@
'_path_to_item': _path_to_item,
'_from_server': _from_server,
'_configuration': _configuration,
'_visited_composed_classes': self._visited_composed_classes,
}
required_args = {
{{#requiredVars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'_from_server',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
])

{{> python-experimental/model_templates/method_init_shared }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501
@convert_js_args_to_python_args
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, _visited_composed_classes=(), **kwargs): # noqa: E501
"""{{classname}} - a model defined in OpenAPI

{{#requiredVars}}
Expand Down Expand Up @@ -31,6 +32,21 @@
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
_visited_composed_classes (tuple): This stores a tuple of
classes that we have traveled through so that
if we see that class again we will not use its
discriminator again.
When traveling through a discriminator, the
composed schema that is
is traveled through is added to this set.
For example if Animal has a discriminator
petType and we pass in "Dog", and the class Dog
allOf includes Animal, we move through Animal
once using the discriminator, and pick Dog.
Then in Dog, we will make an instance of the
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
{{#optionalVars}}
{{name}} ({{{dataType}}}):{{#description}} {{description}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}} # noqa: E501
{{/optionalVars}}
Expand All @@ -40,4 +56,5 @@
self._check_type = _check_type
self._from_server = _from_server
self._path_to_item = _path_to_item
self._configuration = _configuration
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
path_to_item.extend(self._path_to_item)
path_to_item.append(name)

openapi_types = self.openapi_types()
if name in openapi_types:
required_types_mixed = openapi_types[name]
if name in self.openapi_types:
required_types_mixed = self.openapi_types[name]
elif self.additional_properties_type is None:
raise ApiKeyError(
"{0} has no key '{1}'".format(type(self).__name__, name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class {{unescapedDescription}}(ModelComposed):

{{> python-experimental/model_templates/method_init_composed }}

@staticmethod
@cached_property
def _composed_schemas():
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class {{unescapedDescription}}(ModelNormal):
{{/optionalVars}}
}

@staticmethod
def _composed_schemas():
return None
_composed_schemas = {}

{{> python-experimental/model_templates/method_init_normal}}{{#discriminator}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class {{unescapedDescription}}(ModelSimple):

{{> python-experimental/model_templates/classvars }}

@staticmethod
def _composed_schemas():
return None
_composed_schemas = None

{{> python-experimental/model_templates/method_init_normal}}
Loading