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

Commit f552198

Browse files
authored
Merge pull request #7 from EltonChou/feat_overload_endpoint
Feature: overload endpoint
2 parents e50ed27 + f94e86a commit f552198

File tree

462 files changed

+53452
-3517
lines changed

Some content is hidden

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

462 files changed

+53452
-3517
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,20 @@ _all_accept_content_types = (
374374

375375
class BaseApi(api_client.Api):
376376

377+
@typing.overload
377378
def _{{operationId}}_oapg(
378-
{{> endpoint_args selfType="api_client.Api" }}
379+
{{> endpoint_args isOverload=true skipDeserialization="False"}}
380+
381+
@typing.overload
382+
def _{{operationId}}_oapg(
383+
{{> endpoint_args isOverload=true skipDeserialization="True"}}
384+
385+
@typing.overload
386+
def _{{operationId}}_oapg(
387+
{{> endpoint_args isOverload=true skipDeserialization="null"}}
388+
389+
def _{{operationId}}_oapg(
390+
{{> endpoint_args isOverload=false skipDeserialization="null"}}
379391
"""
380392
{{#if summary}}
381393
{{summary}}
@@ -521,8 +533,20 @@ class BaseApi(api_client.Api):
521533
class {{operationIdCamelCase}}(BaseApi):
522534
# this class is used by api classes that refer to endpoints with operationId fn names
523535

536+
@typing.overload
537+
def {{operationId}}(
538+
{{> endpoint_args isOverload=true skipDeserialization="False"}}
539+
540+
@typing.overload
541+
def {{operationId}}(
542+
{{> endpoint_args isOverload=true skipDeserialization="True"}}
543+
544+
@typing.overload
545+
def {{operationId}}(
546+
{{> endpoint_args isOverload=true skipDeserialization="null"}}
547+
524548
def {{operationId}}(
525-
{{> endpoint_args selfType="BaseApi" }}
549+
{{> endpoint_args isOverload=false skipDeserialization="null"}}
526550
return self._{{operationId}}_oapg(
527551
{{> endpoint_args_passed }}
528552
)
@@ -531,8 +555,20 @@ class {{operationIdCamelCase}}(BaseApi):
531555
class ApiFor{{httpMethod}}(BaseApi):
532556
# this class is used by api classes that refer to endpoints by path and http method names
533557

558+
@typing.overload
559+
def {{httpMethod}}(
560+
{{> endpoint_args isOverload=true skipDeserialization="False"}}
561+
562+
@typing.overload
563+
def {{httpMethod}}(
564+
{{> endpoint_args isOverload=true skipDeserialization="True"}}
565+
566+
@typing.overload
567+
def {{httpMethod}}(
568+
{{> endpoint_args isOverload=true skipDeserialization="null"}}
569+
534570
def {{httpMethod}}(
535-
{{> endpoint_args selfType="BaseApi" }}
571+
{{> endpoint_args isOverload=false skipDeserialization="null"}}
536572
return self._{{operationId}}_oapg(
537573
{{> endpoint_args_passed }}
538574
)
Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
self: {{selfType}},
1+
self,
22
{{#if bodyParam}}
3-
{{#with bodyParam}}
4-
body: typing.Union[{{#each content}}{{#with this.schema}}{{baseName}}, {{> model_templates/schema_python_types }}{{/with}}{{/each}}{{#unless required}}schemas.Unset] = schemas.unset{{else}}]{{/unless}},
5-
{{/with}}
3+
{{#with bodyParam}}
4+
body: typing.Union[{{#each content}}{{#with this.schema}}{{baseName}},{{> model_templates/schema_python_types }}{{/with}}{{/each}}{{#unless required}}schemas.Unset] = schemas.unset{{else}}]{{/unless}},
5+
{{/with}}
66
{{/if}}
77
{{#if queryParams}}
88
query_params: RequestQueryParams = frozendict.frozendict(),
@@ -17,11 +17,11 @@
1717
cookie_params: RequestCookieParams = frozendict.frozendict(),
1818
{{/if}}
1919
{{#with bodyParam}}
20-
{{#each content}}
21-
{{#if @first}}
20+
{{#each content}}
21+
{{#if @first}}
2222
content_type: str = '{{{@key}}}',
23-
{{/if}}
24-
{{/each}}
23+
{{/if}}
24+
{{/each}}
2525
{{/with}}
2626
{{#if produces}}
2727
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -31,16 +31,55 @@
3131
{{/if}}
3232
stream: bool = False,
3333
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
34+
{{#if isOverload}}
35+
{{#eq skipDeserialization "True"}}
36+
skip_deserialization: typing_extensions.Literal[True] = True,
37+
{{/eq}}
38+
{{#eq skipDeserialization "False"}}
39+
skip_deserialization: typing_extensions.Literal[False] = False,
40+
{{/eq}}
41+
{{#eq skipDeserialization "null"}}
3442
skip_deserialization: bool = False,
43+
{{/eq}}
44+
{{else}}
45+
skip_deserialization: bool = False,
46+
{{/if}}
47+
{{#eq skipDeserialization "True"}}
48+
) -> api_client.ApiResponseWithoutDeserialization:
49+
{{/eq}}
50+
{{#eq skipDeserialization "False"}}
51+
) -> typing.Union[{{#each responses}}{{#if isDefault}}ApiResponseForDefault,{{else}}{{#if is2xx}}ApiResponseFor{{code}},{{/if}}{{/if}}{{/each}}api_client.ApiResponse]:
52+
{{/eq}}
53+
{{#eq skipDeserialization "null"}}
54+
{{#if isOverload}}
3555
) -> typing.Union[
36-
{{#each responses}}
37-
{{#if isDefault}}
56+
{{#each responses}}
57+
{{#if isDefault}}
3858
ApiResponseForDefault,
39-
{{else}}
40-
{{#if is2xx}}
59+
{{else}}
60+
{{#if is2xx}}
4161
ApiResponseFor{{code}},
42-
{{/if}}
43-
{{/if}}
44-
{{/each}}
45-
api_client.ApiResponseWithoutDeserialization
62+
{{/if}}
63+
{{/if}}
64+
{{/each}}
65+
api_client.ApiResponseWithoutDeserialization,
4666
]:
67+
{{else}}
68+
) -> typing.Union[
69+
{{#each responses}}
70+
{{#if isDefault}}
71+
ApiResponseForDefault,
72+
{{else}}
73+
{{#if is2xx}}
74+
ApiResponseFor{{code}},
75+
{{/if}}
76+
{{/if}}
77+
{{/each}}
78+
api_client.ApiResponse,
79+
api_client.ApiResponseWithoutDeserialization,
80+
]:
81+
{{/if}}
82+
{{/eq}}
83+
{{#if isOverload}}
84+
...
85+
{{/if}}

samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/paths/request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post.py

Lines changed: 120 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,53 @@ class ApiResponseFor200(api_client.ApiResponse):
5959

6060
class BaseApi(api_client.Api):
6161

62+
@typing.overload
6263
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
63-
self: api_client.Api,
64-
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
64+
self,
65+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
66+
content_type: str = 'application/json',
67+
stream: bool = False,
68+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
69+
skip_deserialization: typing_extensions.Literal[False] = False,
70+
) -> typing.Union[ApiResponseFor200,api_client.ApiResponse]:
71+
...
72+
73+
@typing.overload
74+
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
75+
self,
76+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
77+
content_type: str = 'application/json',
78+
stream: bool = False,
79+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
80+
skip_deserialization: typing_extensions.Literal[True] = True,
81+
) -> api_client.ApiResponseWithoutDeserialization:
82+
...
83+
84+
@typing.overload
85+
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
86+
self,
87+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
6588
content_type: str = 'application/json',
6689
stream: bool = False,
6790
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
6891
skip_deserialization: bool = False,
6992
) -> typing.Union[
7093
ApiResponseFor200,
71-
api_client.ApiResponseWithoutDeserialization
94+
api_client.ApiResponseWithoutDeserialization,
95+
]:
96+
...
97+
98+
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
99+
self,
100+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
101+
content_type: str = 'application/json',
102+
stream: bool = False,
103+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
104+
skip_deserialization: bool = False,
105+
) -> typing.Union[
106+
ApiResponseFor200,
107+
api_client.ApiResponse,
108+
api_client.ApiResponseWithoutDeserialization,
72109
]:
73110
"""
74111
:param skip_deserialization: If true then api_response.response will be set but
@@ -119,16 +156,53 @@ class instances
119156
class PostAdditionalpropertiesAllowsASchemaWhichShouldValidateRequestBody(BaseApi):
120157
# this class is used by api classes that refer to endpoints with operationId fn names
121158

159+
@typing.overload
160+
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
161+
self,
162+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
163+
content_type: str = 'application/json',
164+
stream: bool = False,
165+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
166+
skip_deserialization: typing_extensions.Literal[False] = False,
167+
) -> typing.Union[ApiResponseFor200,api_client.ApiResponse]:
168+
...
169+
170+
@typing.overload
171+
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
172+
self,
173+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
174+
content_type: str = 'application/json',
175+
stream: bool = False,
176+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
177+
skip_deserialization: typing_extensions.Literal[True] = True,
178+
) -> api_client.ApiResponseWithoutDeserialization:
179+
...
180+
181+
@typing.overload
122182
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
123-
self: BaseApi,
124-
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
183+
self,
184+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
125185
content_type: str = 'application/json',
126186
stream: bool = False,
127187
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
128188
skip_deserialization: bool = False,
129189
) -> typing.Union[
130190
ApiResponseFor200,
131-
api_client.ApiResponseWithoutDeserialization
191+
api_client.ApiResponseWithoutDeserialization,
192+
]:
193+
...
194+
195+
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
196+
self,
197+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
198+
content_type: str = 'application/json',
199+
stream: bool = False,
200+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
201+
skip_deserialization: bool = False,
202+
) -> typing.Union[
203+
ApiResponseFor200,
204+
api_client.ApiResponse,
205+
api_client.ApiResponseWithoutDeserialization,
132206
]:
133207
return self._post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
134208
body=body,
@@ -142,16 +216,53 @@ def post_additionalproperties_allows_a_schema_which_should_validate_request_body
142216
class ApiForpost(BaseApi):
143217
# this class is used by api classes that refer to endpoints by path and http method names
144218

219+
@typing.overload
220+
def post(
221+
self,
222+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
223+
content_type: str = 'application/json',
224+
stream: bool = False,
225+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
226+
skip_deserialization: typing_extensions.Literal[False] = False,
227+
) -> typing.Union[ApiResponseFor200,api_client.ApiResponse]:
228+
...
229+
230+
@typing.overload
231+
def post(
232+
self,
233+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
234+
content_type: str = 'application/json',
235+
stream: bool = False,
236+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
237+
skip_deserialization: typing_extensions.Literal[True] = True,
238+
) -> api_client.ApiResponseWithoutDeserialization:
239+
...
240+
241+
@typing.overload
242+
def post(
243+
self,
244+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
245+
content_type: str = 'application/json',
246+
stream: bool = False,
247+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
248+
skip_deserialization: bool = False,
249+
) -> typing.Union[
250+
ApiResponseFor200,
251+
api_client.ApiResponseWithoutDeserialization,
252+
]:
253+
...
254+
145255
def post(
146-
self: BaseApi,
147-
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
256+
self,
257+
body: typing.Union[SchemaForRequestBodyApplicationJson,],
148258
content_type: str = 'application/json',
149259
stream: bool = False,
150260
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
151261
skip_deserialization: bool = False,
152262
) -> typing.Union[
153263
ApiResponseFor200,
154-
api_client.ApiResponseWithoutDeserialization
264+
api_client.ApiResponse,
265+
api_client.ApiResponseWithoutDeserialization,
155266
]:
156267
return self._post_additionalproperties_allows_a_schema_which_should_validate_request_body_oapg(
157268
body=body,

0 commit comments

Comments
 (0)