[Inline model resolver] better handling of inline responses and bug fixes (#12353)

* better handling of inline response schemas, bug fixes

* update samples

* add new files

* better code format

* remove unused ruby files

* fix java test

* remove unused js spec files

* remove inline_response_default_test.dart

* fix webclient tests

* fix spring tests
This commit is contained in:
William Cheng
2022-05-13 10:17:59 +08:00
committed by GitHub
parent 2cf3d3805f
commit 12cdacabbf
284 changed files with 7620 additions and 1220 deletions

View File

@@ -40,6 +40,7 @@ docs/FakeApi.md
docs/FakeClassnameTags123Api.md
docs/FileSchemaTestClass.md
docs/Foo.md
docs/FooGetDefaultResponse.md
docs/FormatTest.md
docs/Fruit.md
docs/FruitReq.md
@@ -47,7 +48,6 @@ docs/GmFruit.md
docs/GrandparentAnimal.md
docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md
docs/InlineResponseDefault.md
docs/IsoscelesTriangle.md
docs/Mammal.md
docs/MapTest.md
@@ -159,6 +159,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/FileSchemaTestClass.java
src/main/java/org/openapitools/client/model/Foo.java
src/main/java/org/openapitools/client/model/FooGetDefaultResponse.java
src/main/java/org/openapitools/client/model/FormatTest.java
src/main/java/org/openapitools/client/model/Fruit.java
src/main/java/org/openapitools/client/model/FruitReq.java
@@ -166,7 +167,6 @@ src/main/java/org/openapitools/client/model/GmFruit.java
src/main/java/org/openapitools/client/model/GrandparentAnimal.java
src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java
src/main/java/org/openapitools/client/model/HealthCheckResult.java
src/main/java/org/openapitools/client/model/InlineResponseDefault.java
src/main/java/org/openapitools/client/model/IsoscelesTriangle.java
src/main/java/org/openapitools/client/model/Mammal.java
src/main/java/org/openapitools/client/model/MapTest.java

View File

@@ -187,6 +187,7 @@ Class | Method | HTTP request | Description
- [EquilateralTriangle](docs/EquilateralTriangle.md)
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [Foo](docs/Foo.md)
- [FooGetDefaultResponse](docs/FooGetDefaultResponse.md)
- [FormatTest](docs/FormatTest.md)
- [Fruit](docs/Fruit.md)
- [FruitReq](docs/FruitReq.md)
@@ -194,7 +195,6 @@ Class | Method | HTTP request | Description
- [GrandparentAnimal](docs/GrandparentAnimal.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [HealthCheckResult](docs/HealthCheckResult.md)
- [InlineResponseDefault](docs/InlineResponseDefault.md)
- [IsoscelesTriangle](docs/IsoscelesTriangle.md)
- [Mammal](docs/Mammal.md)
- [MapTest](docs/MapTest.md)

View File

@@ -48,7 +48,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/inline_response_default'
$ref: '#/components/schemas/_foo_get_default_response'
description: response
x-accepts: application/json
/pet:
@@ -2186,7 +2186,7 @@ components:
required:
- name
type: object
inline_response_default:
_foo_get_default_response:
example:
string:
bar: bar

View File

@@ -9,7 +9,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
<a name="fooGet"></a>
# **fooGet**
> InlineResponseDefault fooGet()
> FooGetDefaultResponse fooGet()
@@ -29,7 +29,7 @@ public class Example {
DefaultApi apiInstance = new DefaultApi(defaultClient);
try {
InlineResponseDefault result = apiInstance.fooGet();
FooGetDefaultResponse result = apiInstance.fooGet();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#fooGet");
@@ -47,7 +47,7 @@ This endpoint does not need any parameter.
### Return type
[**InlineResponseDefault**](InlineResponseDefault.md)
[**FooGetDefaultResponse**](FooGetDefaultResponse.md)
### Authorization

View File

@@ -0,0 +1,13 @@
# FooGetDefaultResponse
## Properties
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**string** | [**Foo**](Foo.md) | | [optional] |

View File

@@ -249,13 +249,13 @@ public class JSON {
.registerTypeAdapterFactory(new org.openapitools.client.model.EquilateralTriangle.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FileSchemaTestClass.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Foo.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FooGetDefaultResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FormatTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Fruit.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FruitReq.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.GmFruit.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.HasOnlyReadOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.HealthCheckResult.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.InlineResponseDefault.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.IsoscelesTriangle.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Mammal.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.MapTest.CustomTypeAdapterFactory())

View File

@@ -27,7 +27,7 @@ import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import org.openapitools.client.model.InlineResponseDefault;
import org.openapitools.client.model.FooGetDefaultResponse;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -141,7 +141,7 @@ public class DefaultApi {
/**
*
*
* @return InlineResponseDefault
* @return FooGetDefaultResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
@@ -149,15 +149,15 @@ public class DefaultApi {
<tr><td> 0 </td><td> response </td><td> - </td></tr>
</table>
*/
public InlineResponseDefault fooGet() throws ApiException {
ApiResponse<InlineResponseDefault> localVarResp = fooGetWithHttpInfo();
public FooGetDefaultResponse fooGet() throws ApiException {
ApiResponse<FooGetDefaultResponse> localVarResp = fooGetWithHttpInfo();
return localVarResp.getData();
}
/**
*
*
* @return ApiResponse&lt;InlineResponseDefault&gt;
* @return ApiResponse&lt;FooGetDefaultResponse&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
@@ -165,9 +165,9 @@ public class DefaultApi {
<tr><td> 0 </td><td> response </td><td> - </td></tr>
</table>
*/
public ApiResponse<InlineResponseDefault> fooGetWithHttpInfo() throws ApiException {
public ApiResponse<FooGetDefaultResponse> fooGetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = fooGetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<InlineResponseDefault>(){}.getType();
Type localVarReturnType = new TypeToken<FooGetDefaultResponse>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
@@ -183,10 +183,10 @@ public class DefaultApi {
<tr><td> 0 </td><td> response </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fooGetAsync(final ApiCallback<InlineResponseDefault> _callback) throws ApiException {
public okhttp3.Call fooGetAsync(final ApiCallback<FooGetDefaultResponse> _callback) throws ApiException {
okhttp3.Call localVarCall = fooGetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<InlineResponseDefault>(){}.getType();
Type localVarReturnType = new TypeToken<FooGetDefaultResponse>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}

View File

@@ -0,0 +1,275 @@
/*
* 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.util.Arrays;
import com.google.gson.TypeAdapter;
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import org.openapitools.client.model.Foo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* FooGetDefaultResponse
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class FooGetDefaultResponse {
public static final String SERIALIZED_NAME_STRING = "string";
@SerializedName(SERIALIZED_NAME_STRING)
private Foo string;
public FooGetDefaultResponse() {
}
public FooGetDefaultResponse string(Foo string) {
this.string = string;
return this;
}
/**
* Get string
* @return string
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
public Foo getString() {
return string;
}
public void setString(Foo string) {
this.string = string;
}
/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, Object> additionalProperties;
/**
* Set the additional (undeclared) property with the specified name and value.
* If the property does not already exist, create it otherwise replace it.
*/
public FooGetDefaultResponse putAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}
/**
* Return the additional (undeclared) property.
*/
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
/**
* Return the additional (undeclared) property with the specified name.
*/
public Object getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FooGetDefaultResponse fooGetDefaultResponse = (FooGetDefaultResponse) o;
return Objects.equals(this.string, fooGetDefaultResponse.string)&&
Objects.equals(this.additionalProperties, fooGetDefaultResponse.additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(string, additionalProperties);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class FooGetDefaultResponse {\n");
sb.append(" string: ").append(toIndentedString(string)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet<String> openapiFields;
public static HashSet<String> openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet<String>();
openapiFields.add("string");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
}
/**
* Validates the JSON Object and throws an exception if issues found
*
* @param jsonObj JSON Object
* @throws IOException if the JSON Object is invalid with respect to FooGetDefaultResponse
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (FooGetDefaultResponse.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
throw new IllegalArgumentException(String.format("The required field(s) %s in FooGetDefaultResponse is not found in the empty JSON string", FooGetDefaultResponse.openapiRequiredFields.toString()));
}
}
// validate the optional field `string`
if (jsonObj.getAsJsonObject("string") != null) {
Foo.validateJsonObject(jsonObj.getAsJsonObject("string"));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!FooGetDefaultResponse.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'FooGetDefaultResponse' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<FooGetDefaultResponse> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(FooGetDefaultResponse.class));
return (TypeAdapter<T>) new TypeAdapter<FooGetDefaultResponse>() {
@Override
public void write(JsonWriter out, FooGetDefaultResponse value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
obj.remove("additionalProperties");
// serialize additonal properties
if (value.getAdditionalProperties() != null) {
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(entry.getKey(), (Character) entry.getValue());
else {
obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject());
}
}
}
elementAdapter.write(out, obj);
}
@Override
public FooGetDefaultResponse read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
// store additional fields in the deserialized instance
FooGetDefaultResponse instance = thisAdapter.fromJsonTree(jsonObj);
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
if (!openapiFields.contains(entry.getKey())) {
if (entry.getValue().isJsonPrimitive()) { // primitive type
if (entry.getValue().getAsJsonPrimitive().isString())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
else if (entry.getValue().getAsJsonPrimitive().isNumber())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
else
throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
} else { // non-primitive type
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
}
}
}
return instance;
}
}.nullSafe();
}
}
/**
* Create an instance of FooGetDefaultResponse given an JSON string
*
* @param jsonString JSON string
* @return An instance of FooGetDefaultResponse
* @throws IOException if the JSON string is invalid with respect to FooGetDefaultResponse
*/
public static FooGetDefaultResponse fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, FooGetDefaultResponse.class);
}
/**
* Convert an instance of FooGetDefaultResponse to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -14,9 +14,9 @@
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.InlineResponseDefault;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.FooGetDefaultResponse;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
@@ -31,19 +31,13 @@ public class DefaultApiTest {
private final DefaultApi api = new DefaultApi();
/**
*
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void fooGetTest() throws ApiException {
InlineResponseDefault response = api.fooGet();
FooGetDefaultResponse response = api.fooGet();
// TODO: test validations
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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 com.google.gson.TypeAdapter;
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import org.openapitools.client.model.Foo;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for FooGetDefaultResponse
*/
public class FooGetDefaultResponseTest {
private final FooGetDefaultResponse model = new FooGetDefaultResponse();
/**
* Model tests for FooGetDefaultResponse
*/
@Test
public void testFooGetDefaultResponse() {
// TODO: test FooGetDefaultResponse
}
/**
* Test the property 'string'
*/
@Test
public void stringTest() {
// TODO: test string
}
}