Skip to content

Commit

Permalink
[python-experimental] adds new json content type (#13356)
Browse files Browse the repository at this point in the history
* Adds json detection for application/json-patch+json

* Adds jsonPatch route and schemas

* Adds test_json_patch

* Unit test sample updated

* Reverts version files
  • Loading branch information
spacether committed Sep 5, 2022
1 parent 2a8ea16 commit cb8d9d5
Show file tree
Hide file tree
Showing 34 changed files with 1,580 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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**
<a name="json_patch"></a>
> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit cb8d9d5

Please sign in to comment.