diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 172c26eb0bb0..f9a1915ffc6f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -141,11 +141,15 @@ private void flattenPaths() { } } + // flatten path-level parameters + flattenParameters(pathname, path.getParameters(), null); + + // flatten parameters for each operation for (Map.Entry operationEntry : toFlatten) { Operation operation = operationEntry.getValue(); String inlineSchemaName = this.getInlineSchemaName(operationEntry.getKey(), pathname); flattenRequestBody(inlineSchemaName, operation); - flattenParameters(inlineSchemaName, operation); + flattenParameters(inlineSchemaName, operation.getParameters(), operation.getOperationId()); flattenResponses(inlineSchemaName, operation); } } @@ -509,15 +513,20 @@ private void flattenRequestBody(String modelName, Operation operation) { * Flatten inline models in parameters * * @param modelName model name - * @param operation target operation + * @param parameters list of parameters + * @param operationId operation Id (optional) */ - private void flattenParameters(String modelName, Operation operation) { - List parameters = operation.getParameters(); + private void flattenParameters(String modelName, List parameters, String operationId) { + //List parameters = operation.getParameters(); if (parameters == null) { return; } for (Parameter parameter : parameters) { + if (StringUtils.isNotEmpty(parameter.get$ref())) { + parameter = ModelUtils.getReferencedParameter(openAPI, parameter); + } + if (parameter.getSchema() == null) { continue; } @@ -528,7 +537,7 @@ private void flattenParameters(String modelName, Operation operation) { continue; } String schemaName = resolveModelName(parameterSchema.getTitle(), - (operation.getOperationId() == null ? modelName : operation.getOperationId()) + "_" + parameter.getName() + "_parameter"); + (operationId == null ? modelName : operationId) + "_" + parameter.getName() + "_parameter"); // Recursively gather/make inline models within this schema if any gatherInlineModels(parameterSchema, schemaName); if (isModelNeeded(parameterSchema)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java index ece6f10b7540..d67bb0788643 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java @@ -411,9 +411,7 @@ private void normalizeParameters(List parameters) { parameter = ModelUtils.getReferencedParameter(openAPI, parameter); } - if (parameter.getSchema() == null) { - continue; - } else { + if (parameter.getSchema() != null) { Schema newSchema = normalizeSchema(parameter.getSchema(), new HashSet<>()); parameter.setSchema(newSchema); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 52e71fc22b79..43d890695e08 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -704,7 +704,7 @@ public Map postProcessAllModels(Map objs) propertyHash.put(property.name, property); final CodegenProperty parentVar = property.clone(); parentVar.isInherited = true; - LOGGER.info("adding parent variable {} to {}", property.name, codegenModel.name); + LOGGER.debug("adding parent variable {} to {}", property.name, codegenModel.name); codegenModel.parentVars.add(parentVar); Set imports = parentVar.getImports(true, this.importBaseType, generatorMetadata.getFeatureSet()).stream().filter(Objects::nonNull).collect(Collectors.toSet()); for (String imp : imports) { diff --git a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml index 96e8b57753fa..1f8285397936 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml @@ -1340,7 +1340,7 @@ paths: post: tags: - fake - summary: fake uploads an image with ref request bodies + summary: fake reference parameter description: '' operationId: fake-upload-ref-request-bodies parameters: @@ -1364,7 +1364,18 @@ paths: - 'read:pets' requestBody: $ref: '#/components/requestBodies/upload_body' - + '/fake/pet/{petId}/reference/parameter': + post: + tags: + - fake + summary: fake reference parameter + description: '' + operationId: fake-ref-parameter + parameters: + - $ref: '#/components/parameters/pet_id' + responses: + '200': + description: successful operation /values: get: tags: @@ -1423,6 +1434,16 @@ servers: - url: https://127.0.0.1/no_variable description: The local server without variables components: + parameters: + pet_id: + name: petId + in: path + description: to test oneOf in parameter $ref + required: true + schema: + oneOf: + - type: string + - type: integer requestBodies: upload_body: content: diff --git a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml index 4b20b4fa28b6..5e4b22628055 100644 --- a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml @@ -609,6 +609,28 @@ paths: $ref: '#/components/responses/ref' parameters: - $ref: '#/components/parameters/ref_to_uuid' + /ref/ref_to_path_level_parameter_oneof: + get: + description: to test $ref to path level parameters + operationId: ref_to_ref_parameter_oneof + tags: + - fake + responses: + '200': + description: Successful Response + parameters: + - $ref: '#/components/parameters/ref_to_oneof' + /ref/ref_to_operation_level_parameter_oneof: + get: + description: to test $ref to operation level parameters + operationId: ref_to_ref_parameter_anyof + tags: + - fake + responses: + '200': + description: Successful Response + parameters: + - $ref: '#/components/parameters/ref_to_anyof' "/fake/api/changeowner": post: summary: op1 @@ -720,6 +742,26 @@ components: type: string format: uuid example: 61864654-6e6b-4152-a62f-795fdd606bc2 + ref_to_oneof: + description: to test ref to parameter (oneof) + name: ref_to_oneof + in: header + required: true + schema: + oneOf: + - type: string + - type: integer + ref_to_anyof: + description: to test ref to parameter (anyof) + name: ref_to_anyof + in: header + required: true + schema: + oneOf: + - type: string + - type: array + items: + type: string requestBodies: UserArray: content: @@ -1023,4 +1065,4 @@ components: allOf: - $ref: '#/components/schemas/SimpleModelWithArrayProperty' myObject: - type: object \ No newline at end of file + type: object diff --git a/samples/client/petstore/java/okhttp-gson-3.1/.openapi-generator/FILES b/samples/client/petstore/java/okhttp-gson-3.1/.openapi-generator/FILES index 2cba97181005..943f1a855f60 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/.openapi-generator/FILES +++ b/samples/client/petstore/java/okhttp-gson-3.1/.openapi-generator/FILES @@ -22,6 +22,8 @@ docs/OneOfStringOrInt.md docs/Order.md docs/Pet.md docs/PetApi.md +docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md +docs/RefToRefParameterAnyofRefToAnyofParameter.md docs/SimpleModelWithArrayProperty.md docs/StoreApi.md docs/StringOrInt.md @@ -78,6 +80,8 @@ src/main/java/org/openapitools/client/model/ModelApiResponse.java src/main/java/org/openapitools/client/model/OneOfStringOrInt.java src/main/java/org/openapitools/client/model/Order.java src/main/java/org/openapitools/client/model/Pet.java +src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java +src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java src/main/java/org/openapitools/client/model/SimpleModelWithArrayProperty.java src/main/java/org/openapitools/client/model/StringOrInt.java src/main/java/org/openapitools/client/model/Tag.java diff --git a/samples/client/petstore/java/okhttp-gson-3.1/README.md b/samples/client/petstore/java/okhttp-gson-3.1/README.md index 6ddae902ff07..afe27203cdb2 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/README.md +++ b/samples/client/petstore/java/okhttp-gson-3.1/README.md @@ -120,6 +120,8 @@ Class | Method | HTTP request | Description *FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2 *FakeApi* | [**op3**](docs/FakeApi.md#op3) | **POST** /fake/api/query/enum | op3 *FakeApi* | [**refToRefParameter**](docs/FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter | +*FakeApi* | [**refToRefParameterAnyof**](docs/FakeApi.md#refToRefParameterAnyof) | **GET** /ref/ref_to_operation_level_parameter_oneof | +*FakeApi* | [**refToRefParameterOneof**](docs/FakeApi.md#refToRefParameterOneof) | **GET** /ref/ref_to_path_level_parameter_oneof | *FakeApi* | [**responseNoRef**](docs/FakeApi.md#responseNoRef) | **GET** /no_ref | *FakeApi* | [**responseRefToNoRef**](docs/FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref | *FakeApi* | [**responseRefToRef**](docs/FakeApi.md#responseRefToRef) | **GET** /ref/ref | @@ -162,6 +164,8 @@ Class | Method | HTTP request | Description - [OneOfStringOrInt](docs/OneOfStringOrInt.md) - [Order](docs/Order.md) - [Pet](docs/Pet.md) + - [RefRefToPathLevelParameterOneofRefToOneofParameter](docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md) + - [RefToRefParameterAnyofRefToAnyofParameter](docs/RefToRefParameterAnyofRefToAnyofParameter.md) - [SimpleModelWithArrayProperty](docs/SimpleModelWithArrayProperty.md) - [StringOrInt](docs/StringOrInt.md) - [Tag](docs/Tag.md) diff --git a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml index 262309383b01..489ebd8ff4ba 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml @@ -687,6 +687,34 @@ paths: - text/plain parameters: - $ref: '#/components/parameters/ref_to_uuid' + /ref/ref_to_path_level_parameter_oneof: + get: + description: to test $ref to path level parameters + operationId: ref_to_ref_parameter_oneof + parameters: + - $ref: '#/components/parameters/ref_to_oneof' + responses: + "200": + description: Successful Response + tags: + - fake + x-accepts: + - application/json + parameters: + - $ref: '#/components/parameters/ref_to_oneof' + /ref/ref_to_operation_level_parameter_oneof: + get: + description: to test $ref to operation level parameters + operationId: ref_to_ref_parameter_anyof + parameters: + - $ref: '#/components/parameters/ref_to_anyof' + responses: + "200": + description: Successful Response + tags: + - fake + x-accepts: + - application/json /fake/api/changeowner: post: operationId: op1 @@ -805,6 +833,24 @@ components: format: uuid type: string style: simple + ref_to_oneof: + description: to test ref to parameter (oneof) + explode: false + in: header + name: ref_to_oneof + required: true + schema: + $ref: '#/components/schemas/_ref_ref_to_path_level_parameter_oneof_ref_to_oneof_parameter' + style: simple + ref_to_anyof: + description: to test ref to parameter (anyof) + explode: false + in: header + name: ref_to_anyof + required: true + schema: + $ref: '#/components/schemas/ref_to_ref_parameter_anyof_ref_to_anyof_parameter' + style: simple requestBodies: UserArray: content: @@ -1134,6 +1180,15 @@ components: description: file to upload format: binary type: string + _ref_ref_to_path_level_parameter_oneof_ref_to_oneof_parameter: + oneOf: + - type: string + - type: integer + ref_to_ref_parameter_anyof_ref_to_anyof_parameter: + oneOf: + - type: string + - items: + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md index 19db959c0ed6..ca3064946773 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md @@ -11,6 +11,8 @@ All URIs are relative to *http://petstore.swagger.io/v2* | [**op2**](FakeApi.md#op2) | **POST** /fake/api/changename | op2 | | [**op3**](FakeApi.md#op3) | **POST** /fake/api/query/enum | op3 | | [**refToRefParameter**](FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter | | +| [**refToRefParameterAnyof**](FakeApi.md#refToRefParameterAnyof) | **GET** /ref/ref_to_operation_level_parameter_oneof | | +| [**refToRefParameterOneof**](FakeApi.md#refToRefParameterOneof) | **GET** /ref/ref_to_path_level_parameter_oneof | | | [**responseNoRef**](FakeApi.md#responseNoRef) | **GET** /no_ref | | | [**responseRefToNoRef**](FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref | | | [**responseRefToRef**](FakeApi.md#responseRefToRef) | **GET** /ref/ref | | @@ -417,6 +419,128 @@ No authorization required |-------------|-------------|------------------| | **200** | | - | + +# **refToRefParameterAnyof** +> refToRefParameterAnyof(refToAnyof) + + + +to test $ref to operation level parameters + +### Example +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.FakeApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io/v2"); + + FakeApi apiInstance = new FakeApi(defaultClient); + RefToRefParameterAnyofRefToAnyofParameter refToAnyof = new RefToRefParameterAnyofRefToAnyofParameter(); // RefToRefParameterAnyofRefToAnyofParameter | to test ref to parameter (anyof) + try { + apiInstance.refToRefParameterAnyof(refToAnyof); + } catch (ApiException e) { + System.err.println("Exception when calling FakeApi#refToRefParameterAnyof"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **refToAnyof** | [**RefToRefParameterAnyofRefToAnyofParameter**](.md)| to test ref to parameter (anyof) | | + +### Return type + +null (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 | +|-------------|-------------|------------------| +| **200** | Successful Response | - | + + +# **refToRefParameterOneof** +> refToRefParameterOneof(refToOneof) + + + +to test $ref to path level parameters + +### Example +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.FakeApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io/v2"); + + FakeApi apiInstance = new FakeApi(defaultClient); + RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof = new RefRefToPathLevelParameterOneofRefToOneofParameter(); // RefRefToPathLevelParameterOneofRefToOneofParameter | to test ref to parameter (oneof) + try { + apiInstance.refToRefParameterOneof(refToOneof); + } catch (ApiException e) { + System.err.println("Exception when calling FakeApi#refToRefParameterOneof"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **refToOneof** | [**RefRefToPathLevelParameterOneofRefToOneofParameter**](.md)| to test ref to parameter (oneof) | | + +### Return type + +null (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 | +|-------------|-------------|------------------| +| **200** | Successful Response | - | + # **responseNoRef** > String responseNoRef() diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md new file mode 100644 index 000000000000..1d06eb272969 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md @@ -0,0 +1,12 @@ + + +# RefRefToPathLevelParameterOneofRefToOneofParameter + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterAnyofRefToAnyofParameter.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterAnyofRefToAnyofParameter.md new file mode 100644 index 000000000000..c204a306bfaa --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterAnyofRefToAnyofParameter.md @@ -0,0 +1,12 @@ + + +# RefToRefParameterAnyofRefToAnyofParameter + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterOneofRefToOneofParameter.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterOneofRefToOneofParameter.md new file mode 100644 index 000000000000..2c53b8e02122 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/RefToRefParameterOneofRefToOneofParameter.md @@ -0,0 +1,12 @@ + + +# RefToRefParameterOneofRefToOneofParameter + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java index 6fe26034d7ed..d0a1342c44c5 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java @@ -135,6 +135,8 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.OneOfStringOrInt.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Order.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Pet.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.RefRefToPathLevelParameterOneofRefToOneofParameter.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.RefToRefParameterAnyofRefToAnyofParameter.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.SimpleModelWithArrayProperty.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.StringOrInt.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Tag.CustomTypeAdapterFactory()); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java index 67436864a00f..800c13aa9ec0 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/api/FakeApi.java @@ -28,6 +28,8 @@ import org.openapitools.client.model.CodesEnum; +import org.openapitools.client.model.RefRefToPathLevelParameterOneofRefToOneofParameter; +import org.openapitools.client.model.RefToRefParameterAnyofRefToAnyofParameter; import java.util.UUID; import java.lang.reflect.Type; @@ -893,6 +895,248 @@ public okhttp3.Call refToRefParameterAsync(UUID refToUuid, final ApiCallback + Status Code Description Response Headers + 200 Successful Response - + + */ + public okhttp3.Call refToRefParameterAnyofCall(RefToRefParameterAnyofRefToAnyofParameter refToAnyof, final ApiCallback _callback) throws ApiException { + String basePath = null; + // Operation Servers + String[] localBasePaths = new String[] { }; + + // Determine Base Path to Use + if (localCustomBaseUrl != null){ + basePath = localCustomBaseUrl; + } else if ( localBasePaths.length > 0 ) { + basePath = localBasePaths[localHostIndex]; + } else { + basePath = null; + } + + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/ref/ref_to_operation_level_parameter_oneof"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + if (refToAnyof != null) { + localVarHeaderParams.put("ref_to_anyof", localVarApiClient.parameterToString(refToAnyof)); + } + + final String[] localVarAccepts = { + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + + String[] localVarAuthNames = new String[] { }; + return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call refToRefParameterAnyofValidateBeforeCall(RefToRefParameterAnyofRefToAnyofParameter refToAnyof, final ApiCallback _callback) throws ApiException { + // verify the required parameter 'refToAnyof' is set + if (refToAnyof == null) { + throw new ApiException("Missing the required parameter 'refToAnyof' when calling refToRefParameterAnyof(Async)"); + } + + return refToRefParameterAnyofCall(refToAnyof, _callback); + + } + + /** + * + * to test $ref to operation level parameters + * @param refToAnyof to test ref to parameter (anyof) (required) + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public void refToRefParameterAnyof(RefToRefParameterAnyofRefToAnyofParameter refToAnyof) throws ApiException { + refToRefParameterAnyofWithHttpInfo(refToAnyof); + } + + /** + * + * to test $ref to operation level parameters + * @param refToAnyof to test ref to parameter (anyof) (required) + * @return ApiResponse<Void> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public ApiResponse refToRefParameterAnyofWithHttpInfo(RefToRefParameterAnyofRefToAnyofParameter refToAnyof) throws ApiException { + okhttp3.Call localVarCall = refToRefParameterAnyofValidateBeforeCall(refToAnyof, null); + return localVarApiClient.execute(localVarCall); + } + + /** + * (asynchronously) + * to test $ref to operation level parameters + * @param refToAnyof to test ref to parameter (anyof) (required) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public okhttp3.Call refToRefParameterAnyofAsync(RefToRefParameterAnyofRefToAnyofParameter refToAnyof, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = refToRefParameterAnyofValidateBeforeCall(refToAnyof, _callback); + localVarApiClient.executeAsync(localVarCall, _callback); + return localVarCall; + } + /** + * Build call for refToRefParameterOneof + * @param refToOneof to test ref to parameter (oneof) (required) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public okhttp3.Call refToRefParameterOneofCall(RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof, final ApiCallback _callback) throws ApiException { + String basePath = null; + // Operation Servers + String[] localBasePaths = new String[] { }; + + // Determine Base Path to Use + if (localCustomBaseUrl != null){ + basePath = localCustomBaseUrl; + } else if ( localBasePaths.length > 0 ) { + basePath = localBasePaths[localHostIndex]; + } else { + basePath = null; + } + + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/ref/ref_to_path_level_parameter_oneof"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + if (refToOneof != null) { + localVarHeaderParams.put("ref_to_oneof", localVarApiClient.parameterToString(refToOneof)); + } + + final String[] localVarAccepts = { + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + + String[] localVarAuthNames = new String[] { }; + return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call refToRefParameterOneofValidateBeforeCall(RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof, final ApiCallback _callback) throws ApiException { + // verify the required parameter 'refToOneof' is set + if (refToOneof == null) { + throw new ApiException("Missing the required parameter 'refToOneof' when calling refToRefParameterOneof(Async)"); + } + + return refToRefParameterOneofCall(refToOneof, _callback); + + } + + /** + * + * to test $ref to path level parameters + * @param refToOneof to test ref to parameter (oneof) (required) + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public void refToRefParameterOneof(RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof) throws ApiException { + refToRefParameterOneofWithHttpInfo(refToOneof); + } + + /** + * + * to test $ref to path level parameters + * @param refToOneof to test ref to parameter (oneof) (required) + * @return ApiResponse<Void> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public ApiResponse refToRefParameterOneofWithHttpInfo(RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof) throws ApiException { + okhttp3.Call localVarCall = refToRefParameterOneofValidateBeforeCall(refToOneof, null); + return localVarApiClient.execute(localVarCall); + } + + /** + * (asynchronously) + * to test $ref to path level parameters + * @param refToOneof to test ref to parameter (oneof) (required) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 Successful Response -
+ */ + public okhttp3.Call refToRefParameterOneofAsync(RefRefToPathLevelParameterOneofRefToOneofParameter refToOneof, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = refToRefParameterOneofValidateBeforeCall(refToOneof, _callback); + localVarApiClient.executeAsync(localVarCall, _callback); + return localVarCall; + } /** * Build call for responseNoRef * @param _callback Callback for upload/download progress diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java new file mode 100644 index 000000000000..3001dbb6ac92 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java @@ -0,0 +1,273 @@ +/* + * 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.model; + +import java.util.Objects; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.9.0-SNAPSHOT") +public class RefRefToPathLevelParameterOneofRefToOneofParameter extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(RefRefToPathLevelParameterOneofRefToOneofParameter.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!RefRefToPathLevelParameterOneofRefToOneofParameter.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'RefRefToPathLevelParameterOneofRefToOneofParameter' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterString = gson.getDelegateAdapter(this, TypeToken.get(String.class)); + final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, RefRefToPathLevelParameterOneofRefToOneofParameter value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `String` + if (value.getActualInstance() instanceof String) { + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `Integer` + if (value.getActualInstance() instanceof Integer) { + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, String"); + } + + @Override + public RefRefToPathLevelParameterOneofRefToOneofParameter read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize String + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); + } + // deserialize Integer + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + } + + if (match == 1) { + RefRefToPathLevelParameterOneofRefToOneofParameter ret = new RefRefToPathLevelParameterOneofRefToOneofParameter(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for RefRefToPathLevelParameterOneofRefToOneofParameter: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public RefRefToPathLevelParameterOneofRefToOneofParameter() { + super("oneOf", Boolean.FALSE); + } + + public RefRefToPathLevelParameterOneofRefToOneofParameter(Object o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("String", String.class); + schemas.put("Integer", Integer.class); + } + + @Override + public Map> getSchemas() { + return RefRefToPathLevelParameterOneofRefToOneofParameter.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * Integer, String + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof String) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof Integer) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException("Invalid instance type. Must be Integer, String"); + } + + /** + * Get the actual instance, which can be the following: + * Integer, String + * + * @return The actual instance (Integer, String) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `String`. If the actual instance is not `String`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `String` + * @throws ClassCastException if the instance is not `String` + */ + public String getString() throws ClassCastException { + return (String)super.getActualInstance(); + } + /** + * Get the actual instance of `Integer`. If the actual instance is not `Integer`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Integer` + * @throws ClassCastException if the instance is not `Integer` + */ + public Integer getInteger() throws ClassCastException { + return (Integer)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to RefRefToPathLevelParameterOneofRefToOneofParameter + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for RefRefToPathLevelParameterOneofRefToOneofParameter with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of RefRefToPathLevelParameterOneofRefToOneofParameter given an JSON string + * + * @param jsonString JSON string + * @return An instance of RefRefToPathLevelParameterOneofRefToOneofParameter + * @throws IOException if the JSON string is invalid with respect to RefRefToPathLevelParameterOneofRefToOneofParameter + */ + public static RefRefToPathLevelParameterOneofRefToOneofParameter fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, RefRefToPathLevelParameterOneofRefToOneofParameter.class); + } + + /** + * Convert an instance of RefRefToPathLevelParameterOneofRefToOneofParameter to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java new file mode 100644 index 000000000000..6175d372954e --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java @@ -0,0 +1,294 @@ +/* + * 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.model; + +import java.util.Objects; +import java.util.List; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.9.0-SNAPSHOT") +public class RefToRefParameterAnyofRefToAnyofParameter extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(RefToRefParameterAnyofRefToAnyofParameter.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!RefToRefParameterAnyofRefToAnyofParameter.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'RefToRefParameterAnyofRefToAnyofParameter' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterString = gson.getDelegateAdapter(this, TypeToken.get(String.class)); + + final Type typeInstanceListString = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstanceListString)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, RefToRefParameterAnyofRefToAnyofParameter value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `String` + if (value.getActualInstance() instanceof String) { + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `List` + if (value.getActualInstance() instanceof List) { + JsonPrimitive primitive = adapterListString.toJsonTree((List)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: List, String"); + } + + @Override + public RefToRefParameterAnyofRefToAnyofParameter read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize String + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); + } + // deserialize List + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + actualAdapter = adapterListString; + match++; + log.log(Level.FINER, "Input data matches schema 'List'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); + } + + if (match == 1) { + RefToRefParameterAnyofRefToAnyofParameter ret = new RefToRefParameterAnyofRefToAnyofParameter(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for RefToRefParameterAnyofRefToAnyofParameter: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public RefToRefParameterAnyofRefToAnyofParameter() { + super("oneOf", Boolean.FALSE); + } + + public RefToRefParameterAnyofRefToAnyofParameter(Object o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("String", String.class); + schemas.put("List", List.class); + } + + @Override + public Map> getSchemas() { + return RefToRefParameterAnyofRefToAnyofParameter.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * List, String + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof String) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof List) { + List list = (List) instance; + if (list.get(0) instanceof String) { + super.setActualInstance(instance); + return; + } + } + + throw new RuntimeException("Invalid instance type. Must be List, String"); + } + + /** + * Get the actual instance, which can be the following: + * List, String + * + * @return The actual instance (List, String) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `String`. If the actual instance is not `String`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `String` + * @throws ClassCastException if the instance is not `String` + */ + public String getString() throws ClassCastException { + return (String)super.getActualInstance(); + } + /** + * Get the actual instance of `List`. If the actual instance is not `List`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `List` + * @throws ClassCastException if the instance is not `List` + */ + public List getListString() throws ClassCastException { + return (List)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to RefToRefParameterAnyofRefToAnyofParameter + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for RefToRefParameterAnyofRefToAnyofParameter with oneOf schemas: List, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of RefToRefParameterAnyofRefToAnyofParameter given an JSON string + * + * @param jsonString JSON string + * @return An instance of RefToRefParameterAnyofRefToAnyofParameter + * @throws IOException if the JSON string is invalid with respect to RefToRefParameterAnyofRefToAnyofParameter + */ + public static RefToRefParameterAnyofRefToAnyofParameter fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, RefToRefParameterAnyofRefToAnyofParameter.class); + } + + /** + * Convert an instance of RefToRefParameterAnyofRefToAnyofParameter to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameter.java new file mode 100644 index 000000000000..890716749bc8 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameter.java @@ -0,0 +1,273 @@ +/* + * 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.model; + +import java.util.Objects; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.9.0-SNAPSHOT") +public class RefToRefParameterOneofRefToOneofParameter extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(RefToRefParameterOneofRefToOneofParameter.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!RefToRefParameterOneofRefToOneofParameter.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'RefToRefParameterOneofRefToOneofParameter' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterString = gson.getDelegateAdapter(this, TypeToken.get(String.class)); + final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, RefToRefParameterOneofRefToOneofParameter value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `String` + if (value.getActualInstance() instanceof String) { + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `Integer` + if (value.getActualInstance() instanceof Integer) { + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, String"); + } + + @Override + public RefToRefParameterOneofRefToOneofParameter read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize String + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); + } + // deserialize Integer + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + } + + if (match == 1) { + RefToRefParameterOneofRefToOneofParameter ret = new RefToRefParameterOneofRefToOneofParameter(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for RefToRefParameterOneofRefToOneofParameter: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public RefToRefParameterOneofRefToOneofParameter() { + super("oneOf", Boolean.FALSE); + } + + public RefToRefParameterOneofRefToOneofParameter(Object o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("String", String.class); + schemas.put("Integer", Integer.class); + } + + @Override + public Map> getSchemas() { + return RefToRefParameterOneofRefToOneofParameter.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * Integer, String + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof String) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof Integer) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException("Invalid instance type. Must be Integer, String"); + } + + /** + * Get the actual instance, which can be the following: + * Integer, String + * + * @return The actual instance (Integer, String) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `String`. If the actual instance is not `String`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `String` + * @throws ClassCastException if the instance is not `String` + */ + public String getString() throws ClassCastException { + return (String)super.getActualInstance(); + } + /** + * Get the actual instance of `Integer`. If the actual instance is not `Integer`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Integer` + * @throws ClassCastException if the instance is not `Integer` + */ + public Integer getInteger() throws ClassCastException { + return (Integer)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to RefToRefParameterOneofRefToOneofParameter + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for RefToRefParameterOneofRefToOneofParameter with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of RefToRefParameterOneofRefToOneofParameter given an JSON string + * + * @param jsonString JSON string + * @return An instance of RefToRefParameterOneofRefToOneofParameter + * @throws IOException if the JSON string is invalid with respect to RefToRefParameterOneofRefToOneofParameter + */ + public static RefToRefParameterOneofRefToOneofParameter fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, RefToRefParameterOneofRefToOneofParameter.class); + } + + /** + * Convert an instance of RefToRefParameterOneofRefToOneofParameter to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameterTest.java b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameterTest.java new file mode 100644 index 000000000000..ea34e98696f4 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameterTest.java @@ -0,0 +1,33 @@ +/* + * 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.model; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for RefRefToPathLevelParameterOneofRefToOneofParameter + */ +public class RefRefToPathLevelParameterOneofRefToOneofParameterTest { + private final RefRefToPathLevelParameterOneofRefToOneofParameter model = new RefRefToPathLevelParameterOneofRefToOneofParameter(); + + /** + * Model tests for RefRefToPathLevelParameterOneofRefToOneofParameter + */ + @Test + public void testRefRefToPathLevelParameterOneofRefToOneofParameter() { + // TODO: test RefRefToPathLevelParameterOneofRefToOneofParameter + } + +} diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameterTest.java b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameterTest.java new file mode 100644 index 000000000000..235977518174 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameterTest.java @@ -0,0 +1,34 @@ +/* + * 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.model; + +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for RefToRefParameterAnyofRefToAnyofParameter + */ +public class RefToRefParameterAnyofRefToAnyofParameterTest { + private final RefToRefParameterAnyofRefToAnyofParameter model = new RefToRefParameterAnyofRefToAnyofParameter(); + + /** + * Model tests for RefToRefParameterAnyofRefToAnyofParameter + */ + @Test + public void testRefToRefParameterAnyofRefToAnyofParameter() { + // TODO: test RefToRefParameterAnyofRefToAnyofParameter + } + +} diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameterTest.java b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameterTest.java new file mode 100644 index 000000000000..ebadcce06ccb --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/model/RefToRefParameterOneofRefToOneofParameterTest.java @@ -0,0 +1,33 @@ +/* + * 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.model; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for RefToRefParameterOneofRefToOneofParameter + */ +public class RefToRefParameterOneofRefToOneofParameterTest { + private final RefToRefParameterOneofRefToOneofParameter model = new RefToRefParameterOneofRefToOneofParameter(); + + /** + * Model tests for RefToRefParameterOneofRefToOneofParameter + */ + @Test + public void testRefToRefParameterOneofRefToOneofParameter() { + // TODO: test RefToRefParameterOneofRefToOneofParameter + } + +} diff --git a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES index 113cd16b938e..9f59b5c1b8a2 100644 --- a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES +++ b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES @@ -46,6 +46,7 @@ docs/FakeAnyOfWIthSameErasureGet200Response.md docs/FakeApi.md docs/FakeClassnameTags123Api.md docs/FakeOneOfWIthSameErasureGet200Response.md +docs/FakeRefParameterPetIdParameter.md docs/FileSchemaTestClass.md docs/Foo.md docs/FooGetDefaultResponse.md @@ -190,6 +191,7 @@ src/main/java/org/openapitools/client/model/EnumTest.java src/main/java/org/openapitools/client/model/EquilateralTriangle.java src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java +src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java src/main/java/org/openapitools/client/model/FileSchemaTestClass.java src/main/java/org/openapitools/client/model/Foo.java src/main/java/org/openapitools/client/model/FooGetDefaultResponse.java diff --git a/samples/client/petstore/java/okhttp-gson/README.md b/samples/client/petstore/java/okhttp-gson/README.md index a1a6d0122772..eacf6ad10aff 100644 --- a/samples/client/petstore/java/okhttp-gson/README.md +++ b/samples/client/petstore/java/okhttp-gson/README.md @@ -127,7 +127,8 @@ Class | Method | HTTP request | Description *FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | *FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | *FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | -*FakeApi* | [**fakeUploadRefRequestBodies**](docs/FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake uploads an image with ref request bodies +*FakeApi* | [**fakeRefParameter**](docs/FakeApi.md#fakeRefParameter) | **POST** /fake/pet/{petId}/reference/parameter | fake reference parameter +*FakeApi* | [**fakeUploadRefRequestBodies**](docs/FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake reference parameter *FakeApi* | [**getFakeArrayofenums**](docs/FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums *FakeApi* | [**getFakeHealth**](docs/FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint *FakeApi* | [**getParameterNameMapping**](docs/FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test @@ -207,6 +208,7 @@ Class | Method | HTTP request | Description - [EquilateralTriangle](docs/EquilateralTriangle.md) - [FakeAnyOfWIthSameErasureGet200Response](docs/FakeAnyOfWIthSameErasureGet200Response.md) - [FakeOneOfWIthSameErasureGet200Response](docs/FakeOneOfWIthSameErasureGet200Response.md) + - [FakeRefParameterPetIdParameter](docs/FakeRefParameterPetIdParameter.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md) - [Foo](docs/Foo.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 07fd8fae6889..bf5b3d880975 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -1459,12 +1459,33 @@ paths: - petstore_auth: - write:pets - read:pets - summary: fake uploads an image with ref request bodies + summary: fake reference parameter tags: - fake x-content-type: multipart/form-data x-accepts: - application/json + /fake/pet/{petId}/reference/parameter: + post: + description: "" + operationId: fake-ref-parameter + parameters: + - description: to test oneOf in parameter $ref + explode: false + in: path + name: petId + required: true + schema: + $ref: '#/components/schemas/fake_ref_parameter_petId_parameter' + style: simple + responses: + "200": + description: successful operation + summary: fake reference parameter + tags: + - fake + x-accepts: + - application/json /values: get: description: "" @@ -1502,6 +1523,16 @@ paths: x-accepts: - application/json components: + parameters: + pet_id: + description: to test oneOf in parameter $ref + explode: false + in: path + name: petId + required: true + schema: + $ref: '#/components/schemas/fake_ref_parameter_petId_parameter' + style: simple requestBodies: upload_body: content: @@ -2985,6 +3016,10 @@ components: required: - requiredFile type: object + fake_ref_parameter_petId_parameter: + oneOf: + - type: string + - type: integer FreeFormObjectTestClass_properties: oneOf: - type: string diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md index 18f99688c925..eb2f76491a83 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md @@ -9,7 +9,8 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**fakeOuterCompositeSerialize**](FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | | | [**fakeOuterNumberSerialize**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | | | [**fakeOuterStringSerialize**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | | -| [**fakeUploadRefRequestBodies**](FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake uploads an image with ref request bodies | +| [**fakeRefParameter**](FakeApi.md#fakeRefParameter) | **POST** /fake/pet/{petId}/reference/parameter | fake reference parameter | +| [**fakeUploadRefRequestBodies**](FakeApi.md#fakeUploadRefRequestBodies) | **POST** /fake/pet/{petId}/uploadImage | fake reference parameter | | [**getFakeArrayofenums**](FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums | | [**getFakeHealth**](FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint | | [**getParameterNameMapping**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test | @@ -333,11 +334,72 @@ No authorization required |-------------|-------------|------------------| | **200** | Output string | - | + +# **fakeRefParameter** +> fakeRefParameter(petId) + +fake reference parameter + + + +### Example +```java +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.models.*; +import org.openapitools.client.api.FakeApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io:80/v2"); + + FakeApi apiInstance = new FakeApi(defaultClient); + FakeRefParameterPetIdParameter petId = new FakeRefParameterPetIdParameter(); // FakeRefParameterPetIdParameter | to test oneOf in parameter $ref + try { + apiInstance.fakeRefParameter(petId); + } catch (ApiException e) { + System.err.println("Exception when calling FakeApi#fakeRefParameter"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **petId** | [**FakeRefParameterPetIdParameter**](.md)| to test oneOf in parameter $ref | | + +### Return type + +null (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 | +|-------------|-------------|------------------| +| **200** | successful operation | - | + # **fakeUploadRefRequestBodies** > ModelApiResponse fakeUploadRefRequestBodies(petId, additionalMetadata, _file) -fake uploads an image with ref request bodies +fake reference parameter diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeRefParameterPetIdParameter.md b/samples/client/petstore/java/okhttp-gson/docs/FakeRefParameterPetIdParameter.md new file mode 100644 index 000000000000..1328d3c125c4 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeRefParameterPetIdParameter.md @@ -0,0 +1,12 @@ + + +# FakeRefParameterPetIdParameter + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index 431ee642f413..63cbe4695d17 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -276,6 +276,7 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.EquilateralTriangle.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeAnyOfWIthSameErasureGet200Response.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeOneOfWIthSameErasureGet200Response.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeRefParameterPetIdParameter.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FileSchemaTestClass.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Foo.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FooGetDefaultResponse.CustomTypeAdapterFactory()); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/FakeApi.java index 664a08c41d6f..68ef0840fccb 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/FakeApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/FakeApi.java @@ -29,6 +29,7 @@ import java.math.BigDecimal; import org.openapitools.client.model.Client; +import org.openapitools.client.model.FakeRefParameterPetIdParameter; import java.io.File; import org.openapitools.client.model.FileSchemaTestClass; import org.openapitools.client.model.FreeFormObjectTestClass; @@ -669,6 +670,124 @@ public okhttp3.Call fakeOuterStringSerializeAsync(String body, final ApiCallback localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); return localVarCall; } + /** + * Build call for fakeRefParameter + * @param petId to test oneOf in parameter $ref (required) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful operation -
+ */ + public okhttp3.Call fakeRefParameterCall(FakeRefParameterPetIdParameter petId, final ApiCallback _callback) throws ApiException { + String basePath = null; + // Operation Servers + String[] localBasePaths = new String[] { }; + + // Determine Base Path to Use + if (localCustomBaseUrl != null){ + basePath = localCustomBaseUrl; + } else if ( localBasePaths.length > 0 ) { + basePath = localBasePaths[localHostIndex]; + } else { + basePath = null; + } + + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/fake/pet/{petId}/reference/parameter" + .replace("{" + "petId" + "}", localVarApiClient.escapeString(petId.toString())); + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + + String[] localVarAuthNames = new String[] { }; + return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call fakeRefParameterValidateBeforeCall(FakeRefParameterPetIdParameter petId, final ApiCallback _callback) throws ApiException { + // verify the required parameter 'petId' is set + if (petId == null) { + throw new ApiException("Missing the required parameter 'petId' when calling fakeRefParameter(Async)"); + } + + return fakeRefParameterCall(petId, _callback); + + } + + /** + * fake reference parameter + * + * @param petId to test oneOf in parameter $ref (required) + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful operation -
+ */ + public void fakeRefParameter(FakeRefParameterPetIdParameter petId) throws ApiException { + fakeRefParameterWithHttpInfo(petId); + } + + /** + * fake reference parameter + * + * @param petId to test oneOf in parameter $ref (required) + * @return ApiResponse<Void> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + +
Status Code Description Response Headers
200 successful operation -
+ */ + public ApiResponse fakeRefParameterWithHttpInfo(FakeRefParameterPetIdParameter petId) throws ApiException { + okhttp3.Call localVarCall = fakeRefParameterValidateBeforeCall(petId, null); + return localVarApiClient.execute(localVarCall); + } + + /** + * fake reference parameter (asynchronously) + * + * @param petId to test oneOf in parameter $ref (required) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + +
Status Code Description Response Headers
200 successful operation -
+ */ + public okhttp3.Call fakeRefParameterAsync(FakeRefParameterPetIdParameter petId, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = fakeRefParameterValidateBeforeCall(petId, _callback); + localVarApiClient.executeAsync(localVarCall, _callback); + return localVarCall; + } /** * Build call for fakeUploadRefRequestBodies * @param petId ID of pet to update (required) @@ -749,7 +868,7 @@ private okhttp3.Call fakeUploadRefRequestBodiesValidateBeforeCall(Long petId, St } /** - * fake uploads an image with ref request bodies + * fake reference parameter * * @param petId ID of pet to update (required) * @param additionalMetadata Additional data to pass to server (optional) @@ -768,7 +887,7 @@ public ModelApiResponse fakeUploadRefRequestBodies(Long petId, String additional } /** - * fake uploads an image with ref request bodies + * fake reference parameter * * @param petId ID of pet to update (required) * @param additionalMetadata Additional data to pass to server (optional) @@ -788,7 +907,7 @@ public ApiResponse fakeUploadRefRequestBodiesWithHttpInfo(Long } /** - * fake uploads an image with ref request bodies (asynchronously) + * fake reference parameter (asynchronously) * * @param petId ID of pet to update (required) * @param additionalMetadata Additional data to pass to server (optional) diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java new file mode 100644 index 000000000000..d844f1e5e75f --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java @@ -0,0 +1,273 @@ +/* + * 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: \" \\ + * + * 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.model; + +import java.util.Objects; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.9.0-SNAPSHOT") +public class FakeRefParameterPetIdParameter extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(FakeRefParameterPetIdParameter.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!FakeRefParameterPetIdParameter.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'FakeRefParameterPetIdParameter' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterString = gson.getDelegateAdapter(this, TypeToken.get(String.class)); + final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, FakeRefParameterPetIdParameter value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `String` + if (value.getActualInstance() instanceof String) { + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `Integer` + if (value.getActualInstance() instanceof Integer) { + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, String"); + } + + @Override + public FakeRefParameterPetIdParameter read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize String + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); + } + // deserialize Integer + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + } + + if (match == 1) { + FakeRefParameterPetIdParameter ret = new FakeRefParameterPetIdParameter(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for FakeRefParameterPetIdParameter: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public FakeRefParameterPetIdParameter() { + super("oneOf", Boolean.FALSE); + } + + public FakeRefParameterPetIdParameter(Object o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("String", String.class); + schemas.put("Integer", Integer.class); + } + + @Override + public Map> getSchemas() { + return FakeRefParameterPetIdParameter.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * Integer, String + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof String) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof Integer) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException("Invalid instance type. Must be Integer, String"); + } + + /** + * Get the actual instance, which can be the following: + * Integer, String + * + * @return The actual instance (Integer, String) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `String`. If the actual instance is not `String`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `String` + * @throws ClassCastException if the instance is not `String` + */ + public String getString() throws ClassCastException { + return (String)super.getActualInstance(); + } + /** + * Get the actual instance of `Integer`. If the actual instance is not `Integer`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Integer` + * @throws ClassCastException if the instance is not `Integer` + */ + public Integer getInteger() throws ClassCastException { + return (Integer)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to FakeRefParameterPetIdParameter + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for FakeRefParameterPetIdParameter with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of FakeRefParameterPetIdParameter given an JSON string + * + * @param jsonString JSON string + * @return An instance of FakeRefParameterPetIdParameter + * @throws IOException if the JSON string is invalid with respect to FakeRefParameterPetIdParameter + */ + public static FakeRefParameterPetIdParameter fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, FakeRefParameterPetIdParameter.class); + } + + /** + * Convert an instance of FakeRefParameterPetIdParameter to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeRefParameterPetIdParameterTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeRefParameterPetIdParameterTest.java new file mode 100644 index 000000000000..5d6fca30c3e2 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FakeRefParameterPetIdParameterTest.java @@ -0,0 +1,33 @@ +/* + * 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: \" \\ + * + * 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.model; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for FakeRefParameterPetIdParameter + */ +public class FakeRefParameterPetIdParameterTest { + private final FakeRefParameterPetIdParameter model = new FakeRefParameterPetIdParameter(); + + /** + * Model tests for FakeRefParameterPetIdParameter + */ + @Test + public void testFakeRefParameterPetIdParameter() { + // TODO: test FakeRefParameterPetIdParameter + } + +} diff --git "a/\357\200\272w" "b/\357\200\272w" new file mode 100644 index 000000000000..183bd9857879 --- /dev/null +++ "b/\357\200\272w" @@ -0,0 +1,1045 @@ +openapi: 3.1.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + externalDocs: + description: API documentation for the updatePet operation + url: http://petstore.swagger.io/v2/doc/updatePet + operationId: updatePet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generate exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + tags: + - store + summary: Delete purchase order by ID + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + security: + - api_key: [] + /no_ref: + get: + operationId: response_no_ref + tags: + - fake + responses: + '200': + description: required to pass validation + content: + text/plain: + schema: + type: string + + /ref/no_ref: + get: + operationId: response_ref_to_no_ref + tags: + - fake + responses: + '200': + $ref: '#/components/responses/no_ref' + + /ref/ref: + get: + operationId: response_ref_to_ref + tags: + - fake + responses: + '200': + $ref: '#/components/responses/ref' + /ref/ref_to_parameter: + get: + operationId: ref_to_ref_parameter + tags: + - fake + responses: + '200': + $ref: '#/components/responses/ref' + parameters: + - $ref: '#/components/parameters/ref_to_uuid' + /ref/ref_to_parameter_oneof: + get: + operationId: ref_to_ref_parameter_oneof + tags: + - fake + responses: + '200': + description: Successful Response + parameters: + - $ref: '#/components/parameters/ref_to_oneof' + "/fake/api/changeowner": + post: + summary: op1 + operationId: op1 + tags: + - fake + parameters: [] + responses: + '201': + description: Successful Response + content: + application/json: + schema: {} + '422': + description: Validation Error + content: + application/json: + schema: + "$ref": "#/components/schemas/HTTPValidationError" + "/fake/api/changename": + post: + summary: op2 + operationId: op2 + tags: + - fake + parameters: [] + responses: + '201': + description: Successful Response + content: + application/json: + schema: {} + '422': + description: Validation Error + content: + application/json: + schema: + "$ref": "#/components/schemas/HTTPValidationError" + "/fake/api/query/enum": + post: + summary: op3 + operationId: op3 + tags: + - fake + parameters: + - name: query_enum + in: query + description: query enum test + required: true + schema: + type: array + items: + "$ref": "#/components/schemas/CodesEnum" + responses: + '200': + description: Successful Response + "/fake/inline/schema/anyof/path1": + get: + tags: + - fake + responses: + '200': + description: '' + content: + application/json: + schema: + anyOf: + - type: 'null' + - "$ref": "#/components/schemas/myObject" + "/fake/inline/schema/anyof/path2": + get: + tags: + - fake + responses: + '200': + description: '' + content: + application/json: + schema: + anyOf: + - "$ref": "#/components/schemas/myObject" + - type: 'null' + "/fake/inline/schema/anyof/path3": + get: + tags: + - fake + responses: + '200': + description: '' + content: + application/json: + schema: + anyOf: + - type: array + items: + "$ref": "#/components/schemas/myObject" + - type: 'null' +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + parameters: + ref_to_uuid: + description: to test ref to parameter (uuid) + name: ref_to_uuid + in: header + required: true + schema: + type: string + format: uuid + example: 61864654-6e6b-4152-a62f-795fdd606bc2 + ref_to_oneof: + description: to test ref to parameter (oneof) + name: ref_to_oneof + in: header + required: true + schema: + oneOf: + - type: string + - type: integer + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + responses: + no_ref: + description: required to pass validation + content: + text/plain: + schema: + type: string + + ref: + description: required to pass validation + content: + text/plain: + schema: + $ref: '#/components/schemas/simple_text' + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string + StringOrInt: + description: string or int + type: [string, integer] + OneOfStringOrInt: + description: string or int (onefOf) + oneOf: + - type: string + - type: integer + Dog: + allOf: + - $ref: '#/components/schemas/Animal' + - type: object + properties: + breed: + type: string + Cat: + allOf: + - $ref: '#/components/schemas/Animal' + - type: object + properties: + declawed: + type: boolean + Animal: + type: object + discriminator: + propertyName: className + required: + - className + properties: + className: + type: string + color: + type: string + default: red + simple_text: + type: string + any_type_test: + properties: + any_type_property: {} + array_prop: + type: array + description: test array in 3.1 spec + items: + type: string + ref_array_prefix_items: + $ref: '#/components/schemas/ArrayPrefixItems' + HTTPValidationError: + properties: {} + type: object + title: HTTPValidationError + # okhttp-gson doesnot support array of string + #AnyOfArray: + # anyOf: + # - type: array + # items: + # type: string + # - type: array + # items: + # type: integer + ArrayPrefixItems: + type: array + description: | + An item that was added to the queue. + minItems: 3 + maxItems: 5 + prefixItems: + - type: number + description: Queue priority. + - type: string + description: The hash id of the prompt object. This should be the the prompt ID. + - type: array + description: A list of "good output" node IDs in the prompt. + items: + type: string + circular_reference_1: + type: object + properties: + prop1: + $ref: '#/components/schemas/circular_reference_2' + circular_reference_2: + type: object + properties: + prop1: + $ref: '#/components/schemas/circular_reference_3' + circular_reference_3: + type: object + properties: + prop1: + $ref: '#/components/schemas/circular_reference_1' + array_of_same_ref: + type: object + properties: + arrayFooOne: + type: array + items: + $ref: '#/components/schemas/Tag' + arrayFooTwo: + type: array + items: + $ref: '#/components/schemas/Tag' + arrayFooThree: + type: array + items: + $ref: '#/components/schemas/Tag' + CodesEnum: + type: string + enum: + - Code 1 + - Code 2 + - Code 3 + SimpleModelWithArrayProperty: + type: object + required: + - arrayOfStrings + properties: + arrayOfStrings: + type: array + items: + type: string + AllOfSimpleModel: + allOf: + - $ref: '#/components/schemas/SimpleModelWithArrayProperty' + myObject: + type: object