From cb8d9d5bfed851497d366343eba5f719986715ca Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 5 Sep 2022 09:37:01 -0700 Subject: [PATCH] [python-experimental] adds new json content type (#13356) * Adds json detection for application/json-patch+json * Adds jsonPatch route and schemas * Adds test_json_patch * Unit test sample updated * Reverts version files --- .../python-experimental/api_client.handlebars | 21 ++- ...odels-for-testing-with-http-signature.yaml | 74 ++++++++ .../unit_test_api/api_client.py | 21 ++- .../.openapi-generator/FILES | 12 ++ .../petstore/python-experimental/README.md | 5 + .../docs/apis/tags/FakeApi.md | 80 +++++++++ .../docs/models/JSONPatchRequest.md | 8 + .../models/JSONPatchRequestAddReplaceTest.md | 11 ++ .../docs/models/JSONPatchRequestMoveCopy.md | 11 ++ .../docs/models/JSONPatchRequestRemove.md | 10 ++ .../petstore_api/api_client.py | 21 ++- .../petstore_api/apis/path_to_api.py | 3 + .../apis/paths/fake_json_patch.py | 7 + .../petstore_api/apis/tags/fake_api.py | 2 + .../petstore_api/model/json_patch_request.py | 92 ++++++++++ .../petstore_api/model/json_patch_request.pyi | 92 ++++++++++ .../json_patch_request_add_replace_test.py | 122 +++++++++++++ .../json_patch_request_add_replace_test.pyi | 122 +++++++++++++ .../model/json_patch_request_move_copy.py | 105 ++++++++++++ .../model/json_patch_request_move_copy.pyi | 105 ++++++++++++ .../model/json_patch_request_remove.py | 98 +++++++++++ .../model/json_patch_request_remove.pyi | 98 +++++++++++ .../petstore_api/models/__init__.py | 4 + .../petstore_api/paths/__init__.py | 1 + .../paths/fake_json_patch/__init__.py | 7 + .../paths/fake_json_patch/patch.py | 160 ++++++++++++++++++ .../paths/fake_json_patch/patch.pyi | 135 +++++++++++++++ .../test_models/test_json_patch_request.py | 25 +++ ...est_json_patch_request_add_replace_test.py | 25 +++ .../test_json_patch_request_move_copy.py | 25 +++ .../test_json_patch_request_remove.py | 25 +++ .../test_fake_json_patch/__init__.py | 0 .../test_fake_json_patch/test_patch.py | 40 +++++ .../tests_manual/test_fake_api.py | 37 ++++ 34 files changed, 1580 insertions(+), 24 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequest.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestAddReplaceTest.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestMoveCopy.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestRemove.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/apis/paths/fake_json_patch.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.pyi create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.pyi create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.pyi create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.pyi create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/__init__.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.pyi create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_add_replace_test.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_move_copy.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_remove.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/__init__.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/test_patch.py diff --git a/modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars index bca1ff34f966..bb361662b8dc 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars @@ -797,12 +797,17 @@ class ApiResponseWithoutDeserialization(ApiResponse): class JSONDetector: @staticmethod - def content_type_is_json(content_type: str) -> bool: - """ - for when content_type strings also include charset info like: - application/json; charset=UTF-8 - """ - content_type_piece = content_type.split(';')[0] + def _content_type_is_json(content_type: str) -> bool: + content_type_piece = content_type + if ';' in content_type: + # application/json; charset=UTF-8 + content_type_piece = content_type.split(';')[0] + elif '-' in content_type: + """ + application/json-patch+json + application/json-seq + """ + content_type_piece = content_type.split('-')[0] if content_type_piece == 'application/json': return True return False @@ -905,7 +910,7 @@ class OpenApiResponse(JSONDetector): body=unset ) - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): body_data = self.__deserialize_json(response) elif content_type == 'application/octet-stream': body_data = self.__deserialize_application_octet_stream(response) @@ -1463,7 +1468,7 @@ class RequestBody(StyleFormSerializer, JSONDetector): cast_in_data = media_type.schema(in_data) # TODO check for and use encoding if it exists # and content_type is multipart or application/x-www-form-urlencoded - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): return self.__serialize_json(cast_in_data) elif content_type == 'text/plain': return self.__serialize_text_plain(cast_in_data) diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 82b3f9f0dfbd..d9d9b0a83ecd 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1558,6 +1558,21 @@ paths: content: application/json: {} application/xml: {} + /fake/jsonPatch: + patch: + summary: json patch + description: json patch route with a requestBody + operationId: jsonPatch + tags: + - fake + requestBody: + content: + application/json-patch+json: + schema: + $ref: '#/components/schemas/JSONPatchRequest' + responses: + '200': + description: OK /fake/deleteCoffee/{id}: delete: operationId: deleteCoffee @@ -2832,3 +2847,62 @@ components: AnyTypeNotString: not: type: string + JSONPatchRequest: + type: array + items: + oneOf: + - $ref: '#/components/schemas/JSONPatchRequestAddReplaceTest' + - $ref: '#/components/schemas/JSONPatchRequestRemove' + - $ref: '#/components/schemas/JSONPatchRequestMoveCopy' + JSONPatchRequestAddReplaceTest: + type: object + additionalProperties: false + required: + - value + - op + - path + properties: + path: + description: A JSON Pointer path. + type: string + value: + description: The value to add, replace or test. + op: + description: The operation to perform. + type: string + enum: + - add + - replace + - test + JSONPatchRequestRemove: + type: object + additionalProperties: false + required: + - op + - path + properties: + path: + description: A JSON Pointer path. + type: string + op: + description: The operation to perform. + type: string + enum: + - remove + JSONPatchRequestMoveCopy: + type: object + additionalProperties: false + required: + - from + - op + - path + properties: + path: + description: A JSON Pointer path. + type: string + op: + description: The operation to perform. + type: string + enum: + - move + - copy \ No newline at end of file diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/api_client.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/api_client.py index 4774af5063ad..c6bec775d7a0 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/api_client.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/api_client.py @@ -801,12 +801,17 @@ class ApiResponseWithoutDeserialization(ApiResponse): class JSONDetector: @staticmethod - def content_type_is_json(content_type: str) -> bool: - """ - for when content_type strings also include charset info like: - application/json; charset=UTF-8 - """ - content_type_piece = content_type.split(';')[0] + def _content_type_is_json(content_type: str) -> bool: + content_type_piece = content_type + if ';' in content_type: + # application/json; charset=UTF-8 + content_type_piece = content_type.split(';')[0] + elif '-' in content_type: + """ + application/json-patch+json + application/json-seq + """ + content_type_piece = content_type.split('-')[0] if content_type_piece == 'application/json': return True return False @@ -909,7 +914,7 @@ def deserialize(self, response: urllib3.HTTPResponse, configuration: Configurati body=unset ) - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): body_data = self.__deserialize_json(response) elif content_type == 'application/octet-stream': body_data = self.__deserialize_application_octet_stream(response) @@ -1453,7 +1458,7 @@ def serialize( cast_in_data = media_type.schema(in_data) # TODO check for and use encoding if it exists # and content_type is multipart or application/x-www-form-urlencoded - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): return self.__serialize_json(cast_in_data) elif content_type == 'text/plain': return self.__serialize_text_plain(cast_in_data) diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 6a8feb27ea90..2ccf2ed52ea1 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -74,6 +74,10 @@ docs/models/IntegerEnumWithDefaultValue.md docs/models/IntegerMax10.md docs/models/IntegerMin15.md docs/models/IsoscelesTriangle.md +docs/models/JSONPatchRequest.md +docs/models/JSONPatchRequestAddReplaceTest.md +docs/models/JSONPatchRequestMoveCopy.md +docs/models/JSONPatchRequestRemove.md docs/models/Mammal.md docs/models/MapTest.md docs/models/MixedPropertiesAndAdditionalPropertiesClass.md @@ -264,6 +268,14 @@ petstore_api/model/integer_min15.py petstore_api/model/integer_min15.pyi petstore_api/model/isosceles_triangle.py petstore_api/model/isosceles_triangle.pyi +petstore_api/model/json_patch_request.py +petstore_api/model/json_patch_request.pyi +petstore_api/model/json_patch_request_add_replace_test.py +petstore_api/model/json_patch_request_add_replace_test.pyi +petstore_api/model/json_patch_request_move_copy.py +petstore_api/model/json_patch_request_move_copy.pyi +petstore_api/model/json_patch_request_remove.py +petstore_api/model/json_patch_request_remove.pyi petstore_api/model/mammal.py petstore_api/model/mammal.pyi petstore_api/model/map_test.py diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index 211b5548f454..d8d33f0b471c 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -182,6 +182,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**inline_additional_properties**](docs/apis/tags/FakeApi.md#inline_additional_properties) | **post** /fake/inline-additionalProperties | test inline additionalProperties *FakeApi* | [**inline_composition**](docs/apis/tags/FakeApi.md#inline_composition) | **post** /fake/inlineComposition/ | testing composed schemas at inline locations *FakeApi* | [**json_form_data**](docs/apis/tags/FakeApi.md#json_form_data) | **get** /fake/jsonFormData | test json serialization of form data +*FakeApi* | [**json_patch**](docs/apis/tags/FakeApi.md#json_patch) | **patch** /fake/jsonPatch | json patch *FakeApi* | [**json_with_charset**](docs/apis/tags/FakeApi.md#json_with_charset) | **post** /fake/jsonWithCharset | json with charset tx and rx *FakeApi* | [**mammal**](docs/apis/tags/FakeApi.md#mammal) | **post** /fake/refs/mammal | *FakeApi* | [**number_with_validations**](docs/apis/tags/FakeApi.md#number_with_validations) | **post** /fake/refs/number | @@ -286,6 +287,10 @@ Class | Method | HTTP request | Description - [IntegerMax10](docs/models/IntegerMax10.md) - [IntegerMin15](docs/models/IntegerMin15.md) - [IsoscelesTriangle](docs/models/IsoscelesTriangle.md) + - [JSONPatchRequest](docs/models/JSONPatchRequest.md) + - [JSONPatchRequestAddReplaceTest](docs/models/JSONPatchRequestAddReplaceTest.md) + - [JSONPatchRequestMoveCopy](docs/models/JSONPatchRequestMoveCopy.md) + - [JSONPatchRequestRemove](docs/models/JSONPatchRequestRemove.md) - [Mammal](docs/models/Mammal.md) - [MapTest](docs/models/MapTest.md) - [MixedPropertiesAndAdditionalPropertiesClass](docs/models/MixedPropertiesAndAdditionalPropertiesClass.md) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/apis/tags/FakeApi.md b/samples/openapi3/client/petstore/python-experimental/docs/apis/tags/FakeApi.md index 7942df8c8fdb..b98dd6845a7d 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/apis/tags/FakeApi.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/apis/tags/FakeApi.md @@ -22,6 +22,7 @@ Method | HTTP request | Description [**inline_additional_properties**](#inline_additional_properties) | **post** /fake/inline-additionalProperties | test inline additionalProperties [**inline_composition**](#inline_composition) | **post** /fake/inlineComposition/ | testing composed schemas at inline locations [**json_form_data**](#json_form_data) | **get** /fake/jsonFormData | test json serialization of form data +[**json_patch**](#json_patch) | **patch** /fake/jsonPatch | json patch [**json_with_charset**](#json_with_charset) | **post** /fake/jsonWithCharset | json with charset tx and rx [**mammal**](#mammal) | **post** /fake/refs/mammal | [**number_with_validations**](#number_with_validations) | **post** /fake/refs/number | @@ -1719,6 +1720,85 @@ body | Unset | body was not defined | headers | Unset | headers were not defined | +void (empty response body) + +### Authorization + +No authorization required + +[[Back to top]](#__pageTop) [[Back to API list]](../../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../../README.md#documentation-for-models) [[Back to README]](../../../README.md) + +# **json_patch** + +> json_patch() + +json patch + +json patch route with a requestBody + +### Example + +```python +import petstore_api +from petstore_api.apis.tags import fake_api +from petstore_api.model.json_patch_request import JSONPatchRequest +from pprint import pprint +# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 +# See configuration.py for a list of all supported configuration parameters. +configuration = petstore_api.Configuration( + host = "http://petstore.swagger.io:80/v2" +) + +# Enter a context with an instance of the API client +with petstore_api.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = fake_api.FakeApi(api_client) + + # example passing only optional values + body = JSONPatchRequest([ + None + ]) + try: + # json patch + api_response = api_instance.json_patch( + body=body, + ) + except petstore_api.ApiException as e: + print("Exception when calling FakeApi->json_patch: %s\n" % e) +``` +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +body | typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, Unset] | optional, default is unset | +content_type | str | optional, default is 'application/json-patch+json' | Selects the schema and serialization of the request body +stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file +timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client +skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned + +### body + +#### SchemaForRequestBodyApplicationJsonPatchjson +Type | Description | Notes +------------- | ------------- | ------------- +[**JSONPatchRequest**](JSONPatchRequest.md) | | + + +### Return Types, Responses + +Code | Class | Description +------------- | ------------- | ------------- +n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned +200 | ApiResponseFor200 | OK + +#### ApiResponseFor200 +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +response | urllib3.HTTPResponse | Raw response | +body | Unset | body was not defined | +headers | Unset | headers were not defined | + + void (empty response body) ### Authorization diff --git a/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequest.md b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequest.md new file mode 100644 index 000000000000..eaf835a0e8a7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequest.md @@ -0,0 +1,8 @@ +# petstore_api.model.json_patch_request.JSONPatchRequest + +Type | Description | Notes +------------- | ------------- | ------------- +**[bool, date, datetime, dict, float, int, list, str, none_type]** | | + +[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestAddReplaceTest.md b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestAddReplaceTest.md new file mode 100644 index 000000000000..ca4e31cc06d1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestAddReplaceTest.md @@ -0,0 +1,11 @@ +# petstore_api.model.json_patch_request_add_replace_test.JSONPatchRequestAddReplaceTest + +#### Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**op** | **str** | The operation to perform. | +**path** | **str** | A JSON Pointer path. | +**value** | **bool, date, datetime, dict, float, int, list, str, none_type** | The value to add, replace or test. | + +[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestMoveCopy.md b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestMoveCopy.md new file mode 100644 index 000000000000..78349508e092 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestMoveCopy.md @@ -0,0 +1,11 @@ +# petstore_api.model.json_patch_request_move_copy.JSONPatchRequestMoveCopy + +#### Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**op** | **str** | The operation to perform. | +**path** | **str** | A JSON Pointer path. | +**from** | + +[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestRemove.md b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestRemove.md new file mode 100644 index 000000000000..a0c67f67d312 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/models/JSONPatchRequestRemove.md @@ -0,0 +1,10 @@ +# petstore_api.model.json_patch_request_remove.JSONPatchRequestRemove + +#### Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**op** | **str** | The operation to perform. | +**path** | **str** | A JSON Pointer path. | + +[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api_client.py index 601fa61e8a9e..5f9314c93270 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api_client.py @@ -801,12 +801,17 @@ class ApiResponseWithoutDeserialization(ApiResponse): class JSONDetector: @staticmethod - def content_type_is_json(content_type: str) -> bool: - """ - for when content_type strings also include charset info like: - application/json; charset=UTF-8 - """ - content_type_piece = content_type.split(';')[0] + def _content_type_is_json(content_type: str) -> bool: + content_type_piece = content_type + if ';' in content_type: + # application/json; charset=UTF-8 + content_type_piece = content_type.split(';')[0] + elif '-' in content_type: + """ + application/json-patch+json + application/json-seq + """ + content_type_piece = content_type.split('-')[0] if content_type_piece == 'application/json': return True return False @@ -909,7 +914,7 @@ def deserialize(self, response: urllib3.HTTPResponse, configuration: Configurati body=unset ) - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): body_data = self.__deserialize_json(response) elif content_type == 'application/octet-stream': body_data = self.__deserialize_application_octet_stream(response) @@ -1462,7 +1467,7 @@ def serialize( cast_in_data = media_type.schema(in_data) # TODO check for and use encoding if it exists # and content_type is multipart or application/x-www-form-urlencoded - if self.content_type_is_json(content_type): + if self._content_type_is_json(content_type): return self.__serialize_json(cast_in_data) elif content_type == 'text/plain': return self.__serialize_text_plain(cast_in_data) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/path_to_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/path_to_api.py index 1bc2ef06f9f5..b6a7d1053ecf 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/path_to_api.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/path_to_api.py @@ -46,6 +46,7 @@ from petstore_api.apis.paths.fake_ref_obj_in_query import FakeRefObjInQuery from petstore_api.apis.paths.fake_json_with_charset import FakeJsonWithCharset from petstore_api.apis.paths.fake_response_without_schema import FakeResponseWithoutSchema +from petstore_api.apis.paths.fake_json_patch import FakeJsonPatch from petstore_api.apis.paths.fake_delete_coffee_id import FakeDeleteCoffeeId PathToApi = typing.TypedDict( @@ -96,6 +97,7 @@ PathValues.FAKE_REF_OBJ_IN_QUERY: FakeRefObjInQuery, PathValues.FAKE_JSON_WITH_CHARSET: FakeJsonWithCharset, PathValues.FAKE_RESPONSE_WITHOUT_SCHEMA: FakeResponseWithoutSchema, + PathValues.FAKE_JSON_PATCH: FakeJsonPatch, PathValues.FAKE_DELETE_COFFEE_ID: FakeDeleteCoffeeId, } ) @@ -147,6 +149,7 @@ PathValues.FAKE_REF_OBJ_IN_QUERY: FakeRefObjInQuery, PathValues.FAKE_JSON_WITH_CHARSET: FakeJsonWithCharset, PathValues.FAKE_RESPONSE_WITHOUT_SCHEMA: FakeResponseWithoutSchema, + PathValues.FAKE_JSON_PATCH: FakeJsonPatch, PathValues.FAKE_DELETE_COFFEE_ID: FakeDeleteCoffeeId, } ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/paths/fake_json_patch.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/paths/fake_json_patch.py new file mode 100644 index 000000000000..53e563dbdb9a --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/paths/fake_json_patch.py @@ -0,0 +1,7 @@ +from petstore_api.paths.fake_json_patch.patch import ApiForpatch + + +class FakeJsonPatch( + ApiForpatch, +): + pass diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/tags/fake_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/tags/fake_api.py index e2940c06d562..d4ba07c2e389 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/tags/fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/tags/fake_api.py @@ -26,6 +26,7 @@ from petstore_api.paths.fake_inline_additional_properties.post import InlineAdditionalProperties from petstore_api.paths.fake_inline_composition_.post import InlineComposition from petstore_api.paths.fake_json_form_data.get import JsonFormData +from petstore_api.paths.fake_json_patch.patch import JsonPatch from petstore_api.paths.fake_json_with_charset.post import JsonWithCharset from petstore_api.paths.fake_refs_mammal.post import Mammal from petstore_api.paths.fake_refs_number.post import NumberWithValidations @@ -60,6 +61,7 @@ class FakeApi( InlineAdditionalProperties, InlineComposition, JsonFormData, + JsonPatch, JsonWithCharset, Mammal, NumberWithValidations, diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.py new file mode 100644 index 000000000000..88296e90e840 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.py @@ -0,0 +1,92 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequest( + schemas.ListSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + + class items( + schemas.ComposedSchema, + ): + + + class MetaOapg: + + @classmethod + @property + @functools.cache + def one_of(cls): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error because the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + return [ + JSONPatchRequestAddReplaceTest, + JSONPatchRequestRemove, + JSONPatchRequestMoveCopy, + ] + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ], + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'items': + return super().__new__( + cls, + *args, + _configuration=_configuration, + **kwargs, + ) + + def __new__( + cls, + arg: typing.Union[typing.Tuple[typing.Union[MetaOapg.items, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ]], typing.List[typing.Union[MetaOapg.items, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ]]], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequest': + return super().__new__( + cls, + arg, + _configuration=_configuration, + ) + + def __getitem__(self, i: int) -> MetaOapg.items: + return super().__getitem__(i) + +from petstore_api.model.json_patch_request_add_replace_test import JSONPatchRequestAddReplaceTest +from petstore_api.model.json_patch_request_move_copy import JSONPatchRequestMoveCopy +from petstore_api.model.json_patch_request_remove import JSONPatchRequestRemove diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.pyi b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.pyi new file mode 100644 index 000000000000..88296e90e840 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request.pyi @@ -0,0 +1,92 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequest( + schemas.ListSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + + class items( + schemas.ComposedSchema, + ): + + + class MetaOapg: + + @classmethod + @property + @functools.cache + def one_of(cls): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error because the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + return [ + JSONPatchRequestAddReplaceTest, + JSONPatchRequestRemove, + JSONPatchRequestMoveCopy, + ] + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ], + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'items': + return super().__new__( + cls, + *args, + _configuration=_configuration, + **kwargs, + ) + + def __new__( + cls, + arg: typing.Union[typing.Tuple[typing.Union[MetaOapg.items, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ]], typing.List[typing.Union[MetaOapg.items, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ]]], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequest': + return super().__new__( + cls, + arg, + _configuration=_configuration, + ) + + def __getitem__(self, i: int) -> MetaOapg.items: + return super().__getitem__(i) + +from petstore_api.model.json_patch_request_add_replace_test import JSONPatchRequestAddReplaceTest +from petstore_api.model.json_patch_request_move_copy import JSONPatchRequestMoveCopy +from petstore_api.model.json_patch_request_remove import JSONPatchRequestRemove diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.py new file mode 100644 index 000000000000..a3672ec88660 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.py @@ -0,0 +1,122 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestAddReplaceTest( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + "value", + } + class properties: + path = schemas.StrSchema + value = schemas.AnyTypeSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "add": "ADD", + "replace": "REPLACE", + "test": "TEST", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def ADD(cls): + return cls("add") + + @classmethod + @property + def REPLACE(cls): + return cls("replace") + + @classmethod + @property + def TEST(cls): + return cls("test") + __annotations__ = { + "path": path, + "value": value, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + value: MetaOapg.properties.value + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["value"]) -> MetaOapg.properties.value: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], typing.Literal["value"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["value"]) -> MetaOapg.properties.value: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], typing.Literal["value"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + value: typing.Union[MetaOapg.properties.value, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestAddReplaceTest': + return super().__new__( + cls, + *args, + op=op, + path=path, + value=value, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.pyi b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.pyi new file mode 100644 index 000000000000..a3672ec88660 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_add_replace_test.pyi @@ -0,0 +1,122 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestAddReplaceTest( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + "value", + } + class properties: + path = schemas.StrSchema + value = schemas.AnyTypeSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "add": "ADD", + "replace": "REPLACE", + "test": "TEST", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def ADD(cls): + return cls("add") + + @classmethod + @property + def REPLACE(cls): + return cls("replace") + + @classmethod + @property + def TEST(cls): + return cls("test") + __annotations__ = { + "path": path, + "value": value, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + value: MetaOapg.properties.value + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["value"]) -> MetaOapg.properties.value: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], typing.Literal["value"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["value"]) -> MetaOapg.properties.value: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], typing.Literal["value"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + value: typing.Union[MetaOapg.properties.value, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestAddReplaceTest': + return super().__new__( + cls, + *args, + op=op, + path=path, + value=value, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.py new file mode 100644 index 000000000000..cd3a4bd14062 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.py @@ -0,0 +1,105 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestMoveCopy( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + "from", + } + class properties: + path = schemas.StrSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "move": "MOVE", + "copy": "COPY", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def MOVE(cls): + return cls("move") + + @classmethod + @property + def COPY(cls): + return cls("copy") + __annotations__ = { + "path": path, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestMoveCopy': + return super().__new__( + cls, + *args, + op=op, + path=path, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.pyi b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.pyi new file mode 100644 index 000000000000..cd3a4bd14062 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_move_copy.pyi @@ -0,0 +1,105 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestMoveCopy( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + "from", + } + class properties: + path = schemas.StrSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "move": "MOVE", + "copy": "COPY", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def MOVE(cls): + return cls("move") + + @classmethod + @property + def COPY(cls): + return cls("copy") + __annotations__ = { + "path": path, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestMoveCopy': + return super().__new__( + cls, + *args, + op=op, + path=path, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.py new file mode 100644 index 000000000000..066b1284db5e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.py @@ -0,0 +1,98 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestRemove( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + } + class properties: + path = schemas.StrSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "remove": "REMOVE", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def REMOVE(cls): + return cls("remove") + __annotations__ = { + "path": path, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestRemove': + return super().__new__( + cls, + *args, + op=op, + path=path, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.pyi b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.pyi new file mode 100644 index 000000000000..066b1284db5e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/json_patch_request_remove.pyi @@ -0,0 +1,98 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class JSONPatchRequestRemove( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + required = { + "op", + "path", + } + class properties: + path = schemas.StrSchema + + + class op( + schemas.SchemaEnumMakerClsFactory( + enum_value_to_name={ + "remove": "REMOVE", + } + ), + schemas.StrSchema + ): + + @classmethod + @property + def REMOVE(cls): + return cls("remove") + __annotations__ = { + "path": path, + "op": op, + } + additional_properties = schemas.NotAnyTypeSchema + + op: MetaOapg.properties.op + path: MetaOapg.properties.path + + @typing.overload + def __getitem__(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def __getitem__(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def __getitem__(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + # dict_instance[name] accessor + return super().__getitem__(name) + + @typing.overload + def get_item_oapg(self, name: typing.Literal["op"]) -> MetaOapg.properties.op: ... + + @typing.overload + def get_item_oapg(self, name: typing.Literal["path"]) -> MetaOapg.properties.path: ... + + def get_item_oapg(self, name: typing.Union[typing.Literal["op"], typing.Literal["path"], ]): + return super().get_item_oapg(name) + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + op: typing.Union[MetaOapg.properties.op, str, ], + path: typing.Union[MetaOapg.properties.path, str, ], + _configuration: typing.Optional[schemas.Configuration] = None, + ) -> 'JSONPatchRequestRemove': + return super().__new__( + cls, + *args, + op=op, + path=path, + _configuration=_configuration, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py index 48f6957f02cb..cabc33001240 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py @@ -76,6 +76,10 @@ from petstore_api.model.integer_max10 import IntegerMax10 from petstore_api.model.integer_min15 import IntegerMin15 from petstore_api.model.isosceles_triangle import IsoscelesTriangle +from petstore_api.model.json_patch_request import JSONPatchRequest +from petstore_api.model.json_patch_request_add_replace_test import JSONPatchRequestAddReplaceTest +from petstore_api.model.json_patch_request_move_copy import JSONPatchRequestMoveCopy +from petstore_api.model.json_patch_request_remove import JSONPatchRequestRemove from petstore_api.model.mammal import Mammal from petstore_api.model.map_test import MapTest from petstore_api.model.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/__init__.py index 44ffa277821f..ef62b10d23cc 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/__init__.py @@ -51,4 +51,5 @@ class PathValues(str, enum.Enum): FAKE_REF_OBJ_IN_QUERY = "/fake/refObjInQuery" FAKE_JSON_WITH_CHARSET = "/fake/jsonWithCharset" FAKE_RESPONSE_WITHOUT_SCHEMA = "/fake/responseWithoutSchema" + FAKE_JSON_PATCH = "/fake/jsonPatch" FAKE_DELETE_COFFEE_ID = "/fake/deleteCoffee/{id}" diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/__init__.py new file mode 100644 index 000000000000..b302e74cceb3 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/__init__.py @@ -0,0 +1,7 @@ +# do not import all endpoints into this module because that uses a lot of memory and stack frames +# if you need the ability to import all endpoints from this module, import them with +# from petstore_api.paths.fake_json_patch import Api + +from petstore_api.paths import PathValues + +path = PathValues.FAKE_JSON_PATCH \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.py new file mode 100644 index 000000000000..e09d0a145dcc --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.py @@ -0,0 +1,160 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import urllib3 +from urllib3._collections import HTTPHeaderDict + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.model.json_patch_request import JSONPatchRequest + +from . import path + +# body param +SchemaForRequestBodyApplicationJsonPatchjson = JSONPatchRequest + + +request_body_json_patch_request = api_client.RequestBody( + content={ + 'application/json-patch+json': api_client.MediaType( + schema=SchemaForRequestBodyApplicationJsonPatchjson), + }, +) + + +@dataclass +class ApiResponseFor200(api_client.ApiResponse): + response: urllib3.HTTPResponse + body: schemas.Unset = schemas.unset + headers: schemas.Unset = schemas.unset + + +_response_for_200 = api_client.OpenApiResponse( + response_cls=ApiResponseFor200, +) +_status_code_to_response = { + '200': _response_for_200, +} + + +class BaseApi(api_client.Api): + + def _json_patch_oapg( + self: api_client.Api, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + """ + json patch + :param skip_deserialization: If true then api_response.response will be set but + api_response.body and api_response.headers will not be deserialized into schema + class instances + """ + used_path = path.value + + _headers = HTTPHeaderDict() + # TODO add cookie handling + + _fields = None + _body = None + if body is not schemas.unset: + serialized_data = request_body_json_patch_request.serialize(body, content_type) + _headers.add('Content-Type', content_type) + if 'fields' in serialized_data: + _fields = serialized_data['fields'] + elif 'body' in serialized_data: + _body = serialized_data['body'] + response = self.api_client.call_api( + resource_path=used_path, + method='patch'.upper(), + headers=_headers, + fields=_fields, + body=_body, + stream=stream, + timeout=timeout, + ) + + if skip_deserialization: + api_response = api_client.ApiResponseWithoutDeserialization(response=response) + else: + response_for_status = _status_code_to_response.get(str(response.status)) + if response_for_status: + api_response = response_for_status.deserialize(response, self.api_client.configuration) + else: + api_response = api_client.ApiResponseWithoutDeserialization(response=response) + + if not 200 <= response.status <= 299: + raise exceptions.ApiException(api_response=api_response) + + return api_response + + +class JsonPatch(BaseApi): + # this class is used by api classes that refer to endpoints with operationId fn names + + def json_patch( + self: BaseApi, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + return self._json_patch_oapg( + body=body, + content_type=content_type, + stream=stream, + timeout=timeout, + skip_deserialization=skip_deserialization + ) + + +class ApiForpatch(BaseApi): + # this class is used by api classes that refer to endpoints by path and http method names + + def patch( + self: BaseApi, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + return self._json_patch_oapg( + body=body, + content_type=content_type, + stream=stream, + timeout=timeout, + skip_deserialization=skip_deserialization + ) + + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.pyi b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.pyi new file mode 100644 index 000000000000..046608cd626c --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/paths/fake_json_patch/patch.pyi @@ -0,0 +1,135 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import urllib3 +from urllib3._collections import HTTPHeaderDict + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.model.json_patch_request import JSONPatchRequest + +# body param +SchemaForRequestBodyApplicationJsonPatchjson = JSONPatchRequest + + +class BaseApi(api_client.Api): + + def _json_patch_oapg( + self: api_client.Api, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + """ + json patch + :param skip_deserialization: If true then api_response.response will be set but + api_response.body and api_response.headers will not be deserialized into schema + class instances + """ + used_path = path.value + + _headers = HTTPHeaderDict() + # TODO add cookie handling + + _fields = None + _body = None + if body is not schemas.unset: + serialized_data = request_body_json_patch_request.serialize(body, content_type) + _headers.add('Content-Type', content_type) + if 'fields' in serialized_data: + _fields = serialized_data['fields'] + elif 'body' in serialized_data: + _body = serialized_data['body'] + response = self.api_client.call_api( + resource_path=used_path, + method='patch'.upper(), + headers=_headers, + fields=_fields, + body=_body, + stream=stream, + timeout=timeout, + ) + + if skip_deserialization: + api_response = api_client.ApiResponseWithoutDeserialization(response=response) + else: + response_for_status = _status_code_to_response.get(str(response.status)) + if response_for_status: + api_response = response_for_status.deserialize(response, self.api_client.configuration) + else: + api_response = api_client.ApiResponseWithoutDeserialization(response=response) + + if not 200 <= response.status <= 299: + raise exceptions.ApiException(api_response=api_response) + + return api_response + + +class JsonPatch(BaseApi): + # this class is used by api classes that refer to endpoints with operationId fn names + + def json_patch( + self: BaseApi, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + return self._json_patch_oapg( + body=body, + content_type=content_type, + stream=stream, + timeout=timeout, + skip_deserialization=skip_deserialization + ) + + +class ApiForpatch(BaseApi): + # this class is used by api classes that refer to endpoints by path and http method names + + def patch( + self: BaseApi, + body: typing.Union[SchemaForRequestBodyApplicationJsonPatchjson, schemas.Unset] = schemas.unset, + content_type: str = 'application/json-patch+json', + stream: bool = False, + timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None, + skip_deserialization: bool = False, + ) -> typing.Union[ + ApiResponseFor200, + api_client.ApiResponseWithoutDeserialization + ]: + return self._json_patch_oapg( + body=body, + content_type=content_type, + stream=stream, + timeout=timeout, + skip_deserialization=skip_deserialization + ) + + diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request.py b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request.py new file mode 100644 index 000000000000..87ab0b276156 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.json_patch_request import JSONPatchRequest +from petstore_api import configuration + + +class TestJSONPatchRequest(unittest.TestCase): + """JSONPatchRequest unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_add_replace_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_add_replace_test.py new file mode 100644 index 000000000000..bcabf025afe4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_add_replace_test.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.json_patch_request_add_replace_test import JSONPatchRequestAddReplaceTest +from petstore_api import configuration + + +class TestJSONPatchRequestAddReplaceTest(unittest.TestCase): + """JSONPatchRequestAddReplaceTest unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_move_copy.py b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_move_copy.py new file mode 100644 index 000000000000..388b38f27a50 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_move_copy.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.json_patch_request_move_copy import JSONPatchRequestMoveCopy +from petstore_api import configuration + + +class TestJSONPatchRequestMoveCopy(unittest.TestCase): + """JSONPatchRequestMoveCopy unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_remove.py b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_remove.py new file mode 100644 index 000000000000..fe2001a85cb1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_models/test_json_patch_request_remove.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.json_patch_request_remove import JSONPatchRequestRemove +from petstore_api import configuration + + +class TestJSONPatchRequestRemove(unittest.TestCase): + """JSONPatchRequestRemove unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/__init__.py b/samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/test_patch.py b/samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/test_patch.py new file mode 100644 index 000000000000..add02d961a05 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_paths/test_fake_json_patch/test_patch.py @@ -0,0 +1,40 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +import unittest +from unittest.mock import patch + +import urllib3 + +import petstore_api +from petstore_api.paths.fake_json_patch import patch # noqa: E501 +from petstore_api import configuration, schemas, api_client + +from .. import ApiTestMixin + + +class TestFakeJsonPatch(ApiTestMixin, unittest.TestCase): + """ + FakeJsonPatch unit test stubs + json patch # noqa: E501 + """ + _configuration = configuration.Configuration() + + def setUp(self): + used_api_client = api_client.ApiClient(configuration=self._configuration) + self.api = patch.ApiForpatch(api_client=used_api_client) # noqa: E501 + + def tearDown(self): + pass + + response_status = 200 + response_body = '' + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py index 6ef7d1f990bc..8042169dd872 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py @@ -727,6 +727,43 @@ def test_delete_endpoint_without_request_body(self): assert isinstance(api_response.body, schemas.Unset) assert isinstance(api_response.headers, schemas.Unset) + def test_json_patch(self): + with patch.object(urllib3.PoolManager, 'request') as mock_request: + from petstore_api.model import json_patch_request + from petstore_api.model import json_patch_request_add_replace_test + + mock_request.return_value = self.response("") + body = json_patch_request.JSONPatchRequest( + [ + json_patch_request_add_replace_test.JSONPatchRequestAddReplaceTest( + op='add', + path='/a/b/c', + value='foo', + ) + ] + ) + api_response = self.api.json_patch(body) + json_body = [ + { + 'op': 'add', + 'path': '/a/b/c', + 'value': 'foo' + } + ] + self.assert_pool_manager_request_called_with( + mock_request, + 'http://petstore.swagger.io:80/v2/fake/jsonPatch', + body=self.json_bytes(json_body), + method='PATCH', + content_type='application/json-patch+json', + accept_content_type=None, + ) + + assert isinstance(api_response.response, urllib3.HTTPResponse) + assert isinstance(api_response.body, schemas.Unset) + assert isinstance(api_response.headers, schemas.Unset) + assert api_response.response.status == 200 + if __name__ == '__main__': unittest.main()