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

Commit f5ccbe3

Browse files
committed
Simplifies operation request body input type template
1 parent f99e312 commit f5ccbe3

File tree

38 files changed

+440
-205
lines changed

38 files changed

+440
-205
lines changed

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,13 @@
77
{{/eq}}
88
{{/with}}
99
{{else}}
10-
{{#eq required requiredValue}}
11-
body: typing.Union[
12-
{{#each content}}
13-
{{#with schema}}
14-
{{#eq fullRefModule null}}
15-
{{#if refInfo.refClass}}
16-
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" "content" ../@key.snakeCase "schema" ".") endChar="," }}
17-
{{else}}
18-
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" "content" ../@key.snakeCase "schema" ".") endChar="," }}
19-
{{/if}}
20-
{{else}}
21-
{{#if refInfo.refClass}}
22-
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
23-
{{else}}
24-
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
25-
{{/if}}
26-
{{/eq}}
27-
{{/with}}
28-
{{/each}}
10+
{{#if requiredValue}}
11+
{{#if required}}
12+
{{> paths/path/verb/_helper_operation_args_body_nonref }}
13+
{{/if}}
14+
{{else}}
2915
{{#unless required}}
30-
schemas.Unset,
16+
{{> paths/path/verb/_helper_operation_args_body_nonref }}
3117
{{/unless}}
32-
{{#each getContentSchemas}}
33-
{{> _helper_schema_python_types_newline }}
34-
{{/each}}
35-
]{{#unless required}} = schemas.unset{{/unless}},
36-
{{/eq}}
18+
{{/if}}
3719
{{/if}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
body: typing.Union[
2+
{{#each content}}
3+
{{#with schema}}
4+
{{#eq fullRefModule null}}
5+
{{#if refInfo.refClass}}
6+
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" "content" ../@key.snakeCase "schema" ".") endChar="," }}
7+
{{else}}
8+
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" "content" ../@key.snakeCase "schema" ".") endChar="," }}
9+
{{/if}}
10+
{{else}}
11+
{{#if refInfo.refClass}}
12+
{{> components/schemas/_helper_schema_output_ref_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
13+
{{else}}
14+
{{> components/schemas/_helper_schema_output_type mode="unprefixed" fullRefModule=(join "request_body" fullRefModule "content" ../@key.snakeCase "schema" ".") endChar="," }}
15+
{{/if}}
16+
{{/eq}}
17+
{{/with}}
18+
{{/each}}
19+
{{#unless required}}
20+
schemas.Unset,
21+
{{/unless}}
22+
{{#each getContentSchemas}}
23+
{{> _helper_schema_python_types_newline }}
24+
{{/each}}
25+
]{{#unless required}} = schemas.unset{{/unless}},

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def _call_123_test__special_tags(
3636
request_body.request_body_client.content.application_json.schema.client.ClientDict,
3737
dict,
3838
immutabledict.immutabledict
39-
],
40-
content_type: typing_extensions.Literal["application/json"] = "application/json",
39+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
4140
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4241
server_index: typing.Optional[int] = None,
4342
stream: bool = False,
@@ -52,8 +51,7 @@ def _call_123_test__special_tags(
5251
request_body.request_body_client.content.application_json.schema.client.ClientDict,
5352
dict,
5453
immutabledict.immutabledict
55-
],
56-
content_type: typing_extensions.Literal["application/json"] = "application/json",
54+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
5755
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
5856
server_index: typing.Optional[int] = None,
5957
stream: bool = False,
@@ -67,8 +65,7 @@ def _call_123_test__special_tags(
6765
request_body.request_body_client.content.application_json.schema.client.ClientDict,
6866
dict,
6967
immutabledict.immutabledict
70-
],
71-
content_type: typing_extensions.Literal["application/json"] = "application/json",
68+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
7269
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7370
server_index: typing.Optional[int] = None,
7471
stream: bool = False,

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ class BaseApi(api_client.Api):
9999
@typing.overload
100100
def _enum_parameters(
101101
self,
102-
query_params: typing.Optional[RequestQueryParameters.Params] = None,
102+
body: typing.Union[
103+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
104+
schemas.Unset,
105+
dict,
106+
immutabledict.immutabledict
107+
] = schemas.unset, query_params: typing.Optional[RequestQueryParameters.Params] = None,
103108
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
104109
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
105110
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
@@ -112,7 +117,12 @@ def _enum_parameters(
112117
@typing.overload
113118
def _enum_parameters(
114119
self,
115-
query_params: typing.Optional[RequestQueryParameters.Params] = None,
120+
body: typing.Union[
121+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
122+
schemas.Unset,
123+
dict,
124+
immutabledict.immutabledict
125+
] = schemas.unset, query_params: typing.Optional[RequestQueryParameters.Params] = None,
116126
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
117127
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
118128
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
@@ -124,7 +134,12 @@ def _enum_parameters(
124134

125135
def _enum_parameters(
126136
self,
127-
query_params: typing.Optional[RequestQueryParameters.Params] = None,
137+
body: typing.Union[
138+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
139+
schemas.Unset,
140+
dict,
141+
immutabledict.immutabledict
142+
] = schemas.unset, query_params: typing.Optional[RequestQueryParameters.Params] = None,
128143
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
129144
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
130145
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def _client_model(
3636
request_body.request_body_client.content.application_json.schema.client.ClientDict,
3737
dict,
3838
immutabledict.immutabledict
39-
],
40-
content_type: typing_extensions.Literal["application/json"] = "application/json",
39+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
4140
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4241
server_index: typing.Optional[int] = None,
4342
stream: bool = False,
@@ -52,8 +51,7 @@ def _client_model(
5251
request_body.request_body_client.content.application_json.schema.client.ClientDict,
5352
dict,
5453
immutabledict.immutabledict
55-
],
56-
content_type: typing_extensions.Literal["application/json"] = "application/json",
54+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
5755
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
5856
server_index: typing.Optional[int] = None,
5957
stream: bool = False,
@@ -67,8 +65,7 @@ def _client_model(
6765
request_body.request_body_client.content.application_json.schema.client.ClientDict,
6866
dict,
6967
immutabledict.immutabledict
70-
],
71-
content_type: typing_extensions.Literal["application/json"] = "application/json",
68+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
7269
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7370
server_index: typing.Optional[int] = None,
7471
stream: bool = False,

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ class BaseApi(api_client.Api):
3838
@typing.overload
3939
def _endpoint_parameters(
4040
self,
41-
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
41+
body: typing.Union[
42+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
43+
schemas.Unset,
44+
dict,
45+
immutabledict.immutabledict
46+
] = schemas.unset, content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
4247
security_index: typing.Optional[int] = None,
4348
server_index: typing.Optional[int] = None,
4449
stream: bool = False,
@@ -49,7 +54,12 @@ def _endpoint_parameters(
4954
@typing.overload
5055
def _endpoint_parameters(
5156
self,
52-
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
57+
body: typing.Union[
58+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
59+
schemas.Unset,
60+
dict,
61+
immutabledict.immutabledict
62+
] = schemas.unset, content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
5363
security_index: typing.Optional[int] = None,
5464
server_index: typing.Optional[int] = None,
5565
stream: bool = False,
@@ -59,7 +69,12 @@ def _endpoint_parameters(
5969

6070
def _endpoint_parameters(
6171
self,
62-
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
72+
body: typing.Union[
73+
request_body.content.application_x_www_form_urlencoded.schema.SchemaDict,
74+
schemas.Unset,
75+
dict,
76+
immutabledict.immutabledict
77+
] = schemas.unset, content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
6378
security_index: typing.Optional[int] = None,
6479
server_index: typing.Optional[int] = None,
6580
stream: bool = False,

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_additional_properties_with_array_of_enums/get/operation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def _additional_properties_with_array_of_enums(
3737
schemas.Unset,
3838
dict,
3939
immutabledict.immutabledict
40-
] = schemas.unset,
41-
content_type: typing_extensions.Literal["application/json"] = "application/json",
40+
] = schemas.unset, content_type: typing_extensions.Literal["application/json"] = "application/json",
4241
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4342
server_index: typing.Optional[int] = None,
4443
stream: bool = False,
@@ -54,8 +53,7 @@ def _additional_properties_with_array_of_enums(
5453
schemas.Unset,
5554
dict,
5655
immutabledict.immutabledict
57-
] = schemas.unset,
58-
content_type: typing_extensions.Literal["application/json"] = "application/json",
56+
] = schemas.unset, content_type: typing_extensions.Literal["application/json"] = "application/json",
5957
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6058
server_index: typing.Optional[int] = None,
6159
stream: bool = False,
@@ -70,8 +68,7 @@ def _additional_properties_with_array_of_enums(
7068
schemas.Unset,
7169
dict,
7270
immutabledict.immutabledict
73-
] = schemas.unset,
74-
content_type: typing_extensions.Literal["application/json"] = "application/json",
71+
] = schemas.unset, content_type: typing_extensions.Literal["application/json"] = "application/json",
7572
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7673
server_index: typing.Optional[int] = None,
7774
stream: bool = False,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def _body_with_file_schema(
3232
request_body.content.application_json.schema.file_schema_test_class.FileSchemaTestClassDict,
3333
dict,
3434
immutabledict.immutabledict
35-
],
36-
content_type: typing_extensions.Literal["application/json"] = "application/json",
35+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
3736
server_index: typing.Optional[int] = None,
3837
stream: bool = False,
3938
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -47,8 +46,7 @@ def _body_with_file_schema(
4746
request_body.content.application_json.schema.file_schema_test_class.FileSchemaTestClassDict,
4847
dict,
4948
immutabledict.immutabledict
50-
],
51-
content_type: typing_extensions.Literal["application/json"] = "application/json",
49+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
5250
server_index: typing.Optional[int] = None,
5351
stream: bool = False,
5452
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -61,8 +59,7 @@ def _body_with_file_schema(
6159
request_body.content.application_json.schema.file_schema_test_class.FileSchemaTestClassDict,
6260
dict,
6361
immutabledict.immutabledict
64-
],
65-
content_type: typing_extensions.Literal["application/json"] = "application/json",
62+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
6663
server_index: typing.Optional[int] = None,
6764
stream: bool = False,
6865
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def _body_with_query_params(
5656
request_body.content.application_json.schema.user.UserDict,
5757
dict,
5858
immutabledict.immutabledict
59-
],
60-
query_params: RequestQueryParameters.Params,
59+
], query_params: RequestQueryParameters.Params,
6160
content_type: typing_extensions.Literal["application/json"] = "application/json",
6261
server_index: typing.Optional[int] = None,
6362
stream: bool = False,
@@ -72,8 +71,7 @@ def _body_with_query_params(
7271
request_body.content.application_json.schema.user.UserDict,
7372
dict,
7473
immutabledict.immutabledict
75-
],
76-
query_params: RequestQueryParameters.Params,
74+
], query_params: RequestQueryParameters.Params,
7775
content_type: typing_extensions.Literal["application/json"] = "application/json",
7876
server_index: typing.Optional[int] = None,
7977
stream: bool = False,
@@ -87,8 +85,7 @@ def _body_with_query_params(
8785
request_body.content.application_json.schema.user.UserDict,
8886
dict,
8987
immutabledict.immutabledict
90-
],
91-
query_params: RequestQueryParameters.Params,
88+
], query_params: RequestQueryParameters.Params,
9289
content_type: typing_extensions.Literal["application/json"] = "application/json",
9390
server_index: typing.Optional[int] = None,
9491
stream: bool = False,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def _classname(
4141
request_body.request_body_client.content.application_json.schema.client.ClientDict,
4242
dict,
4343
immutabledict.immutabledict
44-
],
45-
content_type: typing_extensions.Literal["application/json"] = "application/json",
44+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
4645
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4746
security_index: typing.Optional[int] = None,
4847
server_index: typing.Optional[int] = None,
@@ -58,8 +57,7 @@ def _classname(
5857
request_body.request_body_client.content.application_json.schema.client.ClientDict,
5958
dict,
6059
immutabledict.immutabledict
61-
],
62-
content_type: typing_extensions.Literal["application/json"] = "application/json",
60+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
6361
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6462
security_index: typing.Optional[int] = None,
6563
server_index: typing.Optional[int] = None,
@@ -74,8 +72,7 @@ def _classname(
7472
request_body.request_body_client.content.application_json.schema.client.ClientDict,
7573
dict,
7674
immutabledict.immutabledict
77-
],
78-
content_type: typing_extensions.Literal["application/json"] = "application/json",
75+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
7976
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
8077
security_index: typing.Optional[int] = None,
8178
server_index: typing.Optional[int] = None,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def _inline_additional_properties(
3232
request_body.content.application_json.schema.SchemaDict,
3333
dict,
3434
immutabledict.immutabledict
35-
],
36-
content_type: typing_extensions.Literal["application/json"] = "application/json",
35+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
3736
server_index: typing.Optional[int] = None,
3837
stream: bool = False,
3938
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -47,8 +46,7 @@ def _inline_additional_properties(
4746
request_body.content.application_json.schema.SchemaDict,
4847
dict,
4948
immutabledict.immutabledict
50-
],
51-
content_type: typing_extensions.Literal["application/json"] = "application/json",
49+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
5250
server_index: typing.Optional[int] = None,
5351
stream: bool = False,
5452
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -61,8 +59,7 @@ def _inline_additional_properties(
6159
request_body.content.application_json.schema.SchemaDict,
6260
dict,
6361
immutabledict.immutabledict
64-
],
65-
content_type: typing_extensions.Literal["application/json"] = "application/json",
62+
], content_type: typing_extensions.Literal["application/json"] = "application/json",
6663
server_index: typing.Optional[int] = None,
6764
stream: bool = False,
6865
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,

0 commit comments

Comments
 (0)