Skip to content

Commit 110b820

Browse files
authored
add tests for json headre (python) (#25112)
1 parent a5e4173 commit 110b820

84 files changed

Lines changed: 4737 additions & 0 deletions

File tree

Some content is hidden

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

‎modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,28 @@ paths:
15881588
type: integer
15891589
required:
15901590
- file
1591+
/test/json-header-content:
1592+
post:
1593+
tags:
1594+
- fake
1595+
operationId: test-json-header-content
1596+
parameters:
1597+
- name: X-Json-Arg
1598+
in: header
1599+
required: true
1600+
content:
1601+
application/json:
1602+
schema:
1603+
$ref: '#/components/schemas/HeaderArg'
1604+
- name: X-Plain-Arg
1605+
in: header
1606+
required: false
1607+
schema:
1608+
type: string
1609+
responses:
1610+
'204':
1611+
description: No content
1612+
15911613
/import_test/return_datetime:
15921614
get:
15931615
tags:
@@ -2946,3 +2968,10 @@ components:
29462968
type: string
29472969
format: uuid
29482970
pattern: "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
2971+
HeaderArg:
2972+
type: object
2973+
properties:
2974+
path:
2975+
type: string
2976+
recursive:
2977+
type: boolean
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* OpenAPI Petstore
3+
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package org.openapitools.client;
14+
15+
import java.io.IOException;
16+
import java.time.Instant;
17+
import java.time.OffsetDateTime;
18+
import java.time.ZoneId;
19+
import java.time.ZonedDateTime;
20+
import java.time.format.DateTimeFormatter;
21+
import java.time.temporal.Temporal;
22+
import java.time.temporal.TemporalAccessor;
23+
import java.util.function.BiFunction;
24+
import java.util.function.Function;
25+
26+
import com.fasterxml.jackson.core.JsonParser;
27+
import com.fasterxml.jackson.databind.DeserializationContext;
28+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature;
29+
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
30+
31+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
32+
public class RFC3339InstantDeserializer<T extends Temporal> extends InstantDeserializer<T> {
33+
private static final long serialVersionUID = 1L;
34+
private final static boolean DEFAULT_NORMALIZE_ZONE_ID = JavaTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault();
35+
private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
36+
= JavaTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault();
37+
38+
public static final RFC3339InstantDeserializer<Instant> INSTANT = new RFC3339InstantDeserializer<>(
39+
Instant.class, DateTimeFormatter.ISO_INSTANT,
40+
Instant::from,
41+
a -> Instant.ofEpochMilli( a.value ),
42+
a -> Instant.ofEpochSecond( a.integer, a.fraction ),
43+
null,
44+
true, // yes, replace zero offset with Z
45+
DEFAULT_NORMALIZE_ZONE_ID,
46+
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
47+
);
48+
49+
public static final RFC3339InstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new RFC3339InstantDeserializer<>(
50+
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
51+
OffsetDateTime::from,
52+
a -> OffsetDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ),
53+
a -> OffsetDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ),
54+
(d, z) -> ( d.isEqual( OffsetDateTime.MIN ) || d.isEqual( OffsetDateTime.MAX ) ?
55+
d :
56+
d.withOffsetSameInstant( z.getRules().getOffset( d.toLocalDateTime() ) ) ),
57+
true, // yes, replace zero offset with Z
58+
DEFAULT_NORMALIZE_ZONE_ID,
59+
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
60+
);
61+
62+
public static final RFC3339InstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new RFC3339InstantDeserializer<>(
63+
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
64+
ZonedDateTime::from,
65+
a -> ZonedDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ),
66+
a -> ZonedDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ),
67+
ZonedDateTime::withZoneSameInstant,
68+
false, // keep zero offset and Z separate since zones explicitly supported
69+
DEFAULT_NORMALIZE_ZONE_ID,
70+
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
71+
);
72+
73+
protected RFC3339InstantDeserializer(
74+
Class<T> supportedType,
75+
DateTimeFormatter formatter,
76+
Function<TemporalAccessor, T> parsedToValue,
77+
Function<FromIntegerArguments, T> fromMilliseconds,
78+
Function<FromDecimalArguments, T> fromNanoseconds,
79+
BiFunction<T, ZoneId, T> adjust,
80+
boolean replaceZeroOffsetAsZ,
81+
boolean normalizeZoneId,
82+
boolean readNumericStringsAsTimestamp) {
83+
super(
84+
supportedType,
85+
formatter,
86+
parsedToValue,
87+
fromMilliseconds,
88+
fromNanoseconds,
89+
adjust,
90+
replaceZeroOffsetAsZ,
91+
normalizeZoneId,
92+
readNumericStringsAsTimestamp
93+
);
94+
}
95+
96+
@Override
97+
protected T _fromString(JsonParser p, DeserializationContext ctxt, String string0) throws IOException {
98+
return super._fromString(p, ctxt, string0.replace( ' ', 'T' ));
99+
}
100+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* OpenAPI Petstore
3+
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package org.openapitools.client;
14+
15+
import java.time.Instant;
16+
import java.time.OffsetDateTime;
17+
import java.time.ZonedDateTime;
18+
19+
import com.fasterxml.jackson.databind.module.SimpleModule;
20+
import com.fasterxml.jackson.databind.Module.SetupContext;
21+
22+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
23+
public class RFC3339JavaTimeModule extends SimpleModule {
24+
private static final long serialVersionUID = 1L;
25+
26+
public RFC3339JavaTimeModule() {
27+
super("RFC3339JavaTimeModule");
28+
}
29+
30+
@Override
31+
public void setupModule(SetupContext context) {
32+
super.setupModule(context);
33+
34+
addDeserializer(Instant.class, RFC3339InstantDeserializer.INSTANT);
35+
addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME);
36+
addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME);
37+
}
38+
39+
}

‎samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ docs/Foo.md
5757
docs/FooGetDefaultResponse.md
5858
docs/FormatTest.md
5959
docs/HasOnlyReadOnly.md
60+
docs/HeaderArg.md
6061
docs/HealthCheckResult.md
6162
docs/HuntingDog.md
6263
docs/ImportTestDatetimeApi.md
@@ -191,6 +192,7 @@ petstore_api/models/foo.py
191192
petstore_api/models/foo_get_default_response.py
192193
petstore_api/models/format_test.py
193194
petstore_api/models/has_only_read_only.py
195+
petstore_api/models/header_arg.py
194196
petstore_api/models/health_check_result.py
195197
petstore_api/models/hunting_dog.py
196198
petstore_api/models/info.py

‎samples/openapi3/client/petstore/python-aiohttp/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Class | Method | HTTP request | Description
147147
*FakeApi* | [**test_inline_additional_properties**](docs/FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
148148
*FakeApi* | [**test_inline_freeform_additional_properties**](docs/FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
149149
*FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
150+
*FakeApi* | [**test_json_header_content**](docs/FakeApi.md#test_json_header_content) | **POST** /test/json-header-content |
150151
*FakeApi* | [**test_object_for_multipart_requests**](docs/FakeApi.md#test_object_for_multipart_requests) | **POST** /fake/object_for_multipart_requests |
151152
*FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-parameters |
152153
*FakeApi* | [**test_string_map_reference**](docs/FakeApi.md#test_string_map_reference) | **POST** /fake/stringMap-reference | test referenced string map
@@ -228,6 +229,7 @@ Class | Method | HTTP request | Description
228229
- [FooGetDefaultResponse](docs/FooGetDefaultResponse.md)
229230
- [FormatTest](docs/FormatTest.md)
230231
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
232+
- [HeaderArg](docs/HeaderArg.md)
231233
- [HealthCheckResult](docs/HealthCheckResult.md)
232234
- [HuntingDog](docs/HuntingDog.md)
233235
- [Info](docs/Info.md)

‎samples/openapi3/client/petstore/python-aiohttp/docs/FakeApi.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Method | HTTP request | Description
3737
[**test_inline_additional_properties**](FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
3838
[**test_inline_freeform_additional_properties**](FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
3939
[**test_json_form_data**](FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
40+
[**test_json_header_content**](FakeApi.md#test_json_header_content) | **POST** /test/json-header-content |
4041
[**test_object_for_multipart_requests**](FakeApi.md#test_object_for_multipart_requests) | **POST** /fake/object_for_multipart_requests |
4142
[**test_query_parameter_collection_format**](FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-parameters |
4243
[**test_string_map_reference**](FakeApi.md#test_string_map_reference) | **POST** /fake/stringMap-reference | test referenced string map
@@ -2265,6 +2266,69 @@ No authorization required
22652266

22662267
[[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)
22672268

2269+
# **test_json_header_content**
2270+
> test_json_header_content(x_json_arg, x_plain_arg=x_plain_arg)
2271+
2272+
### Example
2273+
2274+
2275+
```python
2276+
import petstore_api
2277+
from petstore_api.models.header_arg import HeaderArg
2278+
from petstore_api.rest import ApiException
2279+
from pprint import pprint
2280+
2281+
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
2282+
# See configuration.py for a list of all supported configuration parameters.
2283+
configuration = petstore_api.Configuration(
2284+
host = "http://petstore.swagger.io:80/v2"
2285+
)
2286+
2287+
2288+
# Enter a context with an instance of the API client
2289+
async with petstore_api.ApiClient(configuration) as api_client:
2290+
# Create an instance of the API class
2291+
api_instance = petstore_api.FakeApi(api_client)
2292+
x_json_arg = petstore_api.HeaderArg() # HeaderArg |
2293+
x_plain_arg = 'x_plain_arg_example' # str | (optional)
2294+
2295+
try:
2296+
await api_instance.test_json_header_content(x_json_arg, x_plain_arg=x_plain_arg)
2297+
except Exception as e:
2298+
print("Exception when calling FakeApi->test_json_header_content: %s\n" % e)
2299+
```
2300+
2301+
2302+
2303+
### Parameters
2304+
2305+
2306+
Name | Type | Description | Notes
2307+
------------- | ------------- | ------------- | -------------
2308+
**x_json_arg** | [**HeaderArg**](.md)| |
2309+
**x_plain_arg** | **str**| | [optional]
2310+
2311+
### Return type
2312+
2313+
void (empty response body)
2314+
2315+
### Authorization
2316+
2317+
No authorization required
2318+
2319+
### HTTP request headers
2320+
2321+
- **Content-Type**: Not defined
2322+
- **Accept**: Not defined
2323+
2324+
### HTTP response details
2325+
2326+
| Status code | Description | Response headers |
2327+
|-------------|-------------|------------------|
2328+
**204** | No content | - |
2329+
2330+
[[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)
2331+
22682332
# **test_object_for_multipart_requests**
22692333
> test_object_for_multipart_requests(marker)
22702334
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# HeaderArg
2+
3+
4+
## Properties
5+
6+
Name | Type | Description | Notes
7+
------------ | ------------- | ------------- | -------------
8+
**path** | **str** | | [optional]
9+
**recursive** | **bool** | | [optional]
10+
11+
## Example
12+
13+
```python
14+
from petstore_api.models.header_arg import HeaderArg
15+
16+
# TODO update the JSON string below
17+
json = "{}"
18+
# create an instance of HeaderArg from a JSON string
19+
header_arg_instance = HeaderArg.from_json(json)
20+
# print the JSON string representation of the object
21+
print(HeaderArg.to_json())
22+
23+
# convert the object into a dict
24+
header_arg_dict = header_arg_instance.to_dict()
25+
# create an instance of HeaderArg from a dict
26+
header_arg_from_dict = HeaderArg.from_dict(header_arg_dict)
27+
```
28+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
29+
30+

‎samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"FooGetDefaultResponse",
8787
"FormatTest",
8888
"HasOnlyReadOnly",
89+
"HeaderArg",
8990
"HealthCheckResult",
9091
"HuntingDog",
9192
"Info",
@@ -225,6 +226,7 @@
225226
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse as FooGetDefaultResponse
226227
from petstore_api.models.format_test import FormatTest as FormatTest
227228
from petstore_api.models.has_only_read_only import HasOnlyReadOnly as HasOnlyReadOnly
229+
from petstore_api.models.header_arg import HeaderArg as HeaderArg
228230
from petstore_api.models.health_check_result import HealthCheckResult as HealthCheckResult
229231
from petstore_api.models.hunting_dog import HuntingDog as HuntingDog
230232
from petstore_api.models.info import Info as Info

0 commit comments

Comments
 (0)