Skip to content

Commit b7ba962

Browse files
authored
Merge pull request #8414 from Open-MBEE/issue-8075
[PYTHON] Issue 8075 - additionalProperties support
2 parents 85a20f2 + f84bfd9 commit b7ba962

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+390
-63
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public PythonClientCodegen() {
7777
languageSpecificPrimitives.add("date");
7878
languageSpecificPrimitives.add("object");
7979

80+
instantiationTypes.put("map", "dict");
81+
8082
typeMapping.clear();
8183
typeMapping.put("integer", "int");
8284
typeMapping.put("float", "float");
@@ -350,6 +352,14 @@ public String modelTestFileFolder() {
350352
return outputFolder + File.separatorChar + testFolder;
351353
}
352354

355+
@Override
356+
public String toInstantiationType(Property p) {
357+
if (p instanceof MapProperty) {
358+
return instantiationTypes.get("map");
359+
}
360+
return null;
361+
}
362+
353363
@Override
354364
public String getTypeDeclaration(Property p) {
355365
if (p instanceof ArrayProperty) {

modules/swagger-codegen/src/main/resources/python/api_client.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,12 @@ class ApiClient(object):
620620

621621
instance = klass(**kwargs)
622622

623+
if (isinstance(instance, dict) and
624+
klass.swagger_types is not None and
625+
isinstance(data, dict)):
626+
for key, value in data.items():
627+
if key not in klass.swagger_types:
628+
instance[key] = value
623629
if hasattr(instance, 'get_real_child_model'):
624630
klass_name = instance.get_real_child_model(data)
625631
if klass_name:

modules/swagger-codegen/src/main/resources/python/model.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import six
1414

1515
{{#models}}
1616
{{#model}}
17-
class {{classname}}(object):
17+
class {{classname}}({{#parent}}{{parent}}{{/parent}}{{^parent}}object{{/parent}}):
1818
"""NOTE: This class is auto generated by the swagger code generator program.
1919

2020
Do not edit the class manually.
@@ -194,6 +194,9 @@ class {{classname}}(object):
194194
))
195195
else:
196196
result[attr] = value
197+
if issubclass({{classname}}, dict):
198+
for key, value in self.items():
199+
result[key] = value
197200

198201
return result
199202

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.4.0-SNAPSHOT

samples/client/petstore-security-test/python/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ import time
5050
import petstore_api
5151
from petstore_api.rest import ApiException
5252
from pprint import pprint
53+
5354
# create an instance of the API class
54-
api_instance = petstore_api.FakeApi()
55+
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
5556
test_code_inject____end____rn_n_r = 'test_code_inject____end____rn_n_r_example' # str | To test code injection */ ' \" =end -- \\r\\n \\n \\r (optional)
5657

5758
try:

samples/client/petstore-security-test/python/git_push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ git_remote=`git remote`
3636
if [ "$git_remote" = "" ]; then # git remote not defined
3737

3838
if [ "$GIT_TOKEN" = "" ]; then
39-
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
4040
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
4141
else
4242
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

samples/client/petstore-security-test/python/petstore_api/api_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ def __deserialize_model(self, data, klass):
614614

615615
instance = klass(**kwargs)
616616

617+
if (isinstance(instance, dict) and
618+
klass.swagger_types is not None and
619+
isinstance(data, dict)):
620+
for key, value in data.items():
621+
if key not in klass.swagger_types:
622+
instance[key] = value
617623
if hasattr(instance, 'get_real_child_model'):
618624
klass_name = instance.get_real_child_model(data)
619625
if klass_name:

samples/client/petstore-security-test/python/petstore_api/models/model_return.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def to_dict(self):
9191
))
9292
else:
9393
result[attr] = value
94+
if issubclass(ModelReturn, dict):
95+
for key, value in self.items():
96+
result[key] = value
9497

9598
return result
9699

samples/client/petstore-security-test/python/tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist = py27, py3
44
[testenv]
55
deps=-r{toxinidir}/requirements.txt
66
-r{toxinidir}/test-requirements.txt
7-
7+
88
commands=
99
nosetests \
10-
[]
10+
[]

samples/client/petstore/python/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ import time
5050
import petstore_api
5151
from petstore_api.rest import ApiException
5252
from pprint import pprint
53+
5354
# create an instance of the API class
54-
api_instance = petstore_api.AnotherFakeApi()
55+
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
5556
body = petstore_api.Client() # Client | client model
5657

5758
try:
@@ -74,6 +75,7 @@ Class | Method | HTTP request | Description
7475
*FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
7576
*FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
7677
*FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
78+
*FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
7779
*FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
7880
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
7981
*FakeApi* | [**test_enum_parameters**](docs/FakeApi.md#test_enum_parameters) | **GET** /fake | To test enum parameters

0 commit comments

Comments
 (0)