mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 18:32:43 +00:00
Fix missing objects when defining inline anyOf, or oneOf (#17141)
* better handling of composed schema in inline model resolver * better handling of example
This commit is contained in:
@@ -821,8 +821,7 @@ public class InlineModelResolver {
|
||||
} else {
|
||||
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isMapSchema(property)) {
|
||||
} else if (ModelUtils.isMapSchema(property)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(property);
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
@@ -852,6 +851,15 @@ public class InlineModelResolver {
|
||||
} else {
|
||||
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
|
||||
}
|
||||
} else if (ModelUtils.isComposedSchema(property)) { // oneOf, anyOf, etc
|
||||
String propertyModelName = resolveModelName(property.getTitle(), path + "_" + key);
|
||||
gatherInlineModels(property, propertyModelName);
|
||||
propertyModelName = addSchemas(propertyModelName, property);
|
||||
Schema schema = new Schema().$ref(propertyModelName);
|
||||
schema.setRequired(property.getRequired());
|
||||
propsToUpdate.put(key, schema);
|
||||
} else {
|
||||
LOGGER.debug("Schema not yet handled in model resolver: {}", property);
|
||||
}
|
||||
}
|
||||
if (propsToUpdate.size() > 0) {
|
||||
@@ -885,8 +893,10 @@ public class InlineModelResolver {
|
||||
// including object types.
|
||||
model.setFormat(object.getFormat());
|
||||
|
||||
if (object.getExample() != null) {
|
||||
model.setExample(example);
|
||||
}
|
||||
model.setDescription(description);
|
||||
model.setExample(example);
|
||||
model.setName(object.getName());
|
||||
model.setXml(xml);
|
||||
model.setRequired(object.getRequired());
|
||||
|
||||
@@ -2493,3 +2493,10 @@ components:
|
||||
- $ref: '#/components/schemas/Tag'
|
||||
required:
|
||||
- value
|
||||
attributes:
|
||||
type: object
|
||||
properties:
|
||||
C:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/Pet'
|
||||
- $ref: '#/components/schemas/Order'
|
||||
|
||||
@@ -7,6 +7,8 @@ build.gradle
|
||||
build.sbt
|
||||
docs/AdditionalPropertiesClass.md
|
||||
docs/AllOfModelArrayAnyOf.md
|
||||
docs/AllOfModelArrayAnyOfAllOfAttributes.md
|
||||
docs/AllOfModelArrayAnyOfAllOfAttributesC.md
|
||||
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md
|
||||
docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md
|
||||
docs/Animal.md
|
||||
@@ -142,6 +144,8 @@ src/main/java/org/openapitools/client/auth/RetryingOAuth.java
|
||||
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
|
||||
src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java
|
||||
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOf.java
|
||||
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributes.java
|
||||
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java
|
||||
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1.java
|
||||
src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java
|
||||
src/main/java/org/openapitools/client/model/Animal.java
|
||||
|
||||
@@ -164,6 +164,8 @@ Class | Method | HTTP request | Description
|
||||
|
||||
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
|
||||
- [AllOfModelArrayAnyOf](docs/AllOfModelArrayAnyOf.md)
|
||||
- [AllOfModelArrayAnyOfAllOfAttributes](docs/AllOfModelArrayAnyOfAllOfAttributes.md)
|
||||
- [AllOfModelArrayAnyOfAllOfAttributesC](docs/AllOfModelArrayAnyOfAllOfAttributesC.md)
|
||||
- [AllOfModelArrayAnyOfAllOfLinkListColumn1](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1.md)
|
||||
- [AllOfModelArrayAnyOfAllOfLinkListColumn1Value](docs/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.md)
|
||||
- [Animal](docs/Animal.md)
|
||||
|
||||
@@ -2477,6 +2477,8 @@ components:
|
||||
- properties:
|
||||
linkListColumn1:
|
||||
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_linkListColumn1'
|
||||
attributes:
|
||||
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_attributes'
|
||||
type: object
|
||||
_foo_get_default_response:
|
||||
example:
|
||||
@@ -2674,7 +2676,15 @@ components:
|
||||
required:
|
||||
- value
|
||||
type: object
|
||||
example: null
|
||||
AllOfModelArrayAnyOf_allOf_attributes_C:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/Pet'
|
||||
- $ref: '#/components/schemas/Order'
|
||||
AllOfModelArrayAnyOf_allOf_attributes:
|
||||
properties:
|
||||
C:
|
||||
$ref: '#/components/schemas/AllOfModelArrayAnyOf_allOf_attributes_C'
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|**id** | **Long** | | [optional] |
|
||||
|**name** | **String** | | |
|
||||
|**linkListColumn1** | [**AllOfModelArrayAnyOfAllOfLinkListColumn1**](AllOfModelArrayAnyOfAllOfLinkListColumn1.md) | | [optional] |
|
||||
|**attributes** | [**AllOfModelArrayAnyOfAllOfAttributes**](AllOfModelArrayAnyOfAllOfAttributes.md) | | [optional] |
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
# AllOfModelArrayAnyOfAllOfAttributes
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
|------------ | ------------- | ------------- | -------------|
|
||||
|**C** | [**AllOfModelArrayAnyOfAllOfAttributesC**](AllOfModelArrayAnyOfAllOfAttributesC.md) | | [optional] |
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
# AllOfModelArrayAnyOfAllOfAttributesC
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
|------------ | ------------- | ------------- | -------------|
|
||||
|**id** | **Long** | | [optional] |
|
||||
|**category** | [**Category**](Category.md) | | [optional] |
|
||||
|**name** | **String** | | |
|
||||
|**photoUrls** | **List<String>** | | |
|
||||
|**tags** | [**List<Tag>**](Tag.md) | | [optional] |
|
||||
|**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional] |
|
||||
|**petId** | **Long** | | [optional] |
|
||||
|**quantity** | **Integer** | | [optional] |
|
||||
|**shipDate** | **OffsetDateTime** | | [optional] |
|
||||
|**complete** | **Boolean** | | [optional] |
|
||||
|
||||
|
||||
|
||||
## Enum: StatusEnum
|
||||
|
||||
| Name | Value |
|
||||
|---- | -----|
|
||||
| PLACED | "placed" |
|
||||
| APPROVED | "approved" |
|
||||
| DELIVERED | "delivered" |
|
||||
|
||||
|
||||
|
||||
@@ -231,6 +231,8 @@ public class JSON {
|
||||
gsonBuilder.registerTypeAdapter(byte[].class, byteArrayAdapter);
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesClass.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOf.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributes.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributesC.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1Value.CustomTypeAdapterFactory());
|
||||
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Apple.CustomTypeAdapterFactory());
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributes;
|
||||
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -64,6 +65,10 @@ public class AllOfModelArrayAnyOf {
|
||||
@SerializedName(SERIALIZED_NAME_LINK_LIST_COLUMN1)
|
||||
private AllOfModelArrayAnyOfAllOfLinkListColumn1 linkListColumn1;
|
||||
|
||||
public static final String SERIALIZED_NAME_ATTRIBUTES = "attributes";
|
||||
@SerializedName(SERIALIZED_NAME_ATTRIBUTES)
|
||||
private AllOfModelArrayAnyOfAllOfAttributes attributes;
|
||||
|
||||
public AllOfModelArrayAnyOf() {
|
||||
}
|
||||
|
||||
@@ -123,6 +128,25 @@ public class AllOfModelArrayAnyOf {
|
||||
this.linkListColumn1 = linkListColumn1;
|
||||
}
|
||||
|
||||
|
||||
public AllOfModelArrayAnyOf attributes(AllOfModelArrayAnyOfAllOfAttributes attributes) {
|
||||
this.attributes = attributes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes
|
||||
* @return attributes
|
||||
**/
|
||||
@javax.annotation.Nullable
|
||||
public AllOfModelArrayAnyOfAllOfAttributes getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(AllOfModelArrayAnyOfAllOfAttributes attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* A container for additional, undeclared properties.
|
||||
* This is a holder for any undeclared properties as specified with
|
||||
@@ -180,13 +204,14 @@ public class AllOfModelArrayAnyOf {
|
||||
AllOfModelArrayAnyOf allOfModelArrayAnyOf = (AllOfModelArrayAnyOf) o;
|
||||
return Objects.equals(this.id, allOfModelArrayAnyOf.id) &&
|
||||
Objects.equals(this.name, allOfModelArrayAnyOf.name) &&
|
||||
Objects.equals(this.linkListColumn1, allOfModelArrayAnyOf.linkListColumn1)&&
|
||||
Objects.equals(this.linkListColumn1, allOfModelArrayAnyOf.linkListColumn1) &&
|
||||
Objects.equals(this.attributes, allOfModelArrayAnyOf.attributes)&&
|
||||
Objects.equals(this.additionalProperties, allOfModelArrayAnyOf.additionalProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, linkListColumn1, additionalProperties);
|
||||
return Objects.hash(id, name, linkListColumn1, attributes, additionalProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -196,6 +221,7 @@ public class AllOfModelArrayAnyOf {
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" linkListColumn1: ").append(toIndentedString(linkListColumn1)).append("\n");
|
||||
sb.append(" attributes: ").append(toIndentedString(attributes)).append("\n");
|
||||
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
@@ -222,6 +248,7 @@ public class AllOfModelArrayAnyOf {
|
||||
openapiFields.add("id");
|
||||
openapiFields.add("name");
|
||||
openapiFields.add("linkListColumn1");
|
||||
openapiFields.add("attributes");
|
||||
|
||||
// a set of required properties/fields (JSON key names)
|
||||
openapiRequiredFields = new HashSet<String>();
|
||||
@@ -255,6 +282,10 @@ public class AllOfModelArrayAnyOf {
|
||||
if (jsonObj.get("linkListColumn1") != null && !jsonObj.get("linkListColumn1").isJsonNull()) {
|
||||
AllOfModelArrayAnyOfAllOfLinkListColumn1.validateJsonElement(jsonObj.get("linkListColumn1"));
|
||||
}
|
||||
// validate the optional field `attributes`
|
||||
if (jsonObj.get("attributes") != null && !jsonObj.get("attributes").isJsonNull()) {
|
||||
AllOfModelArrayAnyOfAllOfAttributes.validateJsonElement(jsonObj.get("attributes"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* 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 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 java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributesC;
|
||||
|
||||
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 com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openapitools.client.JSON;
|
||||
|
||||
/**
|
||||
* AllOfModelArrayAnyOfAllOfAttributes
|
||||
*/
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class AllOfModelArrayAnyOfAllOfAttributes {
|
||||
public static final String SERIALIZED_NAME_C = "C";
|
||||
@SerializedName(SERIALIZED_NAME_C)
|
||||
private AllOfModelArrayAnyOfAllOfAttributesC C;
|
||||
|
||||
public AllOfModelArrayAnyOfAllOfAttributes() {
|
||||
}
|
||||
|
||||
public AllOfModelArrayAnyOfAllOfAttributes C(AllOfModelArrayAnyOfAllOfAttributesC C) {
|
||||
this.C = C;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get C
|
||||
* @return C
|
||||
**/
|
||||
@javax.annotation.Nullable
|
||||
public AllOfModelArrayAnyOfAllOfAttributesC getC() {
|
||||
return C;
|
||||
}
|
||||
|
||||
public void setC(AllOfModelArrayAnyOfAllOfAttributesC C) {
|
||||
this.C = C;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param key name of the property
|
||||
* @param value value of the property
|
||||
* @return the AllOfModelArrayAnyOfAllOfAttributes instance itself
|
||||
*/
|
||||
public AllOfModelArrayAnyOfAllOfAttributes 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.
|
||||
*
|
||||
* @return a map of objects
|
||||
*/
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional (undeclared) property with the specified name.
|
||||
*
|
||||
* @param key name of the property
|
||||
* @return an object
|
||||
*/
|
||||
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;
|
||||
}
|
||||
AllOfModelArrayAnyOfAllOfAttributes allOfModelArrayAnyOfAllOfAttributes = (AllOfModelArrayAnyOfAllOfAttributes) o;
|
||||
return Objects.equals(this.C, allOfModelArrayAnyOfAllOfAttributes.C)&&
|
||||
Objects.equals(this.additionalProperties, allOfModelArrayAnyOfAllOfAttributes.additionalProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(C, additionalProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class AllOfModelArrayAnyOfAllOfAttributes {\n");
|
||||
sb.append(" C: ").append(toIndentedString(C)).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("C");
|
||||
|
||||
// a set of required properties/fields (JSON key names)
|
||||
openapiRequiredFields = new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 AllOfModelArrayAnyOfAllOfAttributes
|
||||
*/
|
||||
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
||||
if (jsonElement == null) {
|
||||
if (!AllOfModelArrayAnyOfAllOfAttributes.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
|
||||
throw new IllegalArgumentException(String.format("The required field(s) %s in AllOfModelArrayAnyOfAllOfAttributes is not found in the empty JSON string", AllOfModelArrayAnyOfAllOfAttributes.openapiRequiredFields.toString()));
|
||||
}
|
||||
}
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
// validate the optional field `C`
|
||||
if (jsonObj.get("C") != null && !jsonObj.get("C").isJsonNull()) {
|
||||
AllOfModelArrayAnyOfAllOfAttributesC.validateJsonElement(jsonObj.get("C"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
if (!AllOfModelArrayAnyOfAllOfAttributes.class.isAssignableFrom(type.getRawType())) {
|
||||
return null; // this class only serializes 'AllOfModelArrayAnyOfAllOfAttributes' and its subtypes
|
||||
}
|
||||
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
|
||||
final TypeAdapter<AllOfModelArrayAnyOfAllOfAttributes> thisAdapter
|
||||
= gson.getDelegateAdapter(this, TypeToken.get(AllOfModelArrayAnyOfAllOfAttributes.class));
|
||||
|
||||
return (TypeAdapter<T>) new TypeAdapter<AllOfModelArrayAnyOfAllOfAttributes>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, AllOfModelArrayAnyOfAllOfAttributes value) throws IOException {
|
||||
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
|
||||
obj.remove("additionalProperties");
|
||||
// serialize additional 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 AllOfModelArrayAnyOfAllOfAttributes read(JsonReader in) throws IOException {
|
||||
JsonElement jsonElement = elementAdapter.read(in);
|
||||
validateJsonElement(jsonElement);
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
// store additional fields in the deserialized instance
|
||||
AllOfModelArrayAnyOfAllOfAttributes 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 if (entry.getValue().isJsonArray()) {
|
||||
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
|
||||
} else { // JSON object
|
||||
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}.nullSafe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of AllOfModelArrayAnyOfAllOfAttributes given an JSON string
|
||||
*
|
||||
* @param jsonString JSON string
|
||||
* @return An instance of AllOfModelArrayAnyOfAllOfAttributes
|
||||
* @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfAttributes
|
||||
*/
|
||||
public static AllOfModelArrayAnyOfAllOfAttributes fromJson(String jsonString) throws IOException {
|
||||
return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfAttributes.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an instance of AllOfModelArrayAnyOfAllOfAttributes to an JSON string
|
||||
*
|
||||
* @return JSON string
|
||||
*/
|
||||
public String toJson() {
|
||||
return JSON.getGson().toJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* 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 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 java.io.IOException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.openapitools.client.model.Category;
|
||||
import org.openapitools.client.model.Order;
|
||||
import org.openapitools.client.model.Pet;
|
||||
import org.openapitools.client.model.Tag;
|
||||
|
||||
|
||||
|
||||
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")
|
||||
public class AllOfModelArrayAnyOfAllOfAttributesC extends AbstractOpenApiSchema {
|
||||
private static final Logger log = Logger.getLogger(AllOfModelArrayAnyOfAllOfAttributesC.class.getName());
|
||||
|
||||
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
if (!AllOfModelArrayAnyOfAllOfAttributesC.class.isAssignableFrom(type.getRawType())) {
|
||||
return null; // this class only serializes 'AllOfModelArrayAnyOfAllOfAttributesC' and its subtypes
|
||||
}
|
||||
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
|
||||
final TypeAdapter<Pet> adapterPet = gson.getDelegateAdapter(this, TypeToken.get(Pet.class));
|
||||
final TypeAdapter<Order> adapterOrder = gson.getDelegateAdapter(this, TypeToken.get(Order.class));
|
||||
|
||||
return (TypeAdapter<T>) new TypeAdapter<AllOfModelArrayAnyOfAllOfAttributesC>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, AllOfModelArrayAnyOfAllOfAttributesC value) throws IOException {
|
||||
if (value == null || value.getActualInstance() == null) {
|
||||
elementAdapter.write(out, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the actual instance is of the type `Pet`
|
||||
if (value.getActualInstance() instanceof Pet) {
|
||||
JsonElement element = adapterPet.toJsonTree((Pet)value.getActualInstance());
|
||||
elementAdapter.write(out, element);
|
||||
return;
|
||||
}
|
||||
// check if the actual instance is of the type `Order`
|
||||
if (value.getActualInstance() instanceof Order) {
|
||||
JsonElement element = adapterOrder.toJsonTree((Order)value.getActualInstance());
|
||||
elementAdapter.write(out, element);
|
||||
return;
|
||||
}
|
||||
throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Order, Pet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllOfModelArrayAnyOfAllOfAttributesC read(JsonReader in) throws IOException {
|
||||
Object deserialized = null;
|
||||
JsonElement jsonElement = elementAdapter.read(in);
|
||||
|
||||
int match = 0;
|
||||
ArrayList<String> errorMessages = new ArrayList<>();
|
||||
TypeAdapter actualAdapter = elementAdapter;
|
||||
|
||||
// deserialize Pet
|
||||
try {
|
||||
// validate the JSON object to see if any exception is thrown
|
||||
Pet.validateJsonElement(jsonElement);
|
||||
actualAdapter = adapterPet;
|
||||
match++;
|
||||
log.log(Level.FINER, "Input data matches schema 'Pet'");
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue
|
||||
errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage()));
|
||||
log.log(Level.FINER, "Input data does not match schema 'Pet'", e);
|
||||
}
|
||||
// deserialize Order
|
||||
try {
|
||||
// validate the JSON object to see if any exception is thrown
|
||||
Order.validateJsonElement(jsonElement);
|
||||
actualAdapter = adapterOrder;
|
||||
match++;
|
||||
log.log(Level.FINER, "Input data matches schema 'Order'");
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue
|
||||
errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage()));
|
||||
log.log(Level.FINER, "Input data does not match schema 'Order'", e);
|
||||
}
|
||||
|
||||
if (match == 1) {
|
||||
AllOfModelArrayAnyOfAllOfAttributesC ret = new AllOfModelArrayAnyOfAllOfAttributesC();
|
||||
ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement));
|
||||
return ret;
|
||||
}
|
||||
|
||||
throw new IOException(String.format("Failed deserialization for AllOfModelArrayAnyOfAllOfAttributesC: %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<String, Class<?>> schemas = new HashMap<String, Class<?>>();
|
||||
|
||||
public AllOfModelArrayAnyOfAllOfAttributesC() {
|
||||
super("oneOf", Boolean.FALSE);
|
||||
}
|
||||
|
||||
public AllOfModelArrayAnyOfAllOfAttributesC(Order o) {
|
||||
super("oneOf", Boolean.FALSE);
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
public AllOfModelArrayAnyOfAllOfAttributesC(Pet o) {
|
||||
super("oneOf", Boolean.FALSE);
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
static {
|
||||
schemas.put("Pet", Pet.class);
|
||||
schemas.put("Order", Order.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getSchemas() {
|
||||
return AllOfModelArrayAnyOfAllOfAttributesC.schemas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the instance that matches the oneOf child schema, check
|
||||
* the instance parameter is valid against the oneOf child schemas:
|
||||
* Order, Pet
|
||||
*
|
||||
* It could be an instance of the 'oneOf' schemas.
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (instance instanceof Pet) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (instance instanceof Order) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new RuntimeException("Invalid instance type. Must be Order, Pet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance, which can be the following:
|
||||
* Order, Pet
|
||||
*
|
||||
* @return The actual instance (Order, Pet)
|
||||
*/
|
||||
@Override
|
||||
public Object getActualInstance() {
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Pet`. If the actual instance is not `Pet`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Pet`
|
||||
* @throws ClassCastException if the instance is not `Pet`
|
||||
*/
|
||||
public Pet getPet() throws ClassCastException {
|
||||
return (Pet)super.getActualInstance();
|
||||
}
|
||||
/**
|
||||
* Get the actual instance of `Order`. If the actual instance is not `Order`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Order`
|
||||
* @throws ClassCastException if the instance is not `Order`
|
||||
*/
|
||||
public Order getOrder() throws ClassCastException {
|
||||
return (Order)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 AllOfModelArrayAnyOfAllOfAttributesC
|
||||
*/
|
||||
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
||||
// validate oneOf schemas one by one
|
||||
int validCount = 0;
|
||||
ArrayList<String> errorMessages = new ArrayList<>();
|
||||
// validate the json string with Pet
|
||||
try {
|
||||
Pet.validateJsonElement(jsonElement);
|
||||
validCount++;
|
||||
} catch (Exception e) {
|
||||
errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage()));
|
||||
// continue to the next one
|
||||
}
|
||||
// validate the json string with Order
|
||||
try {
|
||||
Order.validateJsonElement(jsonElement);
|
||||
validCount++;
|
||||
} catch (Exception e) {
|
||||
errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage()));
|
||||
// continue to the next one
|
||||
}
|
||||
if (validCount != 1) {
|
||||
throw new IOException(String.format("The JSON string is invalid for AllOfModelArrayAnyOfAllOfAttributesC with oneOf schemas: Order, Pet. %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 AllOfModelArrayAnyOfAllOfAttributesC given an JSON string
|
||||
*
|
||||
* @param jsonString JSON string
|
||||
* @return An instance of AllOfModelArrayAnyOfAllOfAttributesC
|
||||
* @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfAttributesC
|
||||
*/
|
||||
public static AllOfModelArrayAnyOfAllOfAttributesC fromJson(String jsonString) throws IOException {
|
||||
return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfAttributesC.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an instance of AllOfModelArrayAnyOfAllOfAttributesC to an JSON string
|
||||
*
|
||||
* @return JSON string
|
||||
*/
|
||||
public String toJson() {
|
||||
return JSON.getGson().toJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 java.io.IOException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.openapitools.client.model.Category;
|
||||
import org.openapitools.client.model.Order;
|
||||
import org.openapitools.client.model.Pet;
|
||||
import org.openapitools.client.model.Tag;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Model tests for AllOfModelArrayAnyOfAllOfAttributesC
|
||||
*/
|
||||
public class AllOfModelArrayAnyOfAllOfAttributesCTest {
|
||||
private final AllOfModelArrayAnyOfAllOfAttributesC model = new AllOfModelArrayAnyOfAllOfAttributesC();
|
||||
|
||||
/**
|
||||
* Model tests for AllOfModelArrayAnyOfAllOfAttributesC
|
||||
*/
|
||||
@Test
|
||||
public void testAllOfModelArrayAnyOfAllOfAttributesC() {
|
||||
// TODO: test AllOfModelArrayAnyOfAllOfAttributesC
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'id'
|
||||
*/
|
||||
@Test
|
||||
public void idTest() {
|
||||
// TODO: test id
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'category'
|
||||
*/
|
||||
@Test
|
||||
public void categoryTest() {
|
||||
// TODO: test category
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'name'
|
||||
*/
|
||||
@Test
|
||||
public void nameTest() {
|
||||
// TODO: test name
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'photoUrls'
|
||||
*/
|
||||
@Test
|
||||
public void photoUrlsTest() {
|
||||
// TODO: test photoUrls
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'tags'
|
||||
*/
|
||||
@Test
|
||||
public void tagsTest() {
|
||||
// TODO: test tags
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'status'
|
||||
*/
|
||||
@Test
|
||||
public void statusTest() {
|
||||
// TODO: test status
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'petId'
|
||||
*/
|
||||
@Test
|
||||
public void petIdTest() {
|
||||
// TODO: test petId
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'quantity'
|
||||
*/
|
||||
@Test
|
||||
public void quantityTest() {
|
||||
// TODO: test quantity
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'shipDate'
|
||||
*/
|
||||
@Test
|
||||
public void shipDateTest() {
|
||||
// TODO: test shipDate
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'complete'
|
||||
*/
|
||||
@Test
|
||||
public void completeTest() {
|
||||
// TODO: test complete
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import org.openapitools.client.model.AllOfModelArrayAnyOfAllOfAttributesC;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Model tests for AllOfModelArrayAnyOfAllOfAttributes
|
||||
*/
|
||||
public class AllOfModelArrayAnyOfAllOfAttributesTest {
|
||||
private final AllOfModelArrayAnyOfAllOfAttributes model = new AllOfModelArrayAnyOfAllOfAttributes();
|
||||
|
||||
/**
|
||||
* Model tests for AllOfModelArrayAnyOfAllOfAttributes
|
||||
*/
|
||||
@Test
|
||||
public void testAllOfModelArrayAnyOfAllOfAttributes() {
|
||||
// TODO: test AllOfModelArrayAnyOfAllOfAttributes
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property 'C'
|
||||
*/
|
||||
@Test
|
||||
public void CTest() {
|
||||
// TODO: test C
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user