Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ced5763
Add source folder variable to fastapi fix 12118
rk0n Apr 12, 2022
ce2dbdc
Add generated sample files for python-fastapi fix 12118
rk0n Apr 12, 2022
83af2ca
[python-experimental] fixes json + charset use case (#12114)
spacether Apr 12, 2022
216ee06
Add example allOf with single ref (#10948)
kuhnroyal Apr 12, 2022
8ae7b89
Add a sample of an enum model array in query params (#12107)
kuhnroyal Apr 12, 2022
82f35b3
[typescript-fetch] drop support typescript under v4.0 (#12102)
mkusaka Apr 12, 2022
f31aab2
update samples
wing328 Apr 12, 2022
8b0e3f0
[dart] Remove old dio generator (to be replaced with dart-dio-next) (…
kuhnroyal Apr 12, 2022
5adc7ee
fix: respect configured generator URL in swagger config (#12064)
fgreinacher Apr 12, 2022
4dacc0e
[typescript*] drop support typescript below 4.0 (#12123)
mkusaka Apr 12, 2022
6d089d1
Upgrade haskell-servant to latest LTS (#12092)
7omb Apr 12, 2022
82d41d5
[C++][Qt] update petstore to 3.0 spec (#12124)
wing328 Apr 13, 2022
69440ec
update readme with onesignal (#12126)
wing328 Apr 13, 2022
d071fc5
[typescript-fetch] Removed functions that are unused when withoutRunt…
mkusaka Apr 13, 2022
d833794
[kotlin][client] fix encoding of individual parts of a multipart requ…
koscejev Apr 13, 2022
e70f243
[python-experimental] Allow response media types to omit schema (#12135)
spacether Apr 13, 2022
aaf9f83
improve errorObjectType to avoid regression (#12131)
wing328 Apr 14, 2022
fecdf0d
[php-slim4] Add monolog package as default logger (#12137)
ybelenko Apr 16, 2022
244f109
Bump async from 2.6.3 to 2.6.4 in /website (#12148)
dependabot[bot] Apr 16, 2022
6e7f2a8
do not put the invalid value of the enum to a JSON structure (#12133)
ityuhui Apr 16, 2022
e243117
[Java] Ignore return value for Java file assert classes (#12145)
borsch Apr 16, 2022
a5132bd
Add @mkusaka to TS technical committee (#12150)
wing328 Apr 16, 2022
77fc9ff
Fix documentation for users of AbstractJavaJAXRSServerCodegen (#12142)
typetetris Apr 16, 2022
c95ee48
[Dart][client] Adjust toJson method to use '_json' instead of 'json' …
0xNF Apr 16, 2022
ac8906a
[dart] Support/Fix sourceFolder parameter and docs (#12113)
kuhnroyal Apr 16, 2022
ce326da
[Ruby] Add support for faraday 2.x (#12112)
ykitamura-mdsol Apr 16, 2022
aaa1c26
[Java/Spring] all-of and one-of Improvements and Fixes (was #12075) (…
cachescrubber Apr 16, 2022
ef17120
[REQ][Ruby] Ruby Allow Follow Redirect (#12047)
moorec22 Apr 16, 2022
feefaf7
set follow_location default to true
wing328 Apr 16, 2022
64ccf06
Adds UUID to python-experimental (#12153)
spacether Apr 16, 2022
899c8e1
update url to travis ci
wing328 Apr 17, 2022
59dc481
Adds not to CodegenComposedSchemas and uses it in python-exp (#12146)
spacether Apr 17, 2022
1f48d76
[python-experimental] fixes bug where some singleton representations …
spacether Apr 17, 2022
cfd51ef
[swift5] Abstract away URLSession (#11651) (#12110)
leszek-s Apr 19, 2022
2e2e557
[Java][OkHTTP] fix empty request body handling (#12172)
borsch Apr 19, 2022
4b2685c
Better inline model resolver to handle inline schema in array item (#…
wing328 Apr 20, 2022
28128e6
[Inline model resolver] minor enhancements/refactoring (#12175)
wing328 Apr 20, 2022
33085f1
[python-experimental] Fixes enum is comparison (#12176)
spacether Apr 20, 2022
dd9f7b5
[php] make ObjectSerializer::toString actually return a string (#12158)
fengelniederhammer Apr 20, 2022
859bfa0
update php samples
wing328 Apr 20, 2022
0cb59fc
Allow selection of MP REST API version for MicroProfile REST client g…
aserkes Apr 20, 2022
7bacfc0
[Java][microprofile] update API test template to work with v3.0 (#12177)
wing328 Apr 20, 2022
52b8368
Return type for Azure funcs (#12115)
Abrhm7786 Apr 20, 2022
0a4b3c9
update doc
wing328 Apr 20, 2022
eb36fc7
Improvements to csharp-netcore-function generator (#12183)
wing328 Apr 20, 2022
178ca12
[java-micronaut] Support Optional for non-required properties (#12144)
auke- Apr 21, 2022
537b1a6
update java samples
wing328 Apr 21, 2022
f41e756
[typescript-fetch] allow initOverrides with async function (#12098)
mkusaka Apr 23, 2022
cce98b8
[Wsdl] Adding cli-option for generating different versions of WSDL-fi…
adessoDpd Apr 24, 2022
dcf8431
[python-flask] Fix return type too strict (#12190)
OJFord Apr 24, 2022
04ece4d
update samples, docs
wing328 Apr 24, 2022
67dc856
Fixing bug in Kotlin Client with BigDecimal default value (#12213)
sjoblomj Apr 24, 2022
ec2778f
Fix duplication of "Api" when structPrefix is set (#12128)
impl Apr 24, 2022
980975a
add samples/client/petstore/kotlin-bigdecimal-default to kotlin ci tests
wing328 Apr 24, 2022
54b6eb5
remove spring-mvc samples (#12222)
wing328 Apr 24, 2022
bfc9f2e
[Micronaut] Add option to describe response wrappers (#12186)
andriy-dmytruk Apr 24, 2022
10d0dbf
Emit default values for aspnetcore 3 value types (#11280)
hauntingEcho Apr 24, 2022
a1e51b3
update samples
wing328 Apr 24, 2022
38b0d9d
Merge branch 'master' into add-source-folder-variable-to-fastapi-fix-…
rk0n Apr 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[python-experimental] fixes json + charset use case (#12114)
* Adds code to detect json content type when charset is also set

* Updates template to properly render content type, regenerates samples

* Adds test_json_with_charset

* Reverts version file

* Fixes typo
  • Loading branch information
spacether authored and rk0n committed Apr 24, 2022
commit 83af2ca5b8e6b75b35ed0d546556ce4dd68a6cd1
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,20 @@ class ApiResponseWithoutDeserialization(ApiResponse):
headers: typing.Union[Unset, typing.List[HeaderParameter]] = unset


class OpenApiResponse:
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]
if content_type_piece == 'application/json':
return True
return False


class OpenApiResponse(JSONDetector):
def __init__(
self,
response_cls: typing.Type[ApiResponse] = ApiResponse,
Expand All @@ -734,8 +747,8 @@ class OpenApiResponse:

@staticmethod
def __deserialize_json(response: urllib3.HTTPResponse) -> typing.Any:
decoded_data = response.data.decode("utf-8")
return json.loads(decoded_data)
# python must be >= 3.9 so we can pass in bytes into json.loads
return json.loads(response.data)

@staticmethod
def __file_name_from_content_disposition(content_disposition: typing.Optional[str]) -> typing.Optional[str]:
Expand Down Expand Up @@ -796,7 +809,7 @@ class OpenApiResponse:
deserialized_body = unset
streamed = response.supports_chunked_reads()
if self.content is not None:
if content_type == 'application/json':
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 @@ -1245,7 +1258,7 @@ class SerializedRequestBody(typing.TypedDict, total=False):
fields: typing.Tuple[typing.Union[RequestField, tuple[str, str]], ...]


class RequestBody(StyleFormSerializer):
class RequestBody(StyleFormSerializer, JSONDetector):
"""
A request body parameter
content: content_type to MediaType Schema info
Expand Down Expand Up @@ -1382,7 +1395,7 @@ class RequestBody(StyleFormSerializer):
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 content_type == 'application/json':
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 @@ -182,7 +182,7 @@ class RequestCookieParams(RequestRequiredCookieParams, RequestOptionalCookiePara
request_body_{{paramName}} = api_client.RequestBody(
content={
{{#each content}}
'{{@key}}': api_client.MediaType(
'{{{@key}}}': api_client.MediaType(
schema={{this.schema.baseName}}),
{{/each}}
},
Expand Down Expand Up @@ -323,7 +323,7 @@ _response_for_{{code}} = api_client.OpenApiResponse(
{{#if @first}}
content={
{{/if}}
'{{@key}}': api_client.MediaType(
'{{{@key}}}': api_client.MediaType(
schema={{this.schema.baseName}}),
{{#if @last}}
},
Expand Down Expand Up @@ -351,7 +351,7 @@ _status_code_to_response = {
{{#if @first}}
_all_accept_content_types = (
{{/if}}
'{{this.mediaType}}',
'{{{this.mediaType}}}',
{{#if @last}}
)
{{/if}}
Expand Down Expand Up @@ -382,7 +382,7 @@ class {{operationIdCamelCase}}(api_client.Api):
{{#with bodyParam}}
{{#each content}}
{{#if @first}}
content_type: str = '{{@key}}',
content_type: str = '{{{@key}}}',
{{/if}}
{{/each}}
{{/with}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,22 @@ paths:
responses:
'200':
description: ok
'/fake/jsonWithCharset':
post:
tags:
- fake
summary: json with charset tx and rx
operationId: jsonWithCharset
requestBody:
content:
application/json; charset=utf-8:
schema: {}
responses:
200:
description: success
content:
application/json; charset=utf-8:
schema: {}
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**inline_additional_properties**](docs/FakeApi.md#inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**inline_composition**](docs/FakeApi.md#inline_composition) | **POST** /fake/inlineComposition/ | testing composed schemas at inline locations
*FakeApi* | [**json_form_data**](docs/FakeApi.md#json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
*FakeApi* | [**json_with_charset**](docs/FakeApi.md#json_with_charset) | **POST** /fake/jsonWithCharset | json with charset tx and rx
*FakeApi* | [**mammal**](docs/FakeApi.md#mammal) | **POST** /fake/refs/mammal |
*FakeApi* | [**number_with_validations**](docs/FakeApi.md#number_with_validations) | **POST** /fake/refs/number |
*FakeApi* | [**object_in_query**](docs/FakeApi.md#object_in_query) | **GET** /fake/objInQuery | user list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Method | HTTP request | Description
[**inline_additional_properties**](FakeApi.md#inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
[**inline_composition**](FakeApi.md#inline_composition) | **POST** /fake/inlineComposition/ | testing composed schemas at inline locations
[**json_form_data**](FakeApi.md#json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
[**json_with_charset**](FakeApi.md#json_with_charset) | **POST** /fake/jsonWithCharset | json with charset tx and rx
[**mammal**](FakeApi.md#mammal) | **POST** /fake/refs/mammal |
[**number_with_validations**](FakeApi.md#number_with_validations) | **POST** /fake/refs/number |
[**object_in_query**](FakeApi.md#object_in_query) | **GET** /fake/objInQuery | user list
Expand Down Expand Up @@ -1618,6 +1619,87 @@ No authorization required

[[Back to top]](#) [[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_with_charset**
> bool, date, datetime, dict, float, int, list, str, none_type json_with_charset()

json with charset tx and rx

### Example

```python
import petstore_api
from petstore_api.api import fake_api
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 = None
try:
# json with charset tx and rx
api_response = api_instance.json_with_charset(
body=body,
)
pprint(api_response)
except petstore_api.ApiException as e:
print("Exception when calling FakeApi->json_with_charset: %s\n" % e)
```
### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
body | typing.Union[SchemaForRequestBodyApplicationJsonCharsetutf8, Unset] | optional, default is unset |
content_type | str | optional, default is 'application/json; charset=utf-8' | Selects the schema and serialization of the request body
accept_content_types | typing.Tuple[str] | default is ('application/json; charset=utf-8', ) | Tells the server the content type(s) that are accepted by the client
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

#### SchemaForRequestBodyApplicationJsonCharsetutf8

Type | Description | Notes
------------- | ------------- | -------------
typing.Union[dict, frozendict, str, date, datetime, int, float, bool, Decimal, None, list, tuple, bytes] | |

### Return Types, Responses

Code | Class | Description
------------- | ------------- | -------------
n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
200 | ApiResponseFor200 | success

#### ApiResponseFor200
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
response | urllib3.HTTPResponse | Raw response |
body | typing.Union[SchemaFor200ResponseBodyApplicationJsonCharsetutf8, ] | |
headers | Unset | headers were not defined |

#### SchemaFor200ResponseBodyApplicationJsonCharsetutf8

Type | Description | Notes
------------- | ------------- | -------------
typing.Union[dict, frozendict, str, date, datetime, int, float, bool, Decimal, None, list, tuple, bytes] | |


**bool, date, datetime, dict, float, int, list, str, none_type**

### Authorization

No authorization required

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **mammal**
> Mammal mammal(mammal)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from petstore_api.api.fake_api_endpoints.inline_additional_properties import InlineAdditionalProperties
from petstore_api.api.fake_api_endpoints.inline_composition import InlineComposition
from petstore_api.api.fake_api_endpoints.json_form_data import JsonFormData
from petstore_api.api.fake_api_endpoints.json_with_charset import JsonWithCharset
from petstore_api.api.fake_api_endpoints.mammal import Mammal
from petstore_api.api.fake_api_endpoints.number_with_validations import NumberWithValidations
from petstore_api.api.fake_api_endpoints.object_in_query import ObjectInQuery
Expand Down Expand Up @@ -57,6 +58,7 @@ class FakeApi(
InlineAdditionalProperties,
InlineComposition,
JsonFormData,
JsonWithCharset,
Mammal,
NumberWithValidations,
ObjectInQuery,
Expand Down
Loading