[Inline model resolver] various improvements (#12293)

* better handling of requestbody in the inline resolver

* remove commented code

* better request body naming

* fix unique naming

* minor code format change

* removed additional underscore from names, fix test

* more fixes, update tests

* fix all tests

* undo changes to default codegen

* update samples

* update python tests

* add new files

* update samples
This commit is contained in:
William Cheng
2022-05-10 17:13:57 +08:00
committed by GitHub
parent 4d0da694ba
commit ad3b5f7045
186 changed files with 9764 additions and 8111 deletions

View File

@@ -12,7 +12,7 @@ docs/Apple.md
docs/AppleReq.md
docs/ArrayOfArrayOfNumberOnly.md
docs/ArrayOfInlineAllOf.md
docs/ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1.md
docs/ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.md
docs/ArrayOfNumberOnly.md
docs/ArrayTest.md
docs/Banana.md
@@ -133,7 +133,7 @@ src/main/java/org/openapitools/client/model/Apple.java
src/main/java/org/openapitools/client/model/AppleReq.java
src/main/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnly.java
src/main/java/org/openapitools/client/model/ArrayOfInlineAllOf.java
src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1.java
src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.java
src/main/java/org/openapitools/client/model/ArrayOfNumberOnly.java
src/main/java/org/openapitools/client/model/ArrayTest.java
src/main/java/org/openapitools/client/model/Banana.java

View File

@@ -162,7 +162,7 @@ Class | Method | HTTP request | Description
- [AppleReq](docs/AppleReq.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfInlineAllOf](docs/ArrayOfInlineAllOf.md)
- [ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1](docs/ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1.md)
- [ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf](docs/ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Banana](docs/Banana.md)

View File

@@ -262,18 +262,10 @@ paths:
type: integer
style: simple
requestBody:
$ref: '#/components/requestBodies/inline_object'
content:
application/x-www-form-urlencoded:
schema:
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
type: object
$ref: '#/components/schemas/updatePetWithForm_request'
responses:
"405":
description: Invalid input
@@ -301,19 +293,10 @@ paths:
type: integer
style: simple
requestBody:
$ref: '#/components/requestBodies/inline_object_1'
content:
multipart/form-data:
schema:
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
type: object
$ref: '#/components/schemas/uploadFile_request'
responses:
"200":
content:
@@ -794,29 +777,10 @@ paths:
type: number
style: form
requestBody:
$ref: '#/components/requestBodies/inline_object_2'
content:
application/x-www-form-urlencoded:
schema:
properties:
enum_form_string_array:
description: Form parameter enum test (string array)
items:
default: $
enum:
- '>'
- $
type: string
type: array
enum_form_string:
default: -efg
description: Form parameter enum test (string)
enum:
- _abc
- -efg
- (xyz)
type: string
type: object
$ref: '#/components/schemas/testEnumParameters_request'
responses:
"400":
description: Invalid request
@@ -852,83 +816,10 @@ paths:
가짜 엔드 포인트
operationId: testEndpointParameters
requestBody:
$ref: '#/components/requestBodies/inline_object_3'
content:
application/x-www-form-urlencoded:
schema:
properties:
integer:
description: None
maximum: 100
minimum: 10
type: integer
int32:
description: None
format: int32
maximum: 200
minimum: 20
type: integer
int64:
description: None
format: int64
type: integer
number:
description: None
maximum: 543.2
minimum: 32.1
type: number
float:
description: None
format: float
maximum: 987.6
type: number
double:
description: None
format: double
maximum: 123.4
minimum: 67.8
type: number
string:
description: None
pattern: "/[a-z]/i"
type: string
pattern_without_delimiter:
description: None
pattern: "^[A-Z].*"
type: string
byte:
description: None
format: byte
type: string
binary:
description: None
format: binary
type: string
date:
description: None
format: date
type: string
dateTime:
default: 2010-02-01T10:20:10.11111+01:00
description: None
example: 2020-02-02T20:20:20.22222Z
format: date-time
type: string
password:
description: None
format: password
maxLength: 64
minLength: 10
type: string
callback:
description: None
type: string
required:
- byte
- double
- number
- pattern_without_delimiter
type: object
$ref: '#/components/schemas/testEndpointParameters_request'
responses:
"400":
description: Invalid username supplied
@@ -1034,21 +925,10 @@ paths:
description: ""
operationId: testJsonFormData
requestBody:
$ref: '#/components/requestBodies/inline_object_4'
content:
application/x-www-form-urlencoded:
schema:
properties:
param:
description: field1
type: string
param2:
description: field2
type: string
required:
- param
- param2
type: object
$ref: '#/components/schemas/testJsonFormData_request'
responses:
"200":
description: successful operation
@@ -1209,21 +1089,10 @@ paths:
type: integer
style: simple
requestBody:
$ref: '#/components/requestBodies/inline_object_5'
content:
multipart/form-data:
schema:
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
requiredFile:
description: file to upload
format: binary
type: string
required:
- requiredFile
type: object
$ref: '#/components/schemas/uploadFileWithRequiredFile_request'
responses:
"200":
content:
@@ -1302,36 +1171,6 @@ components:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
inline_object:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/inline_object'
inline_object_1:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/inline_object_1'
inline_object_2:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/inline_object_2'
inline_object_3:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/inline_object_3'
inline_object_4:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/inline_object_4'
inline_object_5:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/inline_object_5'
schemas:
Foo:
example:
@@ -2344,7 +2183,7 @@ components:
items:
allOf:
- $ref: '#/components/schemas/Dog_allOf'
- $ref: '#/components/schemas/ArrayOfInlineAllOf_array_allof_dog_propertyItems_allOf_1'
- $ref: '#/components/schemas/ArrayOfInlineAllOf_array_allof_dog_property_inner_allOf'
type: array
required:
- name
@@ -2357,7 +2196,7 @@ components:
string:
$ref: '#/components/schemas/Foo'
type: object
inline_object:
updatePetWithForm_request:
properties:
name:
description: Updated name of the pet
@@ -2366,7 +2205,7 @@ components:
description: Updated status of the pet
type: string
type: object
inline_object_1:
uploadFile_request:
properties:
additionalMetadata:
description: Additional data to pass to server
@@ -2376,7 +2215,7 @@ components:
format: binary
type: string
type: object
inline_object_2:
testEnumParameters_request:
properties:
enum_form_string_array:
description: Form parameter enum test (string array)
@@ -2396,7 +2235,7 @@ components:
- (xyz)
type: string
type: object
inline_object_3:
testEndpointParameters_request:
properties:
integer:
description: None
@@ -2470,7 +2309,7 @@ components:
- number
- pattern_without_delimiter
type: object
inline_object_4:
testJsonFormData_request:
properties:
param:
description: field1
@@ -2482,7 +2321,7 @@ components:
- param
- param2
type: object
inline_object_5:
uploadFileWithRequiredFile_request:
properties:
additionalMetadata:
description: Additional data to pass to server
@@ -2504,7 +2343,7 @@ components:
declawed:
type: boolean
type: object
ArrayOfInlineAllOf_array_allof_dog_propertyItems_allOf_1:
ArrayOfInlineAllOf_array_allof_dog_property_inner_allOf:
properties:
color:
type: string

View File

@@ -0,0 +1,13 @@
# ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
## Properties
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**color** | **String** | | [optional] |

View File

@@ -225,7 +225,7 @@ public class JSON {
.registerTypeAdapterFactory(new org.openapitools.client.model.AppleReq.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfArrayOfNumberOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfInlineAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfNumberOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Banana.CustomTypeAdapterFactory())

View File

@@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyItemsAllOf1;
import org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf;
import org.openapitools.client.model.DogAllOf;
import com.google.gson.Gson;

View File

@@ -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.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 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;
/**
* ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf {
public static final String SERIALIZED_NAME_COLOR = "color";
@SerializedName(SERIALIZED_NAME_COLOR)
private String color;
public ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf() {
}
public ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf color(String color) {
this.color = color;
return this;
}
/**
* Get color
* @return color
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
/**
* 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 ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf 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;
}
ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf arrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf = (ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf) o;
return Objects.equals(this.color, arrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.color)&&
Objects.equals(this.additionalProperties, arrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(color, additionalProperties);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf {\n");
sb.append(" color: ").append(toIndentedString(color)).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("color");
// 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 ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf is not found in the empty JSON string", ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.openapiRequiredFields.toString()));
}
}
if (jsonObj.get("color") != null && !jsonObj.get("color").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `color` to be a primitive type in the JSON string but got `%s`", jsonObj.get("color").toString()));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.class));
return (TypeAdapter<T>) new TypeAdapter<ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf>() {
@Override
public void write(JsonWriter out, ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf 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 ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
// store additional fields in the deserialized instance
ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf 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 ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf given an JSON string
*
* @param jsonString JSON string
* @return An instance of ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
* @throws IOException if the JSON string is invalid with respect to ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
*/
public static ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf.class);
}
/**
* Convert an instance of ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
*/
public class ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOfTest {
private final ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf model = new ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf();
/**
* Model tests for ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
*/
@Test
public void testArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf() {
// TODO: test ArrayOfInlineAllOfArrayAllofDogPropertyInnerAllOf
}
/**
* Test the property 'color'
*/
@Test
public void colorTest() {
// TODO: test color
}
}