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

Commit 36f4f72

Browse files
committed
v3 reduce typing overloads (#165)
* Removes overrides from api classes * Fixes type hint for operation methods, reduced 2x duplication * Samples updated * Sample regen
1 parent 79aea14 commit 36f4f72

File tree

493 files changed

+1237
-44524
lines changed

Some content is hidden

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

493 files changed

+1237
-44524
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/components/responses/response.hbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ from .headers import {{jsonPathPiece.snakeCase}}
3939

4040

4141
@dataclasses.dataclass
42-
class _ApiResponse(api_client.ApiResponse):
42+
class Api{{jsonPathPiece.camelCase}}(api_client.ApiResponse):
4343
response: urllib3.HTTPResponse
4444
{{#and headers content}}
4545
{{#if hasContentSchema}}
@@ -99,8 +99,8 @@ class _ApiResponse(api_client.ApiResponse):
9999
{{/unless}}
100100

101101

102-
class {{jsonPathPiece.camelCase}}(api_client.OpenApiResponse[_ApiResponse]):
103-
response_cls = _ApiResponse
102+
class {{jsonPathPiece.camelCase}}(api_client.OpenApiResponse[Api{{jsonPathPiece.camelCase}}]):
103+
response_cls = Api{{jsonPathPiece.camelCase}}
104104
{{#each content}}
105105

106106

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

+2-64
Original file line numberDiff line numberDiff line change
@@ -417,72 +417,10 @@ class BaseApi(api_client.Api):
417417

418418
class {{operationId.camelCase}}(BaseApi):
419419
# this class is used by api classes that refer to endpoints with operationId.snakeCase fn names
420-
421-
{{#if requestBody}}
422-
{{#each getContentTypeToOperation}}
423-
@typing.overload
424-
def {{operationId.snakeCase}}(
425-
{{> paths/path/verb/_helper_operation_args isOverload=true skipDeserialization="False" contentType=@key}}
426-
427-
{{/each}}
428-
@typing.overload
429-
def {{operationId.snakeCase}}(
430-
{{> paths/path/verb/_helper_operation_args isOverload=true skipDeserialization="False" contentType="null"}}
431-
432-
{{else}}
433-
@typing.overload
434-
def {{operationId.snakeCase}}(
435-
{{> paths/path/verb/_helper_operation_args isOverload=true skipDeserialization="False" contentType="null"}}
436-
{{/if}}
437-
438-
@typing.overload
439-
def {{operationId.snakeCase}}(
440-
{{> paths/path/verb/_helper_operation_args isOverload=true skipDeserialization="True" contentType="null"}}
441-
442-
@typing.overload
443-
def {{operationId.snakeCase}}(
444-
{{> paths/path/verb/_helper_operation_args isOverload=true skipDeserialization="null" contentType="null"}}
445-
446-
def {{operationId.snakeCase}}(
447-
{{> paths/path/verb/_helper_operation_args isOverload=false skipDeserialization="null" contentType="null"}}
448-
return self._{{operationId.snakeCase}}(
449-
{{> paths/path/verb/_helper_operation_args_passed }}
450-
)
420+
{{operationId.snakeCase}} = BaseApi._{{operationId.snakeCase}}
451421

452422

453423
class ApiFor{{httpMethod.camelCase}}(BaseApi):
454424
# this class is used by api classes that refer to endpoints by path and http method names
455-
456-
{{#if requestBody}}
457-
{{#each getContentTypeToOperation}}
458-
@typing.overload
459-
def {{httpMethod.original}}(
460-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=true skipDeserialization="False" contentType=@key}}
461-
462-
{{/each}}
463-
@typing.overload
464-
def {{httpMethod.original}}(
465-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=true skipDeserialization="False" contentType="null"}}
466-
467-
{{else}}
468-
@typing.overload
469-
def {{httpMethod.original}}(
470-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=true skipDeserialization="False" contentType="null"}}
471-
{{/if}}
472-
473-
@typing.overload
474-
def {{httpMethod.original}}(
475-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=true skipDeserialization="True" contentType="null"}}
476-
477-
@typing.overload
478-
def {{httpMethod.original}}(
479-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=true skipDeserialization="null" contentType="null"}}
480-
481-
def {{httpMethod.original}}(
482-
{{> paths/path/verb/_helper_operation_args rootSecurity=../security isOverload=false skipDeserialization="null" contentType="null"}}
483-
return self._{{operationId.snakeCase}}(
484-
{{> paths/path/verb/_helper_operation_args_passed rootSecurity=../security }}
485-
)
486-
487-
425+
{{httpMethod.original}} = BaseApi._{{operationId.snakeCase}}
488426
{{/with}}

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

+2-174
Original file line numberDiff line numberDiff line change
@@ -181,181 +181,9 @@ class instances
181181

182182
class PostAdditionalpropertiesAllowsASchemaWhichShouldValidateRequestBody(BaseApi):
183183
# this class is used by api classes that refer to endpoints with operationId.snakeCase fn names
184-
185-
@typing.overload
186-
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
187-
self,
188-
body: typing.Union[
189-
request_body.RequestBody.content["application/json"].schema,
190-
dict,
191-
frozendict.frozendict
192-
],
193-
content_type: typing_extensions.Literal["application/json"] = ...,
194-
server_index: typing.Optional[int] = None,
195-
stream: bool = False,
196-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
197-
skip_deserialization: typing_extensions.Literal[False] = ...,
198-
) -> response_200.ResponseFor200.response_cls: ...
199-
200-
@typing.overload
201-
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
202-
self,
203-
body: typing.Union[
204-
request_body.RequestBody.content["application/json"].schema,
205-
dict,
206-
frozendict.frozendict
207-
],
208-
content_type: str = ...,
209-
server_index: typing.Optional[int] = None,
210-
stream: bool = False,
211-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
212-
skip_deserialization: typing_extensions.Literal[False] = ...,
213-
) -> response_200.ResponseFor200.response_cls: ...
214-
215-
216-
@typing.overload
217-
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
218-
self,
219-
body: typing.Union[
220-
request_body.RequestBody.content["application/json"].schema,
221-
dict,
222-
frozendict.frozendict
223-
],
224-
skip_deserialization: typing_extensions.Literal[True],
225-
content_type: str = ...,
226-
server_index: typing.Optional[int] = None,
227-
stream: bool = False,
228-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
229-
) -> api_client.ApiResponseWithoutDeserialization: ...
230-
231-
@typing.overload
232-
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
233-
self,
234-
body: typing.Union[
235-
request_body.RequestBody.content["application/json"].schema,
236-
dict,
237-
frozendict.frozendict
238-
],
239-
content_type: str = ...,
240-
server_index: typing.Optional[int] = None,
241-
stream: bool = False,
242-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
243-
skip_deserialization: bool = ...,
244-
) -> typing.Union[
245-
response_200.ResponseFor200.response_cls,
246-
api_client.ApiResponseWithoutDeserialization,
247-
]: ...
248-
249-
def post_additionalproperties_allows_a_schema_which_should_validate_request_body(
250-
self,
251-
body: typing.Union[
252-
request_body.RequestBody.content["application/json"].schema,
253-
dict,
254-
frozendict.frozendict
255-
],
256-
content_type: str = 'application/json',
257-
server_index: typing.Optional[int] = None,
258-
stream: bool = False,
259-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
260-
skip_deserialization: bool = False,
261-
):
262-
return self._post_additionalproperties_allows_a_schema_which_should_validate_request_body(
263-
body=body,
264-
content_type=content_type,
265-
server_index=server_index,
266-
stream=stream,
267-
timeout=timeout,
268-
skip_deserialization=skip_deserialization
269-
)
184+
post_additionalproperties_allows_a_schema_which_should_validate_request_body = BaseApi._post_additionalproperties_allows_a_schema_which_should_validate_request_body
270185

271186

272187
class ApiForPost(BaseApi):
273188
# this class is used by api classes that refer to endpoints by path and http method names
274-
275-
@typing.overload
276-
def post(
277-
self,
278-
body: typing.Union[
279-
request_body.RequestBody.content["application/json"].schema,
280-
dict,
281-
frozendict.frozendict
282-
],
283-
content_type: typing_extensions.Literal["application/json"] = ...,
284-
server_index: typing.Optional[int] = None,
285-
stream: bool = False,
286-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
287-
skip_deserialization: typing_extensions.Literal[False] = ...,
288-
) -> response_200.ResponseFor200.response_cls: ...
289-
290-
@typing.overload
291-
def post(
292-
self,
293-
body: typing.Union[
294-
request_body.RequestBody.content["application/json"].schema,
295-
dict,
296-
frozendict.frozendict
297-
],
298-
content_type: str = ...,
299-
server_index: typing.Optional[int] = None,
300-
stream: bool = False,
301-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
302-
skip_deserialization: typing_extensions.Literal[False] = ...,
303-
) -> response_200.ResponseFor200.response_cls: ...
304-
305-
306-
@typing.overload
307-
def post(
308-
self,
309-
body: typing.Union[
310-
request_body.RequestBody.content["application/json"].schema,
311-
dict,
312-
frozendict.frozendict
313-
],
314-
skip_deserialization: typing_extensions.Literal[True],
315-
content_type: str = ...,
316-
server_index: typing.Optional[int] = None,
317-
stream: bool = False,
318-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
319-
) -> api_client.ApiResponseWithoutDeserialization: ...
320-
321-
@typing.overload
322-
def post(
323-
self,
324-
body: typing.Union[
325-
request_body.RequestBody.content["application/json"].schema,
326-
dict,
327-
frozendict.frozendict
328-
],
329-
content_type: str = ...,
330-
server_index: typing.Optional[int] = None,
331-
stream: bool = False,
332-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
333-
skip_deserialization: bool = ...,
334-
) -> typing.Union[
335-
response_200.ResponseFor200.response_cls,
336-
api_client.ApiResponseWithoutDeserialization,
337-
]: ...
338-
339-
def post(
340-
self,
341-
body: typing.Union[
342-
request_body.RequestBody.content["application/json"].schema,
343-
dict,
344-
frozendict.frozendict
345-
],
346-
content_type: str = 'application/json',
347-
server_index: typing.Optional[int] = None,
348-
stream: bool = False,
349-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
350-
skip_deserialization: bool = False,
351-
):
352-
return self._post_additionalproperties_allows_a_schema_which_should_validate_request_body(
353-
body=body,
354-
content_type=content_type,
355-
server_index=server_index,
356-
stream=stream,
357-
timeout=timeout,
358-
skip_deserialization=skip_deserialization
359-
)
360-
361-
189+
post = BaseApi._post_additionalproperties_allows_a_schema_which_should_validate_request_body

samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/paths/request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post/responses/response_200/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323

2424
@dataclasses.dataclass
25-
class _ApiResponse(api_client.ApiResponse):
25+
class ApiResponseFor200(api_client.ApiResponse):
2626
response: urllib3.HTTPResponse
2727
body: schemas.Unset = schemas.unset
2828
headers: schemas.Unset = schemas.unset
2929

3030

31-
class ResponseFor200(api_client.OpenApiResponse[_ApiResponse]):
32-
response_cls = _ApiResponse
31+
class ResponseFor200(api_client.OpenApiResponse[ApiResponseFor200]):
32+
response_cls = ApiResponseFor200

0 commit comments

Comments
 (0)