Repository navigation
Add tests for json headers (python) #25112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * OpenAPI Petstore | ||
| * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
| * | ||
| * The version of the OpenAPI document: 1.0.0 | ||
| * | ||
| * | ||
| * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| * https://openapi-generator.tech | ||
| * Do not edit the class manually. | ||
| */ | ||
|
|
||
| package org.openapitools.client; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Instant; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.temporal.Temporal; | ||
| import java.time.temporal.TemporalAccessor; | ||
| import java.util.function.BiFunction; | ||
| import java.util.function.Function; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParser; | ||
|
Check failure on line 26 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
|
||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
Check failure on line 27 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
|
||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature; | ||
|
Check failure on line 28 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
|
||
| import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer; | ||
|
Check failure on line 29 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
|
||
|
|
||
| @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT") | ||
| public class RFC3339InstantDeserializer<T extends Temporal> extends InstantDeserializer<T> { | ||
| private static final long serialVersionUID = 1L; | ||
| private final static boolean DEFAULT_NORMALIZE_ZONE_ID = JavaTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault(); | ||
| private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS | ||
| = JavaTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault(); | ||
|
|
||
| public static final RFC3339InstantDeserializer<Instant> INSTANT = new RFC3339InstantDeserializer<>( | ||
| Instant.class, DateTimeFormatter.ISO_INSTANT, | ||
| Instant::from, | ||
| a -> Instant.ofEpochMilli( a.value ), | ||
| a -> Instant.ofEpochSecond( a.integer, a.fraction ), | ||
| null, | ||
| true, // yes, replace zero offset with Z | ||
| DEFAULT_NORMALIZE_ZONE_ID, | ||
| DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS | ||
| ); | ||
|
|
||
| public static final RFC3339InstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new RFC3339InstantDeserializer<>( | ||
| OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, | ||
| OffsetDateTime::from, | ||
| a -> OffsetDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ), | ||
| a -> OffsetDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ), | ||
| (d, z) -> ( d.isEqual( OffsetDateTime.MIN ) || d.isEqual( OffsetDateTime.MAX ) ? | ||
| d : | ||
| d.withOffsetSameInstant( z.getRules().getOffset( d.toLocalDateTime() ) ) ), | ||
| true, // yes, replace zero offset with Z | ||
| DEFAULT_NORMALIZE_ZONE_ID, | ||
| DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS | ||
| ); | ||
|
|
||
| public static final RFC3339InstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new RFC3339InstantDeserializer<>( | ||
| ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, | ||
| ZonedDateTime::from, | ||
| a -> ZonedDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ), | ||
| a -> ZonedDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ), | ||
| ZonedDateTime::withZoneSameInstant, | ||
| false, // keep zero offset and Z separate since zones explicitly supported | ||
| DEFAULT_NORMALIZE_ZONE_ID, | ||
| DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS | ||
| ); | ||
|
|
||
| protected RFC3339InstantDeserializer( | ||
| Class<T> supportedType, | ||
| DateTimeFormatter formatter, | ||
| Function<TemporalAccessor, T> parsedToValue, | ||
| Function<FromIntegerArguments, T> fromMilliseconds, | ||
| Function<FromDecimalArguments, T> fromNanoseconds, | ||
| BiFunction<T, ZoneId, T> adjust, | ||
| boolean replaceZeroOffsetAsZ, | ||
| boolean normalizeZoneId, | ||
| boolean readNumericStringsAsTimestamp) { | ||
| super( | ||
| supportedType, | ||
| formatter, | ||
| parsedToValue, | ||
| fromMilliseconds, | ||
| fromNanoseconds, | ||
| adjust, | ||
| replaceZeroOffsetAsZ, | ||
| normalizeZoneId, | ||
| readNumericStringsAsTimestamp | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected T _fromString(JsonParser p, DeserializationContext ctxt, String string0) throws IOException { | ||
| return super._fromString(p, ctxt, string0.replace( ' ', 'T' )); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * OpenAPI Petstore | ||
| * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
| * | ||
| * The version of the OpenAPI document: 1.0.0 | ||
| * | ||
| * | ||
| * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| * https://openapi-generator.tech | ||
| * Do not edit the class manually. | ||
| */ | ||
|
|
||
| package org.openapitools.client; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.ZonedDateTime; | ||
|
|
||
| import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
Check failure on line 19 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java
|
||
| import com.fasterxml.jackson.databind.Module.SetupContext; | ||
|
Check failure on line 20 in samples/client/petstore/java/rest-assured-jackson3/src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java
|
||
|
|
||
| @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT") | ||
| public class RFC3339JavaTimeModule extends SimpleModule { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public RFC3339JavaTimeModule() { | ||
| super("RFC3339JavaTimeModule"); | ||
| } | ||
|
|
||
| @Override | ||
| public void setupModule(SetupContext context) { | ||
| super.setupModule(context); | ||
|
|
||
| addDeserializer(Instant.class, RFC3339InstantDeserializer.INSTANT); | ||
| addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME); | ||
| addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,7 @@ Method | HTTP request | Description | |||||
| [**test_inline_additional_properties**](FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties | ||||||
| [**test_inline_freeform_additional_properties**](FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties | ||||||
| [**test_json_form_data**](FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data | ||||||
| [**test_json_header_content**](FakeApi.md#test_json_header_content) | **POST** /test/json-header-content | | ||||||
| [**test_object_for_multipart_requests**](FakeApi.md#test_object_for_multipart_requests) | **POST** /fake/object_for_multipart_requests | | ||||||
| [**test_query_parameter_collection_format**](FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-parameters | | ||||||
| [**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 | |||||
|
|
||||||
| [[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) | ||||||
|
|
||||||
| # **test_json_header_content** | ||||||
| > test_json_header_content(x_json_arg, x_plain_arg=x_plain_arg) | ||||||
|
|
||||||
| ### Example | ||||||
|
|
||||||
|
|
||||||
| ```python | ||||||
| import petstore_api | ||||||
| from petstore_api.models.header_arg import HeaderArg | ||||||
| from petstore_api.rest import ApiException | ||||||
| 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 | ||||||
| async with petstore_api.ApiClient(configuration) as api_client: | ||||||
| # Create an instance of the API class | ||||||
| api_instance = petstore_api.FakeApi(api_client) | ||||||
| x_json_arg = petstore_api.HeaderArg() # HeaderArg | | ||||||
| x_plain_arg = 'x_plain_arg_example' # str | (optional) | ||||||
|
|
||||||
| try: | ||||||
| await api_instance.test_json_header_content(x_json_arg, x_plain_arg=x_plain_arg) | ||||||
| except Exception as e: | ||||||
| print("Exception when calling FakeApi->test_json_header_content: %s\n" % e) | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| ### Parameters | ||||||
|
|
||||||
|
|
||||||
| Name | Type | Description | Notes | ||||||
| ------------- | ------------- | ------------- | ------------- | ||||||
| **x_json_arg** | [**HeaderArg**](.md)| | | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The Prompt for AI agents
Suggested change
|
||||||
| **x_plain_arg** | **str**| | [optional] | ||||||
|
|
||||||
| ### Return type | ||||||
|
|
||||||
| void (empty response body) | ||||||
|
|
||||||
| ### Authorization | ||||||
|
|
||||||
| No authorization required | ||||||
|
|
||||||
| ### HTTP request headers | ||||||
|
|
||||||
| - **Content-Type**: Not defined | ||||||
| - **Accept**: Not defined | ||||||
|
|
||||||
| ### HTTP response details | ||||||
|
|
||||||
| | Status code | Description | Response headers | | ||||||
| |-------------|-------------|------------------| | ||||||
| **204** | No content | - | | ||||||
|
|
||||||
| [[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) | ||||||
|
|
||||||
| # **test_object_for_multipart_requests** | ||||||
| > test_object_for_multipart_requests(marker) | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| # HeaderArg | ||||||
|
|
||||||
|
|
||||||
| ## Properties | ||||||
|
|
||||||
| Name | Type | Description | Notes | ||||||
| ------------ | ------------- | ------------- | ------------- | ||||||
| **path** | **str** | | [optional] | ||||||
| **recursive** | **bool** | | [optional] | ||||||
|
|
||||||
| ## Example | ||||||
|
|
||||||
| ```python | ||||||
| from petstore_api.models.header_arg import HeaderArg | ||||||
|
|
||||||
| # TODO update the JSON string below | ||||||
| json = "{}" | ||||||
| # create an instance of HeaderArg from a JSON string | ||||||
| header_arg_instance = HeaderArg.from_json(json) | ||||||
| # print the JSON string representation of the object | ||||||
| print(HeaderArg.to_json()) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The example calls Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| # convert the object into a dict | ||||||
| header_arg_dict = header_arg_instance.to_dict() | ||||||
| # create an instance of HeaderArg from a dict | ||||||
| header_arg_from_dict = HeaderArg.from_dict(header_arg_dict) | ||||||
| ``` | ||||||
| [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
super.setupModuleruns while this module has no deserializers, so Jackson never registers these handlers with the mapper. Add them before callingsuper.setupModule.Prompt for AI agents