Skip to content

Commit

Permalink
Adds a Player model with a self type rpoperty, adds a test to ensure …
Browse files Browse the repository at this point in the history
…that it is working right
  • Loading branch information
spacether committed Dec 29, 2019
1 parent a8aafb6 commit 9d4c211
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
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
2 changes: 1 addition & 1 deletion samples/client/petstore/python-experimental/docs/Player.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | |
**enemy_player** | [**player.Player**](Player.md) | | [optional]
**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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def openapi_types():
"""
return {
'name': (str,), # noqa: E501
'enemy_player': (player.Player,), # noqa: E501
'enemy_player': (Player,), # noqa: E501
}

@staticmethod
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, name, _check_type=True, _from_server=False, _path_to_item=(),
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
enemy_player (player.Player): [optional] # noqa: E501
enemy_player (Player): [optional] # noqa: E501
"""

self._data_store = {}
Expand Down
12 changes: 9 additions & 3 deletions samples/client/petstore/python-experimental/test/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ def tearDown(self):

def testPlayer(self):
"""Test Player"""
# FIXME: construct object with mandatory attributes with example values
# model = petstore_api.Player() # noqa: E501
pass
# we can make a player without an enemy_player property
jane = petstore_api.Player(name="Jane")
# we can make a player with an enemy_player
sally = petstore_api.Player(name="Sally", enemy_player=jane)
# we can make a player with an inline enemy_player
jim = petstore_api.Player(
name="Jim",
enemy_player=petstore_api.Player(name="Sam")
)


if __name__ == '__main__':
Expand Down

0 comments on commit 9d4c211

Please sign in to comment.