Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 658854b

Browse files
committed
Handles ref request bodies in operation body type hint
1 parent 24d43b1 commit 658854b

10 files changed

Lines changed: 145 additions & 40 deletions

File tree

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/_helper_operation_args_optional.hbs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
{{#if requestBody}}
22
{{#with requestBody}}
33
{{#if refInfo}}
4-
{{#with getDeepestRef}}
5-
{{#unless required}}
6-
body: typing.Union[
7-
{{#each content}}
8-
{{#with schema}}
9-
{{#if refInfo.refClass}}
10-
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" ../../../refInfo.refModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
11-
{{else}}
12-
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" ../../../refInfo.refModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
13-
{{/if}}
14-
{{/with}}
15-
{{/each}}
16-
schemas.Unset,
17-
{{#each getContentSchemas}}
18-
{{> _helper_schema_python_types_newline }}
19-
{{/each}}
20-
] = schemas.unset,
21-
{{/unless}}
22-
{{/with}}
4+
{{> paths/path/verb/_helper_operation_args_ref_body fullRefModule="" requiredValue=true }}
235
{{else}}
246
{{#unless required}}
257
body: typing.Union[
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{#if refInfo}}
2+
{{#with refInfo.ref}}
3+
{{#eq fullRefModule "" }}
4+
{{> paths/path/verb/_helper_operation_args_ref_body fullRefModule=../refInfo.refModule }}
5+
{{else}}
6+
{{> paths/path/verb/_helper_operation_args_ref_body fullRefModule=(join fullRefModule ../refInfo.refModule ".") }}
7+
{{/eq}}
8+
{{/with}}
9+
{{else}}
10+
{{#eq required requiredValue}}
11+
body: typing.Union[
12+
{{#each content}}
13+
{{#with schema}}
14+
{{#if refInfo.refClass}}
15+
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
16+
{{else}}
17+
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
18+
{{/if}}
19+
{{/with}}
20+
{{/each}}
21+
{{#unless required}}
22+
schemas.Unset,
23+
{{/unless}}
24+
{{#each getContentSchemas}}
25+
{{> _helper_schema_python_types_newline }}
26+
{{/each}}
27+
]{{#unless required}} = schemas.unset{{/unless}},
28+
{{/eq}}
29+
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/_helper_operation_args_required.hbs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
{{#if requestBody}}
22
{{#with requestBody}}
33
{{#if refInfo}}
4-
{{#with getDeepestRef}}
5-
{{#if required}}
6-
body: typing.Union[
7-
{{#each content}}
8-
{{#with schema}}
9-
{{#if refInfo.refClass}}
10-
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" ../../../refInfo.refModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
11-
{{else}}
12-
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" ../../../refInfo.refModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
13-
{{/if}}
14-
{{/with}}
15-
{{/each}}
16-
{{#each getContentSchemas}}
17-
{{> _helper_schema_python_types_newline }}
18-
{{/each}}
19-
],
20-
{{/if}}
21-
{{/with}}
4+
{{> paths/path/verb/_helper_operation_args_ref_body fullRefModule="" requiredValue=true }}
225
{{else}}
236
{{#if required}}
247
body: typing.Union[

samples/openapi3/client/petstore/python/src/petstore_api/paths/another_fake_dummy/patch/operation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def _call_123_test__special_tags(
3737
dict,
3838
immutabledict.immutabledict
3939
],
40+
body: typing.Union[
41+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
42+
dict,
43+
immutabledict.immutabledict
44+
],
4045
content_type: typing_extensions.Literal["application/json"] = "application/json",
4146
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4247
server_index: typing.Optional[int] = None,
@@ -53,6 +58,11 @@ def _call_123_test__special_tags(
5358
dict,
5459
immutabledict.immutabledict
5560
],
61+
body: typing.Union[
62+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
63+
dict,
64+
immutabledict.immutabledict
65+
],
5666
content_type: typing_extensions.Literal["application/json"] = "application/json",
5767
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
5868
server_index: typing.Optional[int] = None,
@@ -68,6 +78,11 @@ def _call_123_test__special_tags(
6878
dict,
6979
immutabledict.immutabledict
7080
],
81+
body: typing.Union[
82+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
83+
dict,
84+
immutabledict.immutabledict
85+
],
7186
content_type: typing_extensions.Literal["application/json"] = "application/json",
7287
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7388
server_index: typing.Optional[int] = None,

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/patch/operation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def _client_model(
3737
dict,
3838
immutabledict.immutabledict
3939
],
40+
body: typing.Union[
41+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
42+
dict,
43+
immutabledict.immutabledict
44+
],
4045
content_type: typing_extensions.Literal["application/json"] = "application/json",
4146
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4247
server_index: typing.Optional[int] = None,
@@ -53,6 +58,11 @@ def _client_model(
5358
dict,
5459
immutabledict.immutabledict
5560
],
61+
body: typing.Union[
62+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
63+
dict,
64+
immutabledict.immutabledict
65+
],
5666
content_type: typing_extensions.Literal["application/json"] = "application/json",
5767
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
5868
server_index: typing.Optional[int] = None,
@@ -68,6 +78,11 @@ def _client_model(
6878
dict,
6979
immutabledict.immutabledict
7080
],
81+
body: typing.Union[
82+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
83+
dict,
84+
immutabledict.immutabledict
85+
],
7186
content_type: typing_extensions.Literal["application/json"] = "application/json",
7287
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7388
server_index: typing.Optional[int] = None,

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_classname_test/patch/operation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def _classname(
4242
dict,
4343
immutabledict.immutabledict
4444
],
45+
body: typing.Union[
46+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
47+
dict,
48+
immutabledict.immutabledict
49+
],
4550
content_type: typing_extensions.Literal["application/json"] = "application/json",
4651
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4752
security_index: typing.Optional[int] = None,
@@ -59,6 +64,11 @@ def _classname(
5964
dict,
6065
immutabledict.immutabledict
6166
],
67+
body: typing.Union[
68+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
69+
dict,
70+
immutabledict.immutabledict
71+
],
6272
content_type: typing_extensions.Literal["application/json"] = "application/json",
6373
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6474
security_index: typing.Optional[int] = None,
@@ -75,6 +85,11 @@ def _classname(
7585
dict,
7686
immutabledict.immutabledict
7787
],
88+
body: typing.Union[
89+
request_body.request_body_client.content.application_json.schema.client.ClientDict,
90+
dict,
91+
immutabledict.immutabledict
92+
],
7893
content_type: typing_extensions.Literal["application/json"] = "application/json",
7994
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
8095
security_index: typing.Optional[int] = None,

samples/openapi3/client/petstore/python/src/petstore_api/paths/pet/post/operation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def _add_pet(
5050
dict,
5151
immutabledict.immutabledict
5252
],
53+
body: typing.Union[
54+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
55+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
56+
dict,
57+
immutabledict.immutabledict
58+
],
5359
content_type: typing_extensions.Literal[
5460
"application/json",
5561
"application/xml",
@@ -70,6 +76,12 @@ def _add_pet(
7076
dict,
7177
immutabledict.immutabledict
7278
],
79+
body: typing.Union[
80+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
81+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
82+
dict,
83+
immutabledict.immutabledict
84+
],
7385
content_type: typing_extensions.Literal[
7486
"application/json",
7587
"application/xml",
@@ -89,6 +101,12 @@ def _add_pet(
89101
dict,
90102
immutabledict.immutabledict
91103
],
104+
body: typing.Union[
105+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
106+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
107+
dict,
108+
immutabledict.immutabledict
109+
],
92110
content_type: typing_extensions.Literal[
93111
"application/json",
94112
"application/xml",

samples/openapi3/client/petstore/python/src/petstore_api/paths/pet/put/operation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def _update_pet(
5151
dict,
5252
immutabledict.immutabledict
5353
],
54+
body: typing.Union[
55+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
56+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
57+
dict,
58+
immutabledict.immutabledict
59+
],
5460
content_type: typing_extensions.Literal[
5561
"application/json",
5662
"application/xml",
@@ -70,6 +76,12 @@ def _update_pet(
7076
dict,
7177
immutabledict.immutabledict
7278
],
79+
body: typing.Union[
80+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
81+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
82+
dict,
83+
immutabledict.immutabledict
84+
],
7385
content_type: typing_extensions.Literal[
7486
"application/json",
7587
"application/xml",
@@ -89,6 +101,12 @@ def _update_pet(
89101
dict,
90102
immutabledict.immutabledict
91103
],
104+
body: typing.Union[
105+
request_body.request_body_pet.content.application_json.schema.pet.PetDict,
106+
request_body.request_body_pet.content.application_xml.schema.ref_pet.pet.PetDict,
107+
dict,
108+
immutabledict.immutabledict
109+
],
92110
content_type: typing_extensions.Literal[
93111
"application/json",
94112
"application/xml",

samples/openapi3/client/petstore/python/src/petstore_api/paths/user_create_with_array/post/operation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def _create_users_with_array_input(
2525
list,
2626
tuple
2727
],
28+
body: typing.Union[
29+
request_body.request_body_user_array.content.application_json.schema.SchemaTuple,
30+
list,
31+
tuple
32+
],
2833
content_type: typing_extensions.Literal["application/json"] = "application/json",
2934
server_index: typing.Optional[int] = None,
3035
stream: bool = False,
@@ -40,6 +45,11 @@ def _create_users_with_array_input(
4045
list,
4146
tuple
4247
],
48+
body: typing.Union[
49+
request_body.request_body_user_array.content.application_json.schema.SchemaTuple,
50+
list,
51+
tuple
52+
],
4353
content_type: typing_extensions.Literal["application/json"] = "application/json",
4454
server_index: typing.Optional[int] = None,
4555
stream: bool = False,
@@ -54,6 +64,11 @@ def _create_users_with_array_input(
5464
list,
5565
tuple
5666
],
67+
body: typing.Union[
68+
request_body.request_body_user_array.content.application_json.schema.SchemaTuple,
69+
list,
70+
tuple
71+
],
5772
content_type: typing_extensions.Literal["application/json"] = "application/json",
5873
server_index: typing.Optional[int] = None,
5974
stream: bool = False,

samples/openapi3/client/petstore/python/src/petstore_api/paths/user_create_with_list/post/operation.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ class BaseApi(api_client.Api):
2121
def _create_users_with_list_input(
2222
self,
2323
body: typing.Union[
24-
request_body.request_body_ref_user_array.content.application_json.schema.SchemaTuple,
24+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
25+
list,
26+
tuple
27+
],
28+
body: typing.Union[
29+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
2530
list,
2631
tuple
2732
],
@@ -36,7 +41,12 @@ def _create_users_with_list_input(
3641
def _create_users_with_list_input(
3742
self,
3843
body: typing.Union[
39-
request_body.request_body_ref_user_array.content.application_json.schema.SchemaTuple,
44+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
45+
list,
46+
tuple
47+
],
48+
body: typing.Union[
49+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
4050
list,
4151
tuple
4252
],
@@ -50,7 +60,12 @@ def _create_users_with_list_input(
5060
def _create_users_with_list_input(
5161
self,
5262
body: typing.Union[
53-
request_body.request_body_ref_user_array.content.application_json.schema.SchemaTuple,
63+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
64+
list,
65+
tuple
66+
],
67+
body: typing.Union[
68+
request_body.request_body_ref_user_array.request_body_user_array.content.application_json.schema.SchemaTuple,
5469
list,
5570
tuple
5671
],

0 commit comments

Comments
 (0)