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 @@ -643,6 +643,11 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty p) {
// fix ListContainers
p.complexType = getPythonClassName(p.mostInnerItems.complexType);
}
// if a model has a property that is of type self, remove the module name from the dataType
if (p.complexType != null && p.dataType.contains(model.classname)) {
String classNameNoModule = getPythonClassName(model.classname);
p.dataType = p.dataType.replace(model.classname, classNameNoModule);
}
}

@Override
Expand Down Expand Up @@ -753,6 +758,10 @@ public CodegenModel fromModel(String name, Schema schema) {
result.imports.add(modelName);
}
}
// if a class has a property of type self, remove the self import from imports
if (result.imports.contains(result.classname)) {
result.imports.remove(result.classname);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
{{/optionalVars}}
}

openapi_types = {
{{#requiredVars}}
'{{name}}': ({{{dataType}}},), # noqa: E501
{{/requiredVars}}
{{#optionalVars}}
'{{name}}': ({{{dataType}}},), # noqa: E501
{{/optionalVars}}
}

validations = {
{{#requiredVars}}
{{#hasValidation}}
Expand Down Expand Up @@ -103,6 +94,25 @@

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

@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import

Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
{{#requiredVars}}
'{{name}}': ({{{dataType}}},), # noqa: E501
{{/requiredVars}}
{{#optionalVars}}
'{{name}}': ({{{dataType}}},), # noqa: E501
{{/optionalVars}}
}

@staticmethod
def discriminator():
return {{^discriminator}}None{{/discriminator}}{{#discriminator}}{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
openapi_types (dict): The key is attribute name
and the value is attribute type.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
path_to_item.extend(self._path_to_item)
path_to_item.append(name)

if name in self.openapi_types:
required_types_mixed = self.openapi_types[name]
openapi_types = self.openapi_types()
if name in openapi_types:
required_types_mixed = 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 @@ -928,7 +928,7 @@ def get_allof_instances(self, model_args, constant_args):

# extract a dict of only required keys from fixed_model_args
kwargs = {}
var_names = set(allof_class.openapi_types.keys())
var_names = set(allof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -963,7 +963,7 @@ def get_oneof_instance(self, model_args, constant_args):

# extract a dict of only required keys from fixed_model_args
kwargs = {}
var_names = set(oneof_class.openapi_types.keys())
var_names = set(oneof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def get_anyof_instances(self, model_args, constant_args):

# extract a dict of only required keys from these_model_vars
kwargs = {}
var_names = set(anyof_class.openapi_types.keys())
var_names = set(anyof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def get_var_name_to_model_instances(self, composed_instances):
all_instances = [self]
all_instances.extend(composed_instances)
for instance in all_instances:
for var_name in instance.openapi_types:
for var_name in instance.openapi_types():
if var_name not in var_name_to_model_instances:
var_name_to_model_instances[var_name] = [instance]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,16 @@ definitions:
properties:
_class:
type: string
Player:
type: object
required:
- name
properties:
name:
type: string
enemyPlayer:
type: object
$ref: '#/components/schemas/Player'
Dog:
allOf:
- $ref: '#/definitions/Animal'
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Class | Method | HTTP request | Description
- [parent_all_of.ParentAllOf](docs/ParentAllOf.md)
- [parent_pet.ParentPet](docs/ParentPet.md)
- [pet.Pet](docs/Pet.md)
- [player.Player](docs/Player.md)
- [read_only_first.ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [special_model_name.SpecialModelName](docs/SpecialModelName.md)
- [string_boolean_map.StringBooleanMap](docs/StringBooleanMap.md)
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/python-experimental/docs/Player.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# player.Player

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | |
**enemy_player** | [**Player**](Player.md) | | [optional]

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


Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
from petstore_api.models.parent_all_of import ParentAllOf
from petstore_api.models.parent_pet import ParentPet
from petstore_api.models.pet import Pet
from petstore_api.models.player import Player
from petstore_api.models.read_only_first import ReadOnlyFirst
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.string_boolean_map import StringBooleanMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def set_attribute(self, name, value):
path_to_item.extend(self._path_to_item)
path_to_item.append(name)

if name in self.openapi_types:
required_types_mixed = self.openapi_types[name]
openapi_types = self.openapi_types()
if name in openapi_types:
required_types_mixed = openapi_types[name]
elif self.additional_properties_type is None:
raise ApiKeyError(
"{0} has no key '{1}'".format(type(self).__name__, name),
Expand Down Expand Up @@ -1181,7 +1182,7 @@ def get_allof_instances(self, model_args, constant_args):

# extract a dict of only required keys from fixed_model_args
kwargs = {}
var_names = set(allof_class.openapi_types.keys())
var_names = set(allof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -1216,7 +1217,7 @@ def get_oneof_instance(self, model_args, constant_args):

# extract a dict of only required keys from fixed_model_args
kwargs = {}
var_names = set(oneof_class.openapi_types.keys())
var_names = set(oneof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -1259,7 +1260,7 @@ def get_anyof_instances(self, model_args, constant_args):

# extract a dict of only required keys from these_model_vars
kwargs = {}
var_names = set(anyof_class.openapi_types.keys())
var_names = set(anyof_class.openapi_types().keys())
for var_name in var_names:
if var_name in fixed_model_args:
kwargs[var_name] = fixed_model_args[var_name]
Expand Down Expand Up @@ -1296,7 +1297,7 @@ def get_var_name_to_model_instances(self, composed_instances):
all_instances = [self]
all_instances.extend(composed_instances)
for instance in all_instances:
for var_name in instance.openapi_types:
for var_name in instance.openapi_types():
if var_name not in var_name_to_model_instances:
var_name_to_model_instances[var_name] = [instance]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class AdditionalPropertiesAnyType(ModelNormal):
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.
openapi_types (dict): The key is attribute name
and the value is attribute type.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
Expand All @@ -59,15 +57,25 @@ class AdditionalPropertiesAnyType(ModelNormal):
allowed_values = {
}

openapi_types = {
'name': (str,), # noqa: E501
}

validations = {
}

additional_properties_type = (bool, date, datetime, dict, float, int, list, str,) # noqa: E501

@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import

Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'name': (str,), # noqa: E501
}

@staticmethod
def discriminator():
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class AdditionalPropertiesArray(ModelNormal):
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.
openapi_types (dict): The key is attribute name
and the value is attribute type.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
Expand All @@ -59,15 +57,25 @@ class AdditionalPropertiesArray(ModelNormal):
allowed_values = {
}

openapi_types = {
'name': (str,), # noqa: E501
}

validations = {
}

additional_properties_type = ([bool, date, datetime, dict, float, int, list, str],) # noqa: E501

@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import

Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'name': (str,), # noqa: E501
}

@staticmethod
def discriminator():
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class AdditionalPropertiesBoolean(ModelNormal):
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.
openapi_types (dict): The key is attribute name
and the value is attribute type.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
Expand All @@ -59,15 +57,25 @@ class AdditionalPropertiesBoolean(ModelNormal):
allowed_values = {
}

openapi_types = {
'name': (str,), # noqa: E501
}

validations = {
}

additional_properties_type = (bool,) # noqa: E501

@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import

Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'name': (str,), # noqa: E501
}

@staticmethod
def discriminator():
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class AdditionalPropertiesClass(ModelNormal):
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.
openapi_types (dict): The key is attribute name
and the value is attribute type.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
Expand All @@ -59,25 +57,35 @@ class AdditionalPropertiesClass(ModelNormal):
allowed_values = {
}

openapi_types = {
'map_string': ({str: (str,)},), # noqa: E501
'map_number': ({str: (float,)},), # noqa: E501
'map_integer': ({str: (int,)},), # noqa: E501
'map_boolean': ({str: (bool,)},), # noqa: E501
'map_array_integer': ({str: ([int],)},), # noqa: E501
'map_array_anytype': ({str: ([bool, date, datetime, dict, float, int, list, str],)},), # noqa: E501
'map_map_string': ({str: ({str: (str,)},)},), # noqa: E501
'map_map_anytype': ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)},), # noqa: E501
'anytype_1': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
'anytype_2': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
'anytype_3': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
}

validations = {
}

additional_properties_type = None

@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import

Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
'map_string': ({str: (str,)},), # noqa: E501
'map_number': ({str: (float,)},), # noqa: E501
'map_integer': ({str: (int,)},), # noqa: E501
'map_boolean': ({str: (bool,)},), # noqa: E501
'map_array_integer': ({str: ([int],)},), # noqa: E501
'map_array_anytype': ({str: ([bool, date, datetime, dict, float, int, list, str],)},), # noqa: E501
'map_map_string': ({str: ({str: (str,)},)},), # noqa: E501
'map_map_anytype': ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)},), # noqa: E501
'anytype_1': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
'anytype_2': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
'anytype_3': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
}

@staticmethod
def discriminator():
return None
Expand Down
Loading