[java][Okhttp] replace okhttp-gson with okhttp-gson-nextgen (#11538)

* replace okhttp-gson with okhttp-gson-nextgen

* add new files

* update doc

* clean up pom

* update test

* restore error handling in doc

* add back changes

* uncomment tests

* update samples
This commit is contained in:
William Cheng
2022-02-08 00:05:44 +08:00
committed by GitHub
parent 949b4e2008
commit 51800471fa
598 changed files with 18766 additions and 42285 deletions

View File

@@ -94,6 +94,7 @@ src/main/java/org/openapitools/client/auth/OAuth.java
src/main/java/org/openapitools/client/auth/OAuthFlow.java
src/main/java/org/openapitools/client/auth/OAuthOkHttpClient.java
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/AdditionalPropertiesAnyType.java
src/main/java/org/openapitools/client/model/AdditionalPropertiesArray.java
src/main/java/org/openapitools/client/model/AdditionalPropertiesBoolean.java

View File

@@ -311,6 +311,16 @@
<artifactId>jackson-databind-nullable</artifactId>
<version>${jackson-databind-nullable-version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@@ -1169,6 +1169,7 @@ public class ApiClient {
/**
* Build HTTP call with the given options.
*
* @param baseUrl The base URL
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
@@ -1191,6 +1192,7 @@ public class ApiClient {
/**
* Build an HTTP request with the given options.
*
* @param baseUrl The base URL
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
@@ -1259,6 +1261,7 @@ public class ApiClient {
/**
* Build full URL by concatenating base path, the given sub path and query parameters.
*
* @param baseUrl The base URL
* @param path The sub path
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
@@ -1353,6 +1356,7 @@ public class ApiClient {
* @param payload HTTP request body
* @param method HTTP method
* @param uri URI
* @throws org.openapitools.client.ApiException If fails to update the parameters
*/
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams,
Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException {

View File

@@ -16,6 +16,8 @@ package org.openapitools.client;
import java.util.Map;
import java.util.List;
import javax.ws.rs.core.GenericType;
/**
* <p>ApiException class.</p>
*/
@@ -25,6 +27,8 @@ public class ApiException extends Exception {
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
private Object errorObject = null;
private GenericType errorObjectType = null;
/**
* <p>Constructor for ApiException.</p>
@@ -151,4 +155,40 @@ public class ApiException extends Exception {
public String getResponseBody() {
return responseBody;
}
/**
* Get the error object type.
*
* @return Error object type
*/
public GenericType getErrorObjectType() {
return errorObjectType;
}
/**
* Set the error object type.
*
* @param errorObjectType object type
*/
public void setErrorObjectType(GenericType errorObjectType) {
this.errorObjectType = errorObjectType;
}
/**
* Get the error object.
*
* @return Error object
*/
public Object getErrorObject() {
return errorObject;
}
/**
* Get the error object.
*
* @param errorObject Error object
*/
public void setErrorObject(Object errorObject) {
this.errorObject = errorObject;
}
}

View File

@@ -27,7 +27,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.openapitools.client.model.*;
import okio.ByteString;
import java.io.IOException;
@@ -41,54 +40,60 @@ import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
/*
* A JSON utility class
*
* NOTE: in the future, this class may be converted to static, which may break
* backward-compatibility
*/
public class JSON {
private Gson gson;
private boolean isLenientOnJson = false;
private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
private ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();
private static Gson gson;
private static boolean isLenientOnJson = false;
private static DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
private static SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private static OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();
@SuppressWarnings("unchecked")
public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
.registerTypeSelector(Animal.class, new TypeSelector<Animal>() {
.registerTypeSelector(org.openapitools.client.model.Animal.class, new TypeSelector<org.openapitools.client.model.Animal>() {
@Override
public Class<? extends Animal> getClassForElement(JsonElement readElement) {
public Class<? extends org.openapitools.client.model.Animal> getClassForElement(JsonElement readElement) {
Map<String, Class> classByDiscriminatorValue = new HashMap<String, Class>();
classByDiscriminatorValue.put("BigCat", BigCat.class);
classByDiscriminatorValue.put("Cat", Cat.class);
classByDiscriminatorValue.put("Dog", Dog.class);
classByDiscriminatorValue.put("Animal", Animal.class);
classByDiscriminatorValue.put("BigCat", org.openapitools.client.model.BigCat.class);
classByDiscriminatorValue.put("Cat", org.openapitools.client.model.Cat.class);
classByDiscriminatorValue.put("Dog", org.openapitools.client.model.Dog.class);
classByDiscriminatorValue.put("Animal", org.openapitools.client.model.Animal.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "className"));
}
})
.registerTypeSelector(BigCat.class, new TypeSelector<BigCat>() {
.registerTypeSelector(org.openapitools.client.model.BigCat.class, new TypeSelector<org.openapitools.client.model.BigCat>() {
@Override
public Class<? extends BigCat> getClassForElement(JsonElement readElement) {
public Class<? extends org.openapitools.client.model.BigCat> getClassForElement(JsonElement readElement) {
Map<String, Class> classByDiscriminatorValue = new HashMap<String, Class>();
classByDiscriminatorValue.put("BigCat", BigCat.class);
classByDiscriminatorValue.put("BigCat", org.openapitools.client.model.BigCat.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "className"));
}
})
.registerTypeSelector(Cat.class, new TypeSelector<Cat>() {
.registerTypeSelector(org.openapitools.client.model.Cat.class, new TypeSelector<org.openapitools.client.model.Cat>() {
@Override
public Class<? extends Cat> getClassForElement(JsonElement readElement) {
public Class<? extends org.openapitools.client.model.Cat> getClassForElement(JsonElement readElement) {
Map<String, Class> classByDiscriminatorValue = new HashMap<String, Class>();
classByDiscriminatorValue.put("BigCat", BigCat.class);
classByDiscriminatorValue.put("Cat", Cat.class);
classByDiscriminatorValue.put("BigCat", org.openapitools.client.model.BigCat.class);
classByDiscriminatorValue.put("Cat", org.openapitools.client.model.Cat.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "className"));
}
})
.registerTypeSelector(Dog.class, new TypeSelector<Dog>() {
.registerTypeSelector(org.openapitools.client.model.Dog.class, new TypeSelector<org.openapitools.client.model.Dog>() {
@Override
public Class<? extends Dog> getClassForElement(JsonElement readElement) {
public Class<? extends org.openapitools.client.model.Dog> getClassForElement(JsonElement readElement) {
Map<String, Class> classByDiscriminatorValue = new HashMap<String, Class>();
classByDiscriminatorValue.put("Dog", Dog.class);
classByDiscriminatorValue.put("Dog", org.openapitools.client.model.Dog.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "className"));
}
@@ -121,13 +126,57 @@ public class JSON {
return clazz;
}
public JSON() {
{
gson = createGson()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
.registerTypeAdapter(byte[].class, byteArrayAdapter)
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesAnyType.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesArray.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesBoolean.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesClass.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesInteger.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesNumber.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesObject.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.AdditionalPropertiesString.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfArrayOfNumberOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfNumberOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.BigCat.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.BigCatAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Capitalization.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.CatAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Category.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ClassModel.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Client.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Dog.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.DogAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.EnumArrays.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.EnumTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FileSchemaTestClass.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.FormatTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.HasOnlyReadOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.MapTest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.MixedPropertiesAndAdditionalPropertiesClass.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Model200Response.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ModelApiResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ModelFile.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ModelList.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ModelReturn.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Name.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.NumberOnly.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Order.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.OuterComposite.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Pet.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.ReadOnlyFirst.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.SpecialModelName.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.Tag.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.TypeHolderDefault.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.TypeHolderExample.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.User.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new org.openapitools.client.model.XmlItem.CustomTypeAdapterFactory())
.create();
}
@@ -136,7 +185,7 @@ public class JSON {
*
* @return Gson
*/
public Gson getGson() {
public static Gson getGson() {
return gson;
}
@@ -144,23 +193,13 @@ public class JSON {
* Set Gson.
*
* @param gson Gson
* @return JSON
*/
public JSON setGson(Gson gson) {
this.gson = gson;
return this;
public static void setGson(Gson gson) {
JSON.gson = gson;
}
/**
* Configure the parser to be liberal in what it accepts.
*
* @param lenientOnJson Set it to true to ignore some syntax errors
* @return JSON
* @see <a href="https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html">https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html</a>
*/
public JSON setLenientOnJson(boolean lenientOnJson) {
public static void setLenientOnJson(boolean lenientOnJson) {
isLenientOnJson = lenientOnJson;
return this;
}
/**
@@ -169,7 +208,7 @@ public class JSON {
* @param obj Object
* @return String representation of the JSON
*/
public String serialize(Object obj) {
public static String serialize(Object obj) {
return gson.toJson(obj);
}
@@ -182,11 +221,11 @@ public class JSON {
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
public static <T> T deserialize(String body, Type returnType) {
try {
if (isLenientOnJson) {
JsonReader jsonReader = new JsonReader(new StringReader(body));
// see https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
@@ -206,7 +245,7 @@ public class JSON {
/**
* Gson TypeAdapter for Byte Array type
*/
public class ByteArrayAdapter extends TypeAdapter<byte[]> {
public static class ByteArrayAdapter extends TypeAdapter<byte[]> {
@Override
public void write(JsonWriter out, byte[] value) throws IOException {
@@ -278,7 +317,7 @@ public class JSON {
/**
* Gson TypeAdapter for JSR310 LocalDate type
*/
public class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
public static class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
private DateTimeFormatter formatter;
@@ -316,14 +355,12 @@ public class JSON {
}
}
public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
public static void setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
offsetDateTimeTypeAdapter.setFormat(dateFormat);
return this;
}
public JSON setLocalDateFormat(DateTimeFormatter dateFormat) {
public static void setLocalDateFormat(DateTimeFormatter dateFormat) {
localDateTypeAdapter.setFormat(dateFormat);
return this;
}
/**
@@ -437,14 +474,11 @@ public class JSON {
}
}
public JSON setDateFormat(DateFormat dateFormat) {
public static void setDateFormat(DateFormat dateFormat) {
dateTypeAdapter.setFormat(dateFormat);
return this;
}
public JSON setSqlDateFormat(DateFormat dateFormat) {
public static void setSqlDateFormat(DateFormat dateFormat) {
sqlDateTypeAdapter.setFormat(dateFormat);
return this;
}
}

View File

@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class AnotherFakeApi {
private ApiClient localVarApiClient;
@@ -89,7 +90,6 @@ public class AnotherFakeApi {
*/
public okhttp3.Call call123testSpecialTagsCall(Client body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -186,8 +186,14 @@ public class AnotherFakeApi {
*/
public ApiResponse<Client> call123testSpecialTagsWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = call123testSpecialTagsValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
}
/**

View File

@@ -45,6 +45,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class FakeApi {
private ApiClient localVarApiClient;
@@ -97,7 +98,6 @@ public class FakeApi {
*/
public okhttp3.Call createXmlItemCall(XmlItem xmlItem, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -228,7 +228,6 @@ public class FakeApi {
*/
public okhttp3.Call fakeOuterBooleanSerializeCall(Boolean body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -320,8 +319,14 @@ public class FakeApi {
*/
public ApiResponse<Boolean> fakeOuterBooleanSerializeWithHttpInfo(Boolean body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterBooleanSerializeValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<Boolean>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Boolean>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Boolean>(){}.getType()));
e.setErrorObjectType(new GenericType<Boolean>(){});
throw e;
}
}
/**
@@ -358,7 +363,6 @@ public class FakeApi {
*/
public okhttp3.Call fakeOuterCompositeSerializeCall(OuterComposite body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -450,8 +454,14 @@ public class FakeApi {
*/
public ApiResponse<OuterComposite> fakeOuterCompositeSerializeWithHttpInfo(OuterComposite body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterCompositeSerializeValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<OuterComposite>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<OuterComposite>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<OuterComposite>(){}.getType()));
e.setErrorObjectType(new GenericType<OuterComposite>(){});
throw e;
}
}
/**
@@ -488,7 +498,6 @@ public class FakeApi {
*/
public okhttp3.Call fakeOuterNumberSerializeCall(BigDecimal body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -580,8 +589,14 @@ public class FakeApi {
*/
public ApiResponse<BigDecimal> fakeOuterNumberSerializeWithHttpInfo(BigDecimal body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterNumberSerializeValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<BigDecimal>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<BigDecimal>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<BigDecimal>(){}.getType()));
e.setErrorObjectType(new GenericType<BigDecimal>(){});
throw e;
}
}
/**
@@ -618,7 +633,6 @@ public class FakeApi {
*/
public okhttp3.Call fakeOuterStringSerializeCall(String body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -710,8 +724,14 @@ public class FakeApi {
*/
public ApiResponse<String> fakeOuterStringSerializeWithHttpInfo(String body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterStringSerializeValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<String>(){}.getType()));
e.setErrorObjectType(new GenericType<String>(){});
throw e;
}
}
/**
@@ -748,7 +768,6 @@ public class FakeApi {
*/
public okhttp3.Call testBodyWithFileSchemaCall(FileSchemaTestClass body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -880,7 +899,6 @@ public class FakeApi {
*/
public okhttp3.Call testBodyWithQueryParamsCall(String query, User body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1020,7 +1038,6 @@ public class FakeApi {
*/
public okhttp3.Call testClientModelCall(Client body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1117,8 +1134,14 @@ public class FakeApi {
*/
public ApiResponse<Client> testClientModelWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = testClientModelValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
}
/**
@@ -1169,7 +1192,6 @@ public class FakeApi {
*/
public okhttp3.Call testEndpointParametersCall(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, File binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1421,7 +1443,6 @@ public class FakeApi {
*/
public okhttp3.Call testEnumParametersCall(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1573,7 +1594,6 @@ public class FakeApi {
}
private okhttp3.Call testGroupParametersCall(Integer requiredStringGroup, Boolean requiredBooleanGroup, Long requiredInt64Group, Integer stringGroup, Boolean booleanGroup, Long int64Group, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1800,7 +1820,6 @@ public class FakeApi {
*/
public okhttp3.Call testInlineAdditionalPropertiesCall(Map<String, String> param, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1932,7 +1951,6 @@ public class FakeApi {
*/
public okhttp3.Call testJsonFormDataCall(String param, String param2, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -2083,7 +2101,6 @@ public class FakeApi {
*/
public okhttp3.Call testQueryParameterCollectionFormatCall(List<String> pipe, List<String> ioutil, List<String> http, List<String> url, List<String> context, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };

View File

@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class FakeClassnameTags123Api {
private ApiClient localVarApiClient;
@@ -89,7 +90,6 @@ public class FakeClassnameTags123Api {
*/
public okhttp3.Call testClassnameCall(Client body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -186,8 +186,14 @@ public class FakeClassnameTags123Api {
*/
public ApiResponse<Client> testClassnameWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = testClassnameValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
}
/**

View File

@@ -40,6 +40,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class PetApi {
private ApiClient localVarApiClient;
@@ -93,7 +94,6 @@ public class PetApi {
*/
public okhttp3.Call addPetCall(Pet body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -229,7 +229,6 @@ public class PetApi {
*/
public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -369,7 +368,6 @@ public class PetApi {
*/
public okhttp3.Call findPetsByStatusCall(List<String> status, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -469,8 +467,14 @@ public class PetApi {
*/
public ApiResponse<List<Pet>> findPetsByStatusWithHttpInfo(List<String> status) throws ApiException {
okhttp3.Call localVarCall = findPetsByStatusValidateBeforeCall(status, null);
Type localVarReturnType = new TypeToken<List<Pet>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<List<Pet>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<List<Pet>>(){}.getType()));
e.setErrorObjectType(new GenericType<List<Pet>>(){});
throw e;
}
}
/**
@@ -511,7 +515,6 @@ public class PetApi {
@Deprecated
public okhttp3.Call findPetsByTagsCall(Set<String> tags, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -616,8 +619,14 @@ public class PetApi {
@Deprecated
public ApiResponse<Set<Pet>> findPetsByTagsWithHttpInfo(Set<String> tags) throws ApiException {
okhttp3.Call localVarCall = findPetsByTagsValidateBeforeCall(tags, null);
Type localVarReturnType = new TypeToken<Set<Pet>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Set<Pet>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Set<Pet>>(){}.getType()));
e.setErrorObjectType(new GenericType<Set<Pet>>(){});
throw e;
}
}
/**
@@ -659,7 +668,6 @@ public class PetApi {
*/
public okhttp3.Call getPetByIdCall(Long petId, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -761,8 +769,14 @@ public class PetApi {
*/
public ApiResponse<Pet> getPetByIdWithHttpInfo(Long petId) throws ApiException {
okhttp3.Call localVarCall = getPetByIdValidateBeforeCall(petId, null);
Type localVarReturnType = new TypeToken<Pet>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Pet>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Pet>(){}.getType()));
e.setErrorObjectType(new GenericType<Pet>(){});
throw e;
}
}
/**
@@ -804,7 +818,6 @@ public class PetApi {
*/
public okhttp3.Call updatePetCall(Pet body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -946,7 +959,6 @@ public class PetApi {
*/
public okhttp3.Call updatePetWithFormCall(Long petId, String name, String status, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1094,7 +1106,6 @@ public class PetApi {
*/
public okhttp3.Call uploadFileCall(Long petId, String additionalMetadata, File _file, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1204,8 +1215,14 @@ public class PetApi {
*/
public ApiResponse<ModelApiResponse> uploadFileWithHttpInfo(Long petId, String additionalMetadata, File _file) throws ApiException {
okhttp3.Call localVarCall = uploadFileValidateBeforeCall(petId, additionalMetadata, _file, null);
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<ModelApiResponse>(){}.getType()));
e.setErrorObjectType(new GenericType<ModelApiResponse>(){});
throw e;
}
}
/**
@@ -1246,7 +1263,6 @@ public class PetApi {
*/
public okhttp3.Call uploadFileWithRequiredFileCall(Long petId, File requiredFile, String additionalMetadata, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1361,8 +1377,14 @@ public class PetApi {
*/
public ApiResponse<ModelApiResponse> uploadFileWithRequiredFileWithHttpInfo(Long petId, File requiredFile, String additionalMetadata) throws ApiException {
okhttp3.Call localVarCall = uploadFileWithRequiredFileValidateBeforeCall(petId, requiredFile, additionalMetadata, null);
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<ModelApiResponse>(){}.getType()));
e.setErrorObjectType(new GenericType<ModelApiResponse>(){});
throw e;
}
}
/**

View File

@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class StoreApi {
private ApiClient localVarApiClient;
@@ -90,7 +91,6 @@ public class StoreApi {
*/
public okhttp3.Call deleteOrderCall(String orderId, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -224,7 +224,6 @@ public class StoreApi {
*/
public okhttp3.Call getInventoryCall(final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -314,8 +313,14 @@ public class StoreApi {
*/
public ApiResponse<Map<String, Integer>> getInventoryWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = getInventoryValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<Map<String, Integer>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Map<String, Integer>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Map<String, Integer>>(){}.getType()));
e.setErrorObjectType(new GenericType<Map<String, Integer>>(){});
throw e;
}
}
/**
@@ -353,7 +358,6 @@ public class StoreApi {
*/
public okhttp3.Call getOrderByIdCall(Long orderId, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -455,8 +459,14 @@ public class StoreApi {
*/
public ApiResponse<Order> getOrderByIdWithHttpInfo(Long orderId) throws ApiException {
okhttp3.Call localVarCall = getOrderByIdValidateBeforeCall(orderId, null);
Type localVarReturnType = new TypeToken<Order>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Order>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Order>(){}.getType()));
e.setErrorObjectType(new GenericType<Order>(){});
throw e;
}
}
/**
@@ -496,7 +506,6 @@ public class StoreApi {
*/
public okhttp3.Call placeOrderCall(Order body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -595,8 +604,14 @@ public class StoreApi {
*/
public ApiResponse<Order> placeOrderWithHttpInfo(Order body) throws ApiException {
okhttp3.Call localVarCall = placeOrderValidateBeforeCall(body, null);
Type localVarReturnType = new TypeToken<Order>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<Order>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Order>(){}.getType()));
e.setErrorObjectType(new GenericType<Order>(){});
throw e;
}
}
/**

View File

@@ -38,6 +38,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
public class UserApi {
private ApiClient localVarApiClient;
@@ -90,7 +91,6 @@ public class UserApi {
*/
public okhttp3.Call createUserCall(User body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -221,7 +221,6 @@ public class UserApi {
*/
public okhttp3.Call createUsersWithArrayInputCall(List<User> body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -352,7 +351,6 @@ public class UserApi {
*/
public okhttp3.Call createUsersWithListInputCall(List<User> body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -484,7 +482,6 @@ public class UserApi {
*/
public okhttp3.Call deleteUserCall(String username, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -621,7 +618,6 @@ public class UserApi {
*/
public okhttp3.Call getUserByNameCall(String username, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -723,8 +719,14 @@ public class UserApi {
*/
public ApiResponse<User> getUserByNameWithHttpInfo(String username) throws ApiException {
okhttp3.Call localVarCall = getUserByNameValidateBeforeCall(username, null);
Type localVarReturnType = new TypeToken<User>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<User>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<User>(){}.getType()));
e.setErrorObjectType(new GenericType<User>(){});
throw e;
}
}
/**
@@ -765,7 +767,6 @@ public class UserApi {
*/
public okhttp3.Call loginUserCall(String username, String password, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -873,8 +874,14 @@ public class UserApi {
*/
public ApiResponse<String> loginUserWithHttpInfo(String username, String password) throws ApiException {
okhttp3.Call localVarCall = loginUserValidateBeforeCall(username, password, null);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
try {
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<String>(){}.getType()));
e.setErrorObjectType(new GenericType<String>(){});
throw e;
}
}
/**
@@ -912,7 +919,6 @@ public class UserApi {
*/
public okhttp3.Call logoutUserCall(final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@@ -1037,7 +1043,6 @@ public class UserApi {
*/
public okhttp3.Call updateUserCall(String username, User body, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };

View File

@@ -28,22 +28,31 @@ public class RetryingOAuth extends OAuth implements Interceptor {
private TokenRequestBuilder tokenRequestBuilder;
/**
* @param client An OkHttp client
* @param tokenRequestBuilder A token request builder
*/
public RetryingOAuth(OkHttpClient client, TokenRequestBuilder tokenRequestBuilder) {
this.oAuthClient = new OAuthClient(new OAuthOkHttpClient(client));
this.tokenRequestBuilder = tokenRequestBuilder;
}
/**
* @param tokenRequestBuilder A token request builder
*/
public RetryingOAuth(TokenRequestBuilder tokenRequestBuilder) {
this(new OkHttpClient(), tokenRequestBuilder);
}
/**
@param tokenUrl The token URL to be used for this OAuth2 flow.
Applicable to the following OAuth2 flows: "password", "clientCredentials" and "authorizationCode".
The value must be an absolute URL.
@param clientId The OAuth2 client ID for the "clientCredentials" flow.
@param clientSecret The OAuth2 client secret for the "clientCredentials" flow.
*/
* @param tokenUrl The token URL to be used for this OAuth2 flow.
* Applicable to the following OAuth2 flows: "password", "clientCredentials" and "authorizationCode".
* The value must be an absolute URL.
* @param clientId The OAuth2 client ID for the "clientCredentials" flow.
* @param flow OAuth flow.
* @param clientSecret The OAuth2 client secret for the "clientCredentials" flow.
* @param parameters A map of string.
*/
public RetryingOAuth(
String tokenUrl,
String clientId,
@@ -62,6 +71,11 @@ public class RetryingOAuth extends OAuth implements Interceptor {
}
}
/**
* Set the OAuth flow
*
* @param flow The OAuth flow.
*/
public void setFlow(OAuthFlow flow) {
switch(flow) {
case ACCESS_CODE:
@@ -147,8 +161,12 @@ public class RetryingOAuth extends OAuth implements Interceptor {
}
}
/*
/**
* Returns true if the access token has been updated
*
* @param requestAccessToken the request access token
* @return True if the update is successful
* @throws java.io.IOException If fail to update the access token
*/
public synchronized boolean updateAccessToken(String requestAccessToken) throws IOException {
if (getAccessToken() == null || getAccessToken().equals(requestAccessToken)) {
@@ -165,10 +183,21 @@ public class RetryingOAuth extends OAuth implements Interceptor {
return getAccessToken() == null || !getAccessToken().equals(requestAccessToken);
}
/**
* Gets the token request builder
*
* @return A token request builder
* @throws java.io.IOException If fail to update the access token
*/
public TokenRequestBuilder getTokenRequestBuilder() {
return tokenRequestBuilder;
}
/**
* Sets the token request builder
*
* @param tokenRequestBuilder Token request builder
*/
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
this.tokenRequestBuilder = tokenRequestBuilder;
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesAnyType
*/
@@ -100,5 +119,89 @@ public class AdditionalPropertiesAnyType extends HashMap<String, Object> {
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("name");
// 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 AdditionalPropertiesAnyType
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesAnyType.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesAnyType is not found in the empty JSON string", AdditionalPropertiesAnyType.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesAnyType.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesAnyType` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesAnyType.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesAnyType' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesAnyType> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesAnyType.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesAnyType>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesAnyType value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesAnyType read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesAnyType given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesAnyType
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesAnyType
*/
public static AdditionalPropertiesAnyType fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesAnyType.class);
}
/**
* Convert an instance of AdditionalPropertiesAnyType to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ 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.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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesArray
*/
@@ -101,5 +120,89 @@ public class AdditionalPropertiesArray extends HashMap<String, List> {
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("name");
// 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 AdditionalPropertiesArray
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesArray.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesArray is not found in the empty JSON string", AdditionalPropertiesArray.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesArray.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesArray` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesArray.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesArray' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesArray> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesArray.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesArray>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesArray value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesArray read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesArray given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesArray
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesArray
*/
public static AdditionalPropertiesArray fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesArray.class);
}
/**
* Convert an instance of AdditionalPropertiesArray to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesBoolean
*/
@@ -100,5 +119,89 @@ public class AdditionalPropertiesBoolean extends HashMap<String, Boolean> {
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("name");
// 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 AdditionalPropertiesBoolean
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesBoolean.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesBoolean is not found in the empty JSON string", AdditionalPropertiesBoolean.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesBoolean.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesBoolean` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesBoolean.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesBoolean' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesBoolean> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesBoolean.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesBoolean>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesBoolean value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesBoolean read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesBoolean given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesBoolean
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesBoolean
*/
public static AdditionalPropertiesBoolean fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesBoolean.class);
}
/**
* Convert an instance of AdditionalPropertiesBoolean to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -28,6 +28,25 @@ 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.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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesClass
*/
@@ -454,5 +473,99 @@ public class AdditionalPropertiesClass {
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("map_string");
openapiFields.add("map_number");
openapiFields.add("map_integer");
openapiFields.add("map_boolean");
openapiFields.add("map_array_integer");
openapiFields.add("map_array_anytype");
openapiFields.add("map_map_string");
openapiFields.add("map_map_anytype");
openapiFields.add("anytype_1");
openapiFields.add("anytype_2");
openapiFields.add("anytype_3");
// 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 AdditionalPropertiesClass
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesClass.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesClass is not found in the empty JSON string", AdditionalPropertiesClass.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesClass.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesClass` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesClass.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesClass' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesClass> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesClass.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesClass>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesClass value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesClass read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesClass given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesClass
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesClass
*/
public static AdditionalPropertiesClass fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesClass.class);
}
/**
* Convert an instance of AdditionalPropertiesClass to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesInteger
*/
@@ -100,5 +119,89 @@ public class AdditionalPropertiesInteger extends HashMap<String, Integer> {
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("name");
// 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 AdditionalPropertiesInteger
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesInteger.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesInteger is not found in the empty JSON string", AdditionalPropertiesInteger.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesInteger.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesInteger` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesInteger.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesInteger' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesInteger> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesInteger.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesInteger>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesInteger value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesInteger read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesInteger given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesInteger
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesInteger
*/
public static AdditionalPropertiesInteger fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesInteger.class);
}
/**
* Convert an instance of AdditionalPropertiesInteger to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesNumber
*/
@@ -101,5 +120,89 @@ public class AdditionalPropertiesNumber extends HashMap<String, BigDecimal> {
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("name");
// 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 AdditionalPropertiesNumber
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesNumber.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesNumber is not found in the empty JSON string", AdditionalPropertiesNumber.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesNumber.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesNumber` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesNumber.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesNumber' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesNumber> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesNumber.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesNumber>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesNumber value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesNumber read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesNumber given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesNumber
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesNumber
*/
public static AdditionalPropertiesNumber fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesNumber.class);
}
/**
* Convert an instance of AdditionalPropertiesNumber to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesObject
*/
@@ -100,5 +119,89 @@ public class AdditionalPropertiesObject extends HashMap<String, Map> {
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("name");
// 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 AdditionalPropertiesObject
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesObject.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesObject is not found in the empty JSON string", AdditionalPropertiesObject.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesObject.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesObject` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesObject.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesObject' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesObject> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesObject.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesObject>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesObject value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesObject read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesObject given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesObject
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesObject
*/
public static AdditionalPropertiesObject fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesObject.class);
}
/**
* Convert an instance of AdditionalPropertiesObject to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* AdditionalPropertiesString
*/
@@ -100,5 +119,89 @@ public class AdditionalPropertiesString extends HashMap<String, String> {
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("name");
// 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 AdditionalPropertiesString
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (AdditionalPropertiesString.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in AdditionalPropertiesString is not found in the empty JSON string", AdditionalPropertiesString.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!AdditionalPropertiesString.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AdditionalPropertiesString` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!AdditionalPropertiesString.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'AdditionalPropertiesString' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<AdditionalPropertiesString> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(AdditionalPropertiesString.class));
return (TypeAdapter<T>) new TypeAdapter<AdditionalPropertiesString>() {
@Override
public void write(JsonWriter out, AdditionalPropertiesString value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public AdditionalPropertiesString read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of AdditionalPropertiesString given an JSON string
*
* @param jsonString JSON string
* @return An instance of AdditionalPropertiesString
* @throws IOException if the JSON string is invalid with respect to AdditionalPropertiesString
*/
public static AdditionalPropertiesString fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, AdditionalPropertiesString.class);
}
/**
* Convert an instance of AdditionalPropertiesString to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import org.openapitools.client.model.BigCat;
import org.openapitools.client.model.Cat;
import org.openapitools.client.model.Dog;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Animal
*/
@@ -129,5 +148,71 @@ public class Animal {
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("className");
openapiFields.add("color");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("className");
}
/**
* 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 Animal
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Animal.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Animal is not found in the empty JSON string", Animal.openapiRequiredFields.toString()));
}
}
String discriminatorValue = jsonObj.get("className").getAsString();
switch (discriminatorValue) {
case "BigCat":
BigCat.validateJsonObject(jsonObj);
break;
case "Cat":
Cat.validateJsonObject(jsonObj);
break;
case "Dog":
Dog.validateJsonObject(jsonObj);
break;
default:
throw new IllegalArgumentException(String.format("The value of the `className` field `%s` does not match any key defined in the discriminator's mapping.", discriminatorValue));
}
}
/**
* Create an instance of Animal given an JSON string
*
* @param jsonString JSON string
* @return An instance of Animal
* @throws IOException if the JSON string is invalid with respect to Animal
*/
public static Animal fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Animal.class);
}
/**
* Convert an instance of Animal to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ArrayOfArrayOfNumberOnly
*/
@@ -107,5 +126,89 @@ public class ArrayOfArrayOfNumberOnly {
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("ArrayArrayNumber");
// 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 ArrayOfArrayOfNumberOnly
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ArrayOfArrayOfNumberOnly.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ArrayOfArrayOfNumberOnly is not found in the empty JSON string", ArrayOfArrayOfNumberOnly.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ArrayOfArrayOfNumberOnly.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ArrayOfArrayOfNumberOnly` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ArrayOfArrayOfNumberOnly.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ArrayOfArrayOfNumberOnly' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ArrayOfArrayOfNumberOnly> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ArrayOfArrayOfNumberOnly.class));
return (TypeAdapter<T>) new TypeAdapter<ArrayOfArrayOfNumberOnly>() {
@Override
public void write(JsonWriter out, ArrayOfArrayOfNumberOnly value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ArrayOfArrayOfNumberOnly read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ArrayOfArrayOfNumberOnly given an JSON string
*
* @param jsonString JSON string
* @return An instance of ArrayOfArrayOfNumberOnly
* @throws IOException if the JSON string is invalid with respect to ArrayOfArrayOfNumberOnly
*/
public static ArrayOfArrayOfNumberOnly fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ArrayOfArrayOfNumberOnly.class);
}
/**
* Convert an instance of ArrayOfArrayOfNumberOnly to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ArrayOfNumberOnly
*/
@@ -107,5 +126,89 @@ public class ArrayOfNumberOnly {
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("ArrayNumber");
// 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 ArrayOfNumberOnly
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ArrayOfNumberOnly.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ArrayOfNumberOnly is not found in the empty JSON string", ArrayOfNumberOnly.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ArrayOfNumberOnly.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ArrayOfNumberOnly` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ArrayOfNumberOnly.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ArrayOfNumberOnly' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ArrayOfNumberOnly> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ArrayOfNumberOnly.class));
return (TypeAdapter<T>) new TypeAdapter<ArrayOfNumberOnly>() {
@Override
public void write(JsonWriter out, ArrayOfNumberOnly value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ArrayOfNumberOnly read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ArrayOfNumberOnly given an JSON string
*
* @param jsonString JSON string
* @return An instance of ArrayOfNumberOnly
* @throws IOException if the JSON string is invalid with respect to ArrayOfNumberOnly
*/
public static ArrayOfNumberOnly fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ArrayOfNumberOnly.class);
}
/**
* Convert an instance of ArrayOfNumberOnly to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.util.ArrayList;
import java.util.List;
import org.openapitools.client.model.ReadOnlyFirst;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ArrayTest
*/
@@ -181,5 +200,91 @@ public class ArrayTest {
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("array_of_string");
openapiFields.add("array_array_of_integer");
openapiFields.add("array_array_of_model");
// 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 ArrayTest
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ArrayTest.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ArrayTest is not found in the empty JSON string", ArrayTest.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ArrayTest.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ArrayTest` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ArrayTest.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ArrayTest' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ArrayTest> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ArrayTest.class));
return (TypeAdapter<T>) new TypeAdapter<ArrayTest>() {
@Override
public void write(JsonWriter out, ArrayTest value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ArrayTest read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ArrayTest given an JSON string
*
* @param jsonString JSON string
* @return An instance of ArrayTest
* @throws IOException if the JSON string is invalid with respect to ArrayTest
*/
public static ArrayTest fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ArrayTest.class);
}
/**
* Convert an instance of ArrayTest to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import org.openapitools.client.model.BigCatAllOf;
import org.openapitools.client.model.Cat;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* BigCat
*/
@@ -152,5 +171,100 @@ public class BigCat extends Cat {
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("className");
openapiFields.add("color");
openapiFields.add("declawed");
openapiFields.add("kind");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("className");
}
/**
* 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 BigCat
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (BigCat.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in BigCat is not found in the empty JSON string", BigCat.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!BigCat.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `BigCat` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : BigCat.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!BigCat.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'BigCat' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<BigCat> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(BigCat.class));
return (TypeAdapter<T>) new TypeAdapter<BigCat>() {
@Override
public void write(JsonWriter out, BigCat value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public BigCat read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of BigCat given an JSON string
*
* @param jsonString JSON string
* @return An instance of BigCat
* @throws IOException if the JSON string is invalid with respect to BigCat
*/
public static BigCat fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, BigCat.class);
}
/**
* Convert an instance of BigCat to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* BigCatAllOf
*/
@@ -147,5 +166,89 @@ public class BigCatAllOf {
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("kind");
// 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 BigCatAllOf
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (BigCatAllOf.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in BigCatAllOf is not found in the empty JSON string", BigCatAllOf.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!BigCatAllOf.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `BigCatAllOf` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!BigCatAllOf.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'BigCatAllOf' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<BigCatAllOf> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(BigCatAllOf.class));
return (TypeAdapter<T>) new TypeAdapter<BigCatAllOf>() {
@Override
public void write(JsonWriter out, BigCatAllOf value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public BigCatAllOf read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of BigCatAllOf given an JSON string
*
* @param jsonString JSON string
* @return An instance of BigCatAllOf
* @throws IOException if the JSON string is invalid with respect to BigCatAllOf
*/
public static BigCatAllOf fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, BigCatAllOf.class);
}
/**
* Convert an instance of BigCatAllOf to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Capitalization
*/
@@ -241,5 +260,94 @@ public class Capitalization {
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("smallCamel");
openapiFields.add("CapitalCamel");
openapiFields.add("small_Snake");
openapiFields.add("Capital_Snake");
openapiFields.add("SCA_ETH_Flow_Points");
openapiFields.add("ATT_NAME");
// 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 Capitalization
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Capitalization.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Capitalization is not found in the empty JSON string", Capitalization.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Capitalization.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Capitalization` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Capitalization.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Capitalization' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Capitalization> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Capitalization.class));
return (TypeAdapter<T>) new TypeAdapter<Capitalization>() {
@Override
public void write(JsonWriter out, Capitalization value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Capitalization read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Capitalization given an JSON string
*
* @param jsonString JSON string
* @return An instance of Capitalization
* @throws IOException if the JSON string is invalid with respect to Capitalization
*/
public static Capitalization fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Capitalization.class);
}
/**
* Convert an instance of Capitalization to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import org.openapitools.client.model.Animal;
import org.openapitools.client.model.BigCat;
import org.openapitools.client.model.CatAllOf;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Cat
*/
@@ -102,5 +121,66 @@ public class Cat extends Animal {
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("className");
openapiFields.add("color");
openapiFields.add("declawed");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("className");
}
/**
* 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 Cat
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Cat.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Cat is not found in the empty JSON string", Cat.openapiRequiredFields.toString()));
}
}
String discriminatorValue = jsonObj.get("className").getAsString();
switch (discriminatorValue) {
case "BigCat":
BigCat.validateJsonObject(jsonObj);
break;
default:
throw new IllegalArgumentException(String.format("The value of the `className` field `%s` does not match any key defined in the discriminator's mapping.", discriminatorValue));
}
}
/**
* Create an instance of Cat given an JSON string
*
* @param jsonString JSON string
* @return An instance of Cat
* @throws IOException if the JSON string is invalid with respect to Cat
*/
public static Cat fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Cat.class);
}
/**
* Convert an instance of Cat to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* CatAllOf
*/
@@ -96,5 +115,89 @@ public class CatAllOf {
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("declawed");
// 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 CatAllOf
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (CatAllOf.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in CatAllOf is not found in the empty JSON string", CatAllOf.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!CatAllOf.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `CatAllOf` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!CatAllOf.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'CatAllOf' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<CatAllOf> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(CatAllOf.class));
return (TypeAdapter<T>) new TypeAdapter<CatAllOf>() {
@Override
public void write(JsonWriter out, CatAllOf value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public CatAllOf read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of CatAllOf given an JSON string
*
* @param jsonString JSON string
* @return An instance of CatAllOf
* @throws IOException if the JSON string is invalid with respect to CatAllOf
*/
public static CatAllOf fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, CatAllOf.class);
}
/**
* Convert an instance of CatAllOf to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Category
*/
@@ -125,5 +144,98 @@ public class Category {
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("id");
openapiFields.add("name");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("name");
}
/**
* 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 Category
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Category.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Category is not found in the empty JSON string", Category.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Category.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Category` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : Category.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Category.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Category' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Category> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Category.class));
return (TypeAdapter<T>) new TypeAdapter<Category>() {
@Override
public void write(JsonWriter out, Category value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Category read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Category given an JSON string
*
* @param jsonString JSON string
* @return An instance of Category
* @throws IOException if the JSON string is invalid with respect to Category
*/
public static Category fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Category.class);
}
/**
* Convert an instance of Category to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Model for testing model with \&quot;_class\&quot; property
*/
@@ -97,5 +116,89 @@ public class ClassModel {
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("_class");
// 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 ClassModel
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ClassModel.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ClassModel is not found in the empty JSON string", ClassModel.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ClassModel.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ClassModel` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ClassModel.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ClassModel' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ClassModel> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ClassModel.class));
return (TypeAdapter<T>) new TypeAdapter<ClassModel>() {
@Override
public void write(JsonWriter out, ClassModel value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ClassModel read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ClassModel given an JSON string
*
* @param jsonString JSON string
* @return An instance of ClassModel
* @throws IOException if the JSON string is invalid with respect to ClassModel
*/
public static ClassModel fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ClassModel.class);
}
/**
* Convert an instance of ClassModel to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Client
*/
@@ -96,5 +115,89 @@ public class Client {
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("client");
// 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 Client
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Client.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Client is not found in the empty JSON string", Client.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Client.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Client` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Client.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Client' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Client> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Client.class));
return (TypeAdapter<T>) new TypeAdapter<Client>() {
@Override
public void write(JsonWriter out, Client value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Client read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Client given an JSON string
*
* @param jsonString JSON string
* @return An instance of Client
* @throws IOException if the JSON string is invalid with respect to Client
*/
public static Client fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Client.class);
}
/**
* Convert an instance of Client to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import org.openapitools.client.model.Animal;
import org.openapitools.client.model.DogAllOf;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Dog
*/
@@ -101,5 +120,99 @@ public class Dog extends Animal {
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("className");
openapiFields.add("color");
openapiFields.add("breed");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("className");
}
/**
* 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 Dog
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Dog.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Dog is not found in the empty JSON string", Dog.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Dog.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Dog` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : Dog.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Dog.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Dog' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Dog> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Dog.class));
return (TypeAdapter<T>) new TypeAdapter<Dog>() {
@Override
public void write(JsonWriter out, Dog value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Dog read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Dog given an JSON string
*
* @param jsonString JSON string
* @return An instance of Dog
* @throws IOException if the JSON string is invalid with respect to Dog
*/
public static Dog fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Dog.class);
}
/**
* Convert an instance of Dog to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* DogAllOf
*/
@@ -96,5 +115,89 @@ public class DogAllOf {
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("breed");
// 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 DogAllOf
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (DogAllOf.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in DogAllOf is not found in the empty JSON string", DogAllOf.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!DogAllOf.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `DogAllOf` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!DogAllOf.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'DogAllOf' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<DogAllOf> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(DogAllOf.class));
return (TypeAdapter<T>) new TypeAdapter<DogAllOf>() {
@Override
public void write(JsonWriter out, DogAllOf value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public DogAllOf read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of DogAllOf given an JSON string
*
* @param jsonString JSON string
* @return An instance of DogAllOf
* @throws IOException if the JSON string is invalid with respect to DogAllOf
*/
public static DogAllOf fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, DogAllOf.class);
}
/**
* Convert an instance of DogAllOf to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -26,6 +26,25 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* EnumArrays
*/
@@ -229,5 +248,90 @@ public class EnumArrays {
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("just_symbol");
openapiFields.add("array_enum");
// 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 EnumArrays
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (EnumArrays.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in EnumArrays is not found in the empty JSON string", EnumArrays.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!EnumArrays.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EnumArrays` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!EnumArrays.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'EnumArrays' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<EnumArrays> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(EnumArrays.class));
return (TypeAdapter<T>) new TypeAdapter<EnumArrays>() {
@Override
public void write(JsonWriter out, EnumArrays value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public EnumArrays read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of EnumArrays given an JSON string
*
* @param jsonString JSON string
* @return An instance of EnumArrays
* @throws IOException if the JSON string is invalid with respect to EnumArrays
*/
public static EnumArrays fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, EnumArrays.class);
}
/**
* Convert an instance of EnumArrays to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -25,6 +25,25 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import org.openapitools.client.model.OuterEnum;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* EnumTest
*/
@@ -405,5 +424,101 @@ public class EnumTest {
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("enum_string");
openapiFields.add("enum_string_required");
openapiFields.add("enum_integer");
openapiFields.add("enum_number");
openapiFields.add("outerEnum");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("enum_string_required");
}
/**
* 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 EnumTest
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (EnumTest.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in EnumTest is not found in the empty JSON string", EnumTest.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!EnumTest.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EnumTest` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : EnumTest.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!EnumTest.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'EnumTest' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<EnumTest> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(EnumTest.class));
return (TypeAdapter<T>) new TypeAdapter<EnumTest>() {
@Override
public void write(JsonWriter out, EnumTest value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public EnumTest read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of EnumTest given an JSON string
*
* @param jsonString JSON string
* @return An instance of EnumTest
* @throws IOException if the JSON string is invalid with respect to EnumTest
*/
public static EnumTest fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, EnumTest.class);
}
/**
* Convert an instance of EnumTest to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.util.ArrayList;
import java.util.List;
import org.openapitools.client.model.ModelFile;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* FileSchemaTestClass
*/
@@ -136,5 +155,101 @@ public class FileSchemaTestClass {
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("file");
openapiFields.add("files");
// 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 FileSchemaTestClass
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (FileSchemaTestClass.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in FileSchemaTestClass is not found in the empty JSON string", FileSchemaTestClass.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!FileSchemaTestClass.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `FileSchemaTestClass` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// validate the optional field `file`
if (jsonObj.getAsJsonObject("file") != null) {
ModelFile.validateJsonObject(jsonObj.getAsJsonObject("file"));
}
JsonArray jsonArrayfiles = jsonObj.getAsJsonArray("files");
// validate the optional field `files` (array)
if (jsonArrayfiles != null) {
for (int i = 0; i < jsonArrayfiles.size(); i++) {
ModelFile.validateJsonObject(jsonArrayfiles.get(i).getAsJsonObject());
};
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!FileSchemaTestClass.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'FileSchemaTestClass' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<FileSchemaTestClass> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(FileSchemaTestClass.class));
return (TypeAdapter<T>) new TypeAdapter<FileSchemaTestClass>() {
@Override
public void write(JsonWriter out, FileSchemaTestClass value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public FileSchemaTestClass read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of FileSchemaTestClass given an JSON string
*
* @param jsonString JSON string
* @return An instance of FileSchemaTestClass
* @throws IOException if the JSON string is invalid with respect to FileSchemaTestClass
*/
public static FileSchemaTestClass fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, FileSchemaTestClass.class);
}
/**
* Convert an instance of FileSchemaTestClass to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -29,6 +29,25 @@ import java.util.UUID;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* FormatTest
*/
@@ -488,5 +507,113 @@ public class FormatTest {
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("integer");
openapiFields.add("int32");
openapiFields.add("int64");
openapiFields.add("number");
openapiFields.add("float");
openapiFields.add("double");
openapiFields.add("string");
openapiFields.add("byte");
openapiFields.add("binary");
openapiFields.add("date");
openapiFields.add("dateTime");
openapiFields.add("uuid");
openapiFields.add("password");
openapiFields.add("BigDecimal");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("number");
openapiRequiredFields.add("byte");
openapiRequiredFields.add("date");
openapiRequiredFields.add("password");
}
/**
* 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 FormatTest
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (FormatTest.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in FormatTest is not found in the empty JSON string", FormatTest.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!FormatTest.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `FormatTest` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : FormatTest.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!FormatTest.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'FormatTest' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<FormatTest> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(FormatTest.class));
return (TypeAdapter<T>) new TypeAdapter<FormatTest>() {
@Override
public void write(JsonWriter out, FormatTest value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public FormatTest read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of FormatTest given an JSON string
*
* @param jsonString JSON string
* @return An instance of FormatTest
* @throws IOException if the JSON string is invalid with respect to FormatTest
*/
public static FormatTest fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, FormatTest.class);
}
/**
* Convert an instance of FormatTest to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* HasOnlyReadOnly
*/
@@ -117,5 +136,90 @@ public class HasOnlyReadOnly {
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("bar");
openapiFields.add("foo");
// 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 HasOnlyReadOnly
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (HasOnlyReadOnly.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in HasOnlyReadOnly is not found in the empty JSON string", HasOnlyReadOnly.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!HasOnlyReadOnly.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `HasOnlyReadOnly` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!HasOnlyReadOnly.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'HasOnlyReadOnly' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<HasOnlyReadOnly> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(HasOnlyReadOnly.class));
return (TypeAdapter<T>) new TypeAdapter<HasOnlyReadOnly>() {
@Override
public void write(JsonWriter out, HasOnlyReadOnly value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public HasOnlyReadOnly read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of HasOnlyReadOnly given an JSON string
*
* @param jsonString JSON string
* @return An instance of HasOnlyReadOnly
* @throws IOException if the JSON string is invalid with respect to HasOnlyReadOnly
*/
public static HasOnlyReadOnly fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, HasOnlyReadOnly.class);
}
/**
* Convert an instance of HasOnlyReadOnly to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ 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.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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* MapTest
*/
@@ -265,5 +284,92 @@ public class MapTest {
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("map_map_of_string");
openapiFields.add("map_of_enum_string");
openapiFields.add("direct_map");
openapiFields.add("indirect_map");
// 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 MapTest
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (MapTest.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in MapTest is not found in the empty JSON string", MapTest.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!MapTest.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `MapTest` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!MapTest.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'MapTest' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<MapTest> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(MapTest.class));
return (TypeAdapter<T>) new TypeAdapter<MapTest>() {
@Override
public void write(JsonWriter out, MapTest value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public MapTest read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of MapTest given an JSON string
*
* @param jsonString JSON string
* @return An instance of MapTest
* @throws IOException if the JSON string is invalid with respect to MapTest
*/
public static MapTest fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, MapTest.class);
}
/**
* Convert an instance of MapTest to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -30,6 +30,25 @@ import java.util.UUID;
import org.openapitools.client.model.Animal;
import org.threeten.bp.OffsetDateTime;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* MixedPropertiesAndAdditionalPropertiesClass
*/
@@ -168,5 +187,91 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
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("uuid");
openapiFields.add("dateTime");
openapiFields.add("map");
// 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 MixedPropertiesAndAdditionalPropertiesClass
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (MixedPropertiesAndAdditionalPropertiesClass.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in MixedPropertiesAndAdditionalPropertiesClass is not found in the empty JSON string", MixedPropertiesAndAdditionalPropertiesClass.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!MixedPropertiesAndAdditionalPropertiesClass.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `MixedPropertiesAndAdditionalPropertiesClass` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!MixedPropertiesAndAdditionalPropertiesClass.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'MixedPropertiesAndAdditionalPropertiesClass' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<MixedPropertiesAndAdditionalPropertiesClass> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(MixedPropertiesAndAdditionalPropertiesClass.class));
return (TypeAdapter<T>) new TypeAdapter<MixedPropertiesAndAdditionalPropertiesClass>() {
@Override
public void write(JsonWriter out, MixedPropertiesAndAdditionalPropertiesClass value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public MixedPropertiesAndAdditionalPropertiesClass read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of MixedPropertiesAndAdditionalPropertiesClass given an JSON string
*
* @param jsonString JSON string
* @return An instance of MixedPropertiesAndAdditionalPropertiesClass
* @throws IOException if the JSON string is invalid with respect to MixedPropertiesAndAdditionalPropertiesClass
*/
public static MixedPropertiesAndAdditionalPropertiesClass fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, MixedPropertiesAndAdditionalPropertiesClass.class);
}
/**
* Convert an instance of MixedPropertiesAndAdditionalPropertiesClass to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Model for testing model name starting with number
*/
@@ -126,5 +145,90 @@ public class Model200Response {
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("name");
openapiFields.add("class");
// 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 Model200Response
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Model200Response.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Model200Response is not found in the empty JSON string", Model200Response.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Model200Response.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Model200Response` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Model200Response.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Model200Response' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Model200Response> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Model200Response.class));
return (TypeAdapter<T>) new TypeAdapter<Model200Response>() {
@Override
public void write(JsonWriter out, Model200Response value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Model200Response read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Model200Response given an JSON string
*
* @param jsonString JSON string
* @return An instance of Model200Response
* @throws IOException if the JSON string is invalid with respect to Model200Response
*/
public static Model200Response fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Model200Response.class);
}
/**
* Convert an instance of Model200Response to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ModelApiResponse
*/
@@ -154,5 +173,91 @@ public class ModelApiResponse {
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("code");
openapiFields.add("type");
openapiFields.add("message");
// 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 ModelApiResponse
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ModelApiResponse.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ModelApiResponse is not found in the empty JSON string", ModelApiResponse.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ModelApiResponse.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ModelApiResponse` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ModelApiResponse.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ModelApiResponse' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ModelApiResponse> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ModelApiResponse.class));
return (TypeAdapter<T>) new TypeAdapter<ModelApiResponse>() {
@Override
public void write(JsonWriter out, ModelApiResponse value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ModelApiResponse read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ModelApiResponse given an JSON string
*
* @param jsonString JSON string
* @return An instance of ModelApiResponse
* @throws IOException if the JSON string is invalid with respect to ModelApiResponse
*/
public static ModelApiResponse fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ModelApiResponse.class);
}
/**
* Convert an instance of ModelApiResponse to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Must be named &#x60;File&#x60; for test.
*/
@@ -97,5 +116,89 @@ public class ModelFile {
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("sourceURI");
// 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 ModelFile
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ModelFile.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ModelFile is not found in the empty JSON string", ModelFile.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ModelFile.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ModelFile` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ModelFile.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ModelFile' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ModelFile> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ModelFile.class));
return (TypeAdapter<T>) new TypeAdapter<ModelFile>() {
@Override
public void write(JsonWriter out, ModelFile value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ModelFile read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ModelFile given an JSON string
*
* @param jsonString JSON string
* @return An instance of ModelFile
* @throws IOException if the JSON string is invalid with respect to ModelFile
*/
public static ModelFile fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ModelFile.class);
}
/**
* Convert an instance of ModelFile to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ModelList
*/
@@ -96,5 +115,89 @@ public class ModelList {
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("123-list");
// 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 ModelList
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ModelList.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ModelList is not found in the empty JSON string", ModelList.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ModelList.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ModelList` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ModelList.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ModelList' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ModelList> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ModelList.class));
return (TypeAdapter<T>) new TypeAdapter<ModelList>() {
@Override
public void write(JsonWriter out, ModelList value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ModelList read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ModelList given an JSON string
*
* @param jsonString JSON string
* @return An instance of ModelList
* @throws IOException if the JSON string is invalid with respect to ModelList
*/
public static ModelList fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ModelList.class);
}
/**
* Convert an instance of ModelList to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Model for testing reserved words
*/
@@ -97,5 +116,89 @@ public class ModelReturn {
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("return");
// 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 ModelReturn
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ModelReturn.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ModelReturn is not found in the empty JSON string", ModelReturn.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ModelReturn.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ModelReturn` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ModelReturn.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ModelReturn' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ModelReturn> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ModelReturn.class));
return (TypeAdapter<T>) new TypeAdapter<ModelReturn>() {
@Override
public void write(JsonWriter out, ModelReturn value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ModelReturn read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ModelReturn given an JSON string
*
* @param jsonString JSON string
* @return An instance of ModelReturn
* @throws IOException if the JSON string is invalid with respect to ModelReturn
*/
public static ModelReturn fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ModelReturn.class);
}
/**
* Convert an instance of ModelReturn to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Model for testing model name same as property name
*/
@@ -176,5 +195,100 @@ public class Name {
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("name");
openapiFields.add("snake_case");
openapiFields.add("property");
openapiFields.add("123Number");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("name");
}
/**
* 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 Name
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Name.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Name is not found in the empty JSON string", Name.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Name.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Name` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : Name.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Name.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Name' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Name> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Name.class));
return (TypeAdapter<T>) new TypeAdapter<Name>() {
@Override
public void write(JsonWriter out, Name value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Name read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Name given an JSON string
*
* @param jsonString JSON string
* @return An instance of Name
* @throws IOException if the JSON string is invalid with respect to Name
*/
public static Name fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Name.class);
}
/**
* Convert an instance of Name to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -25,6 +25,25 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.math.BigDecimal;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* NumberOnly
*/
@@ -97,5 +116,89 @@ public class NumberOnly {
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("JustNumber");
// 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 NumberOnly
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (NumberOnly.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in NumberOnly is not found in the empty JSON string", NumberOnly.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!NumberOnly.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `NumberOnly` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!NumberOnly.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'NumberOnly' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<NumberOnly> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(NumberOnly.class));
return (TypeAdapter<T>) new TypeAdapter<NumberOnly>() {
@Override
public void write(JsonWriter out, NumberOnly value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public NumberOnly read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of NumberOnly given an JSON string
*
* @param jsonString JSON string
* @return An instance of NumberOnly
* @throws IOException if the JSON string is invalid with respect to NumberOnly
*/
public static NumberOnly fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, NumberOnly.class);
}
/**
* Convert an instance of NumberOnly to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -25,6 +25,25 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import org.threeten.bp.OffsetDateTime;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Order
*/
@@ -291,5 +310,94 @@ public class Order {
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("id");
openapiFields.add("petId");
openapiFields.add("quantity");
openapiFields.add("shipDate");
openapiFields.add("status");
openapiFields.add("complete");
// 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 Order
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Order.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Order is not found in the empty JSON string", Order.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Order.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Order` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Order.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Order' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Order> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Order.class));
return (TypeAdapter<T>) new TypeAdapter<Order>() {
@Override
public void write(JsonWriter out, Order value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Order read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Order given an JSON string
*
* @param jsonString JSON string
* @return An instance of Order
* @throws IOException if the JSON string is invalid with respect to Order
*/
public static Order fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Order.class);
}
/**
* Convert an instance of Order to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -25,6 +25,25 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.math.BigDecimal;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* OuterComposite
*/
@@ -155,5 +174,91 @@ public class OuterComposite {
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("my_number");
openapiFields.add("my_string");
openapiFields.add("my_boolean");
// 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 OuterComposite
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (OuterComposite.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in OuterComposite is not found in the empty JSON string", OuterComposite.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!OuterComposite.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `OuterComposite` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!OuterComposite.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'OuterComposite' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<OuterComposite> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(OuterComposite.class));
return (TypeAdapter<T>) new TypeAdapter<OuterComposite>() {
@Override
public void write(JsonWriter out, OuterComposite value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public OuterComposite read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of OuterComposite given an JSON string
*
* @param jsonString JSON string
* @return An instance of OuterComposite
* @throws IOException if the JSON string is invalid with respect to OuterComposite
*/
public static OuterComposite fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, OuterComposite.class);
}
/**
* Convert an instance of OuterComposite to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -30,6 +30,25 @@ import java.util.Set;
import org.openapitools.client.model.Category;
import org.openapitools.client.model.Tag;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Pet
*/
@@ -309,5 +328,114 @@ public class Pet {
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("id");
openapiFields.add("category");
openapiFields.add("name");
openapiFields.add("photoUrls");
openapiFields.add("tags");
openapiFields.add("status");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("name");
openapiRequiredFields.add("photoUrls");
}
/**
* 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 Pet
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Pet.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Pet is not found in the empty JSON string", Pet.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Pet.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Pet` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : Pet.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
// validate the optional field `category`
if (jsonObj.getAsJsonObject("category") != null) {
Category.validateJsonObject(jsonObj.getAsJsonObject("category"));
}
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
// validate the optional field `tags` (array)
if (jsonArraytags != null) {
for (int i = 0; i < jsonArraytags.size(); i++) {
Tag.validateJsonObject(jsonArraytags.get(i).getAsJsonObject());
};
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Pet.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Pet' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Pet> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Pet.class));
return (TypeAdapter<T>) new TypeAdapter<Pet>() {
@Override
public void write(JsonWriter out, Pet value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Pet read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Pet given an JSON string
*
* @param jsonString JSON string
* @return An instance of Pet
* @throws IOException if the JSON string is invalid with respect to Pet
*/
public static Pet fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Pet.class);
}
/**
* Convert an instance of Pet to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* ReadOnlyFirst
*/
@@ -124,5 +143,90 @@ public class ReadOnlyFirst {
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("bar");
openapiFields.add("baz");
// 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 ReadOnlyFirst
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ReadOnlyFirst.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in ReadOnlyFirst is not found in the empty JSON string", ReadOnlyFirst.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!ReadOnlyFirst.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ReadOnlyFirst` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ReadOnlyFirst.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'ReadOnlyFirst' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<ReadOnlyFirst> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(ReadOnlyFirst.class));
return (TypeAdapter<T>) new TypeAdapter<ReadOnlyFirst>() {
@Override
public void write(JsonWriter out, ReadOnlyFirst value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public ReadOnlyFirst read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of ReadOnlyFirst given an JSON string
*
* @param jsonString JSON string
* @return An instance of ReadOnlyFirst
* @throws IOException if the JSON string is invalid with respect to ReadOnlyFirst
*/
public static ReadOnlyFirst fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, ReadOnlyFirst.class);
}
/**
* Convert an instance of ReadOnlyFirst to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* SpecialModelName
*/
@@ -96,5 +115,89 @@ public class SpecialModelName {
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("$special[property.name]");
// 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 SpecialModelName
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (SpecialModelName.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in SpecialModelName is not found in the empty JSON string", SpecialModelName.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!SpecialModelName.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `SpecialModelName` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!SpecialModelName.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'SpecialModelName' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<SpecialModelName> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(SpecialModelName.class));
return (TypeAdapter<T>) new TypeAdapter<SpecialModelName>() {
@Override
public void write(JsonWriter out, SpecialModelName value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public SpecialModelName read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of SpecialModelName given an JSON string
*
* @param jsonString JSON string
* @return An instance of SpecialModelName
* @throws IOException if the JSON string is invalid with respect to SpecialModelName
*/
public static SpecialModelName fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, SpecialModelName.class);
}
/**
* Convert an instance of SpecialModelName to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* Tag
*/
@@ -125,5 +144,90 @@ public class Tag {
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("id");
openapiFields.add("name");
// 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 Tag
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Tag.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in Tag is not found in the empty JSON string", Tag.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!Tag.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Tag` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Tag.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Tag' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Tag> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Tag.class));
return (TypeAdapter<T>) new TypeAdapter<Tag>() {
@Override
public void write(JsonWriter out, Tag value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Tag read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of Tag given an JSON string
*
* @param jsonString JSON string
* @return An instance of Tag
* @throws IOException if the JSON string is invalid with respect to Tag
*/
public static Tag fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Tag.class);
}
/**
* Convert an instance of Tag to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* TypeHolderDefault
*/
@@ -220,5 +239,105 @@ public class TypeHolderDefault {
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_item");
openapiFields.add("number_item");
openapiFields.add("integer_item");
openapiFields.add("bool_item");
openapiFields.add("array_item");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("string_item");
openapiRequiredFields.add("number_item");
openapiRequiredFields.add("integer_item");
openapiRequiredFields.add("bool_item");
openapiRequiredFields.add("array_item");
}
/**
* 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 TypeHolderDefault
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (TypeHolderDefault.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in TypeHolderDefault is not found in the empty JSON string", TypeHolderDefault.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!TypeHolderDefault.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `TypeHolderDefault` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : TypeHolderDefault.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!TypeHolderDefault.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'TypeHolderDefault' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<TypeHolderDefault> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(TypeHolderDefault.class));
return (TypeAdapter<T>) new TypeAdapter<TypeHolderDefault>() {
@Override
public void write(JsonWriter out, TypeHolderDefault value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public TypeHolderDefault read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of TypeHolderDefault given an JSON string
*
* @param jsonString JSON string
* @return An instance of TypeHolderDefault
* @throws IOException if the JSON string is invalid with respect to TypeHolderDefault
*/
public static TypeHolderDefault fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, TypeHolderDefault.class);
}
/**
* Convert an instance of TypeHolderDefault to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* TypeHolderExample
*/
@@ -249,5 +268,107 @@ public class TypeHolderExample {
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_item");
openapiFields.add("number_item");
openapiFields.add("float_item");
openapiFields.add("integer_item");
openapiFields.add("bool_item");
openapiFields.add("array_item");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
openapiRequiredFields.add("string_item");
openapiRequiredFields.add("number_item");
openapiRequiredFields.add("float_item");
openapiRequiredFields.add("integer_item");
openapiRequiredFields.add("bool_item");
openapiRequiredFields.add("array_item");
}
/**
* 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 TypeHolderExample
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (TypeHolderExample.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in TypeHolderExample is not found in the empty JSON string", TypeHolderExample.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!TypeHolderExample.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `TypeHolderExample` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : TypeHolderExample.openapiRequiredFields) {
if (jsonObj.get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!TypeHolderExample.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'TypeHolderExample' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<TypeHolderExample> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(TypeHolderExample.class));
return (TypeAdapter<T>) new TypeAdapter<TypeHolderExample>() {
@Override
public void write(JsonWriter out, TypeHolderExample value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public TypeHolderExample read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of TypeHolderExample given an JSON string
*
* @param jsonString JSON string
* @return An instance of TypeHolderExample
* @throws IOException if the JSON string is invalid with respect to TypeHolderExample
*/
public static TypeHolderExample fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, TypeHolderExample.class);
}
/**
* Convert an instance of TypeHolderExample to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -24,6 +24,25 @@ 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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* User
*/
@@ -299,5 +318,96 @@ public class User {
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("id");
openapiFields.add("username");
openapiFields.add("firstName");
openapiFields.add("lastName");
openapiFields.add("email");
openapiFields.add("password");
openapiFields.add("phone");
openapiFields.add("userStatus");
// 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 User
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (User.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in User is not found in the empty JSON string", User.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!User.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `User` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!User.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'User' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<User> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(User.class));
return (TypeAdapter<T>) new TypeAdapter<User>() {
@Override
public void write(JsonWriter out, User value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public User read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of User given an JSON string
*
* @param jsonString JSON string
* @return An instance of User
* @throws IOException if the JSON string is invalid with respect to User
*/
public static User fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, User.class);
}
/**
* Convert an instance of User to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

View File

@@ -27,6 +27,25 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.openapitools.client.JSON;
/**
* XmlItem
*/
@@ -983,5 +1002,117 @@ public class XmlItem {
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("attribute_string");
openapiFields.add("attribute_number");
openapiFields.add("attribute_integer");
openapiFields.add("attribute_boolean");
openapiFields.add("wrapped_array");
openapiFields.add("name_string");
openapiFields.add("name_number");
openapiFields.add("name_integer");
openapiFields.add("name_boolean");
openapiFields.add("name_array");
openapiFields.add("name_wrapped_array");
openapiFields.add("prefix_string");
openapiFields.add("prefix_number");
openapiFields.add("prefix_integer");
openapiFields.add("prefix_boolean");
openapiFields.add("prefix_array");
openapiFields.add("prefix_wrapped_array");
openapiFields.add("namespace_string");
openapiFields.add("namespace_number");
openapiFields.add("namespace_integer");
openapiFields.add("namespace_boolean");
openapiFields.add("namespace_array");
openapiFields.add("namespace_wrapped_array");
openapiFields.add("prefix_ns_string");
openapiFields.add("prefix_ns_number");
openapiFields.add("prefix_ns_integer");
openapiFields.add("prefix_ns_boolean");
openapiFields.add("prefix_ns_array");
openapiFields.add("prefix_ns_wrapped_array");
// 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 XmlItem
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (XmlItem.openapiRequiredFields.isEmpty()) {
return;
} else { // has reuqired fields
throw new IllegalArgumentException(String.format("The required field(s) %s in XmlItem is not found in the empty JSON string", XmlItem.openapiRequiredFields.toString()));
}
}
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
// check to see if the JSON string contains additional fields
for (Entry<String, JsonElement> entry : entries) {
if (!XmlItem.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `XmlItem` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!XmlItem.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'XmlItem' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<XmlItem> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(XmlItem.class));
return (TypeAdapter<T>) new TypeAdapter<XmlItem>() {
@Override
public void write(JsonWriter out, XmlItem value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public XmlItem read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonObj);
}
}.nullSafe();
}
}
/**
* Create an instance of XmlItem given an JSON string
*
* @param jsonString JSON string
* @return An instance of XmlItem
* @throws IOException if the JSON string is invalid with respect to XmlItem
*/
public static XmlItem fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, XmlItem.class);
}
/**
* Convert an instance of XmlItem to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}