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

Commit eb26ffe

Browse files
committed
Adds partials for content type and body relationship
1 parent cfc9993 commit eb26ffe

File tree

77 files changed

+1920
-1831
lines changed

Some content is hidden

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

77 files changed

+1920
-1831
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ _all_accept_content_types = (
375375
class BaseApi(api_client.Api):
376376
{{#if bodyParam}}
377377
{{#each getContentTypeToOperation}}
378-
{{> endpoint_args_wrapper contentType=@key}}
378+
{{> endpoint_args_baseapi_wrapper contentType=@key this=this}}
379379
{{/each}}
380380
{{else}}
381381
@typing.overload
@@ -538,13 +538,19 @@ class BaseApi(api_client.Api):
538538
class {{operationIdCamelCase}}(BaseApi):
539539
# this class is used by api classes that refer to endpoints with operationId fn names
540540

541+
{{#if bodyParam}}
542+
{{#each getContentTypeToOperation}}
543+
{{> endpoint_args_operationid_wrapper contentType=@key this=this}}
544+
{{/each}}
545+
{{else}}
541546
@typing.overload
542547
def {{operationId}}(
543-
{{> endpoint_args isOverload=true skipDeserialization="False"}}
548+
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="null"}}
549+
{{/if}}
544550

545551
@typing.overload
546552
def {{operationId}}(
547-
{{> endpoint_args isOverload=true skipDeserialization="True"}}
553+
{{> endpoint_args isOverload=true skipDeserialization="True" contentType="null"}}
548554

549555
@typing.overload
550556
def {{operationId}}(
@@ -560,9 +566,15 @@ class {{operationIdCamelCase}}(BaseApi):
560566
class ApiFor{{httpMethod}}(BaseApi):
561567
# this class is used by api classes that refer to endpoints by path and http method names
562568

569+
{{#if bodyParam}}
570+
{{#each getContentTypeToOperation}}
571+
{{> endpoint_args_httpmethod_wrapper contentType=@key this=this}}
572+
{{/each}}
573+
{{else}}
563574
@typing.overload
564575
def {{httpMethod}}(
565-
{{> endpoint_args isOverload=true skipDeserialization="False"}}
576+
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="null"}}
577+
{{/if}}
566578

567579
@typing.overload
568580
def {{httpMethod}}(

modules/openapi-json-schema-generator/src/main/resources/python/endpoint_args.handlebars

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,22 @@
3333
cookie_params: RequestCookieParams = frozendict.frozendict(),
3434
{{/if}}
3535
{{#if bodyParam}}
36-
{{#if isOverload}}
37-
{{else}}
38-
content_type: typing_extensions.Literal["{{contentType}}"] = '{{contentType}}',
36+
{{#if isOverload}}
37+
{{#eq contentType "null"}}
38+
content_type: str = ...,
39+
{{else}}
40+
content_type: typing_extensions.Literal["{{{contentType}}}"] = "{{{contentType}}}",
41+
{{/eq}}
42+
{{else}}
43+
{{#with bodyParam}}
44+
{{#each content}}
45+
{{#if @first}}
46+
content_type: str = '{{{@key}}}',
47+
{{/if}}
48+
{{/each}}
49+
{{/with}}
50+
{{/if}}
3951
{{/if}}
40-
content_type: typing_extensions.Literal["{{contentType}}"] = '{{contentType}}',
41-
{{/with}}
4252
{{#if produces}}
4353
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
4454
{{/if}}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
contentType="{{{contentType}}}"
21
@typing.overload
32
{{#with this}}
43
def _{{operationId}}_oapg(
5-
{{> endpoint_args isOverload=true skipDeserialization="False" contentType="{{{contentType}}}"}}
4+
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
65
{{/with}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@typing.overload
2+
{{#with this}}
3+
def {{httpMethod}}(
4+
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
5+
{{/with}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@typing.overload
2+
{{#with this}}
3+
def {{operationId}}(
4+
{{> endpoint_args isOverload=true skipDeserialization="False" contentType=contentType}}
5+
{{/with}}

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ class ApiResponseFor200(api_client.ApiResponse):
6868

6969

7070
class BaseApi(api_client.Api):
71-
contentType="application/json"
7271
@typing.overload
7372
def _call_123_test_special_tags_oapg(
7473
self,
75-
body: typing.Union[],
76-
content_type: typing_extensions.Literal[""] = '',
74+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
75+
content_type: typing_extensions.Literal["application/json"] = "application/json",
7776
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
7877
stream: bool = False,
7978
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -85,9 +84,9 @@ def _call_123_test_special_tags_oapg(
8584
@typing.overload
8685
def _call_123_test_special_tags_oapg(
8786
self,
88-
body: typing.Union[],
87+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
8988
skip_deserialization: typing_extensions.Literal[True],
90-
content_type: typing_extensions.Literal[""] = '',
89+
content_type: str = ...,
9190
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
9291
stream: bool = False,
9392
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -96,8 +95,8 @@ def _call_123_test_special_tags_oapg(
9695
@typing.overload
9796
def _call_123_test_special_tags_oapg(
9897
self,
99-
body: typing.Union[],
100-
content_type: typing_extensions.Literal[""] = '',
98+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
99+
content_type: str = ...,
101100
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
102101
stream: bool = False,
103102
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -109,8 +108,8 @@ def _call_123_test_special_tags_oapg(
109108

110109
def _call_123_test_special_tags_oapg(
111110
self,
112-
body: typing.Union[],
113-
content_type: typing_extensions.Literal[""] = '',
111+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
112+
content_type: str = 'application/json',
114113
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
115114
stream: bool = False,
116115
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -172,8 +171,8 @@ class Call123TestSpecialTags(BaseApi):
172171
@typing.overload
173172
def call_123_test_special_tags(
174173
self,
175-
body: typing.Union[],
176-
content_type: typing_extensions.Literal[""] = '',
174+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
175+
content_type: typing_extensions.Literal["application/json"] = "application/json",
177176
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
178177
stream: bool = False,
179178
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -185,9 +184,9 @@ def call_123_test_special_tags(
185184
@typing.overload
186185
def call_123_test_special_tags(
187186
self,
188-
body: typing.Union[],
187+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
189188
skip_deserialization: typing_extensions.Literal[True],
190-
content_type: typing_extensions.Literal[""] = '',
189+
content_type: str = ...,
191190
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
192191
stream: bool = False,
193192
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -196,8 +195,8 @@ def call_123_test_special_tags(
196195
@typing.overload
197196
def call_123_test_special_tags(
198197
self,
199-
body: typing.Union[],
200-
content_type: typing_extensions.Literal[""] = '',
198+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
199+
content_type: str = ...,
201200
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
202201
stream: bool = False,
203202
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -209,8 +208,8 @@ def call_123_test_special_tags(
209208

210209
def call_123_test_special_tags(
211210
self,
212-
body: typing.Union[],
213-
content_type: typing_extensions.Literal[""] = '',
211+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
212+
content_type: str = 'application/json',
214213
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
215214
stream: bool = False,
216215
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -232,8 +231,8 @@ class ApiForpatch(BaseApi):
232231
@typing.overload
233232
def patch(
234233
self,
235-
body: typing.Union[],
236-
content_type: typing_extensions.Literal[""] = '',
234+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
235+
content_type: typing_extensions.Literal["application/json"] = "application/json",
237236
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
238237
stream: bool = False,
239238
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -245,9 +244,9 @@ def patch(
245244
@typing.overload
246245
def patch(
247246
self,
248-
body: typing.Union[],
247+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
249248
skip_deserialization: typing_extensions.Literal[True],
250-
content_type: typing_extensions.Literal[""] = '',
249+
content_type: str = ...,
251250
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
252251
stream: bool = False,
253252
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -256,8 +255,8 @@ def patch(
256255
@typing.overload
257256
def patch(
258257
self,
259-
body: typing.Union[],
260-
content_type: typing_extensions.Literal[""] = '',
258+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
259+
content_type: str = ...,
261260
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
262261
stream: bool = False,
263262
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -269,8 +268,8 @@ def patch(
269268

270269
def patch(
271270
self,
272-
body: typing.Union[],
273-
content_type: typing_extensions.Literal[""] = '',
271+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
272+
content_type: str = 'application/json',
274273
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
275274
stream: bool = False,
276275
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,

samples/openapi3/client/petstore/python/petstore_api/paths/another_fake_dummy/patch.pyi

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ _all_accept_content_types = (
6363

6464

6565
class BaseApi(api_client.Api):
66-
contentType="application/json"
6766
@typing.overload
6867
def _call_123_test_special_tags_oapg(
6968
self,
70-
body: typing.Union[],
71-
content_type: typing_extensions.Literal[""] = '',
69+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
70+
content_type: typing_extensions.Literal["application/json"] = "application/json",
7271
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
7372
stream: bool = False,
7473
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -80,9 +79,9 @@ class BaseApi(api_client.Api):
8079
@typing.overload
8180
def _call_123_test_special_tags_oapg(
8281
self,
83-
body: typing.Union[],
82+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
8483
skip_deserialization: typing_extensions.Literal[True],
85-
content_type: typing_extensions.Literal[""] = '',
84+
content_type: str = ...,
8685
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
8786
stream: bool = False,
8887
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -91,8 +90,8 @@ class BaseApi(api_client.Api):
9190
@typing.overload
9291
def _call_123_test_special_tags_oapg(
9392
self,
94-
body: typing.Union[],
95-
content_type: typing_extensions.Literal[""] = '',
93+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
94+
content_type: str = ...,
9695
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
9796
stream: bool = False,
9897
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -104,8 +103,8 @@ class BaseApi(api_client.Api):
104103

105104
def _call_123_test_special_tags_oapg(
106105
self,
107-
body: typing.Union[],
108-
content_type: typing_extensions.Literal[""] = '',
106+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
107+
content_type: str = 'application/json',
109108
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
110109
stream: bool = False,
111110
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -167,8 +166,8 @@ class Call123TestSpecialTags(BaseApi):
167166
@typing.overload
168167
def call_123_test_special_tags(
169168
self,
170-
body: typing.Union[],
171-
content_type: typing_extensions.Literal[""] = '',
169+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
170+
content_type: typing_extensions.Literal["application/json"] = "application/json",
172171
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
173172
stream: bool = False,
174173
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -180,9 +179,9 @@ class Call123TestSpecialTags(BaseApi):
180179
@typing.overload
181180
def call_123_test_special_tags(
182181
self,
183-
body: typing.Union[],
182+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
184183
skip_deserialization: typing_extensions.Literal[True],
185-
content_type: typing_extensions.Literal[""] = '',
184+
content_type: str = ...,
186185
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
187186
stream: bool = False,
188187
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -191,8 +190,8 @@ class Call123TestSpecialTags(BaseApi):
191190
@typing.overload
192191
def call_123_test_special_tags(
193192
self,
194-
body: typing.Union[],
195-
content_type: typing_extensions.Literal[""] = '',
193+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
194+
content_type: str = ...,
196195
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
197196
stream: bool = False,
198197
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -204,8 +203,8 @@ class Call123TestSpecialTags(BaseApi):
204203

205204
def call_123_test_special_tags(
206205
self,
207-
body: typing.Union[],
208-
content_type: typing_extensions.Literal[""] = '',
206+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
207+
content_type: str = 'application/json',
209208
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
210209
stream: bool = False,
211210
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -227,8 +226,8 @@ class ApiForpatch(BaseApi):
227226
@typing.overload
228227
def patch(
229228
self,
230-
body: typing.Union[],
231-
content_type: typing_extensions.Literal[""] = '',
229+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
230+
content_type: typing_extensions.Literal["application/json"] = "application/json",
232231
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
233232
stream: bool = False,
234233
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -240,9 +239,9 @@ class ApiForpatch(BaseApi):
240239
@typing.overload
241240
def patch(
242241
self,
243-
body: typing.Union[],
242+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
244243
skip_deserialization: typing_extensions.Literal[True],
245-
content_type: typing_extensions.Literal[""] = '',
244+
content_type: str = ...,
246245
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
247246
stream: bool = False,
248247
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -251,8 +250,8 @@ class ApiForpatch(BaseApi):
251250
@typing.overload
252251
def patch(
253252
self,
254-
body: typing.Union[],
255-
content_type: typing_extensions.Literal[""] = '',
253+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
254+
content_type: str = ...,
256255
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
257256
stream: bool = False,
258257
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
@@ -264,8 +263,8 @@ class ApiForpatch(BaseApi):
264263

265264
def patch(
266265
self,
267-
body: typing.Union[],
268-
content_type: typing_extensions.Literal[""] = '',
266+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
267+
content_type: str = 'application/json',
269268
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
270269
stream: bool = False,
271270
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,

0 commit comments

Comments
 (0)