diff --git a/bin/utils/test_file_list.yaml b/bin/utils/test_file_list.yaml index 6bb064f509c..c86ca6ea74f 100644 --- a/bin/utils/test_file_list.yaml +++ b/bin/utils/test_file_list.yaml @@ -10,7 +10,7 @@ - filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java" sha256: db505f7801fef62c13a08a8e9ca1fc4c5c947ab46b46f12943139d353feacf17 - filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java" - sha256: c479b587cf0d51fa550eb81d33b277081807b87dc28649027d1164224c25ad0a + sha256: 8210bdaf06aae8dc46521515a8a0ef10e48c980fadd3efd95313e6c806f409c2 - filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java" sha256: 0d64cdc11809a7b5b952ccdad2bd91bd0045b3894d6fabf3e368fa0be12b8217 - filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java" diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index 1569eed43e4..33d93192d4c 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -54,8 +54,8 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isArray}} {{#isArray}} - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter<{{{dataType}}}> adapter{{complexType}}List = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType(); + final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); {{/isArray}} {{/anyOf}} {{/composedSchemas}} @@ -74,30 +74,32 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im // check if the actual instance is of the type `{{{dataType}}}` if (value.getActualInstance() instanceof {{#isArray}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) { {{#isPrimitiveType}} - JsonPrimitive primitive = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; - {{/isPrimitiveType}} - {{#isArray}} - List list = (List) value.getActualInstance(); - if(list.get(0) instanceof {{complexType}}) { - JsonArray array = adapter{{{complexType}}}List.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonArray(); - elementAdapter.write(out, array); + JsonPrimitive primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); return; - } + {{/isPrimitiveType}} + {{^isPrimitiveType}} + {{#isArray}} + List list = (List) value.getActualInstance(); + if (list.get(0) instanceof {{{items.dataType}}}) { + JsonArray array = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonArray(); + elementAdapter.write(out, array); + return; + } {{/isArray}} + {{/isPrimitiveType}} {{^isArray}} {{^isPrimitiveType}} - JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()); + elementAdapter.write(out, element); + return; {{/isPrimitiveType}} {{/isArray}} } {{/vendorExtensions.x-duplicated-data-type}} {{/anyOf}} {{/composedSchemas}} - throw new IOException("Failed to serialize as the type doesn't match anyOf schemae: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}"); + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}"); } @Override @@ -114,63 +116,66 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{^hasVars}} // deserialize {{{dataType}}} try { - // validate the JSON object to see if any exception is thrown + // validate the JSON object to see if any exception is thrown + {{^isArray}} {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; {{/isNumber}} {{^isNumber}} {{#isPrimitiveType}} - if(!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{^isArray}} - {{{dataType}}}.validateJsonElement(jsonElement); - actualAdapter = adapter{{{dataType}}}; - {{/isArray}} + if (!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(jsonElement); + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; {{/isPrimitiveType}} {{/isNumber}} - {{#isArray}} - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } - - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - {{#items}} - {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; - {{/isNumber}} - {{^isNumber}} - {{#isPrimitiveType}} - if(!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{{dataType}}}.validateJsonElement(element); - {{/isPrimitiveType}} - {{/isNumber}} - {{/items}} - } - actualAdapter = adapter{{{complexType}}}List; {{/isArray}} - {{classname}} ret = new {{classname}}(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + {{#isArray}} + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + {{#items}} + {{#isNumber}} + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isNumber}} + {{^isNumber}} + {{#isPrimitiveType}} + if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(element); + {{/isPrimitiveType}} + {{/isNumber}} + {{/items}} + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; + {{/isArray}} + {{classname}} ret = new {{classname}}(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema '{{{dataType}}}'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema '{{{dataType}}}'", e); } {{/hasVars}} {{#hasVars}} @@ -182,7 +187,6 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{classname}} ret = new {{classname}}(); ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); return ret; - log.log(Level.FINER, "Input data matches schema '{{{.}}}'"); } catch (Exception e) { // deserialization failed, continue errorMessages.add(String.format("Deserialization for {{{.}}} failed with `%s`.", e.getMessage())); @@ -250,10 +254,10 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im if (instance instanceof {{#isArray}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) { {{#isArray}} List list = (List) instance; - if(list.get(0) instanceof {{complexType}}) { - super.setActualInstance(instance); - return; - } + if (list.get(0) instanceof {{{items.dataType}}}) { + super.setActualInstance(instance); + return; + } {{/isArray}} {{^isArray}} super.setActualInstance(instance); @@ -273,6 +277,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im * * @return The actual instance ({{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -288,105 +293,108 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im * @return The actual instance of `{{{dataType}}}` * @throws ClassCastException if the instance is not `{{{dataType}}}` */ - public {{{dataType}}} get{{#isArray}}{{complexType}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException { + public {{{dataType}}} get{{#isArray}}{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException { return ({{{dataType}}})super.getActualInstance(); } {{/vendorExtensions.x-duplicated-data-type}} {{/anyOf}} {{/composedSchemas}} - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to {{classname}} - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate anyOf schemas one by one - ArrayList errorMessages = new ArrayList<>(); - {{#composedSchemas}} - {{#anyOf}} - {{^vendorExtensions.x-duplicated-data-type}} - // validate the json string with {{{dataType}}} - try { - {{^hasVars}} - {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isNumber}} - {{^isNumber}} - {{#isPrimitiveType}} - if(!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{^isArray}} - {{{dataType}}}.validateJsonElement(jsonElement); - {{/isArray}} - {{/isPrimitiveType}} - {{/isNumber}} - {{#isArray}} - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - {{#items}} + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to {{classname}} + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + {{#composedSchemas}} + {{#anyOf}} + {{^vendorExtensions.x-duplicated-data-type}} + // validate the json string with {{{dataType}}} + try { + {{^hasVars}} + {{^isArray}} {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } {{/isNumber}} {{^isNumber}} {{#isPrimitiveType}} - if(!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{{dataType}}}.validateJsonElement(element); + if (!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } {{/isPrimitiveType}} {{/isNumber}} - {{/items}} - } - {{/isArray}} - {{/hasVars}} - {{#hasVars}} - {{{.}}}.validateJsonElement(jsonElement); - return; - {{/hasVars}} - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); - // continue to the next one + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(jsonElement); + {{/isPrimitiveType}} + {{/isNumber}} + {{/isArray}} + {{#isArray}} + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + {{#items}} + {{#isNumber}} + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isNumber}} + {{^isNumber}} + {{#isPrimitiveType}} + if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(element); + {{/isPrimitiveType}} + {{/isNumber}} + {{/items}} + } + {{/isArray}} + {{/hasVars}} + {{#hasVars}} + {{{.}}}.validateJsonElement(jsonElement); + return; + {{/hasVars}} + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); + // continue to the next one + } + {{/vendorExtensions.x-duplicated-data-type}} + {{/anyOf}} + {{/composedSchemas}} + throw new IOException(String.format("The JSON string is invalid for {{classname}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); } - {{/vendorExtensions.x-duplicated-data-type}} - {{/anyOf}} - {{/composedSchemas}} - throw new IOException(String.format("The JSON string is invalid for {{classname}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); - - } - /** - * Create an instance of {{classname}} given an JSON string - * - * @param jsonString JSON string - * @return An instance of {{classname}} - * @throws IOException if the JSON string is invalid with respect to {{classname}} - */ - public static {{{classname}}} fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, {{{classname}}}.class); - } + /** + * Create an instance of {{classname}} given an JSON string + * + * @param jsonString JSON string + * @return An instance of {{classname}} + * @throws IOException if the JSON string is invalid with respect to {{classname}} + */ + public static {{{classname}}} fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, {{{classname}}}.class); + } - /** - * Convert an instance of {{classname}} to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of {{classname}} to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index b2ab54955d4..4a34934dce7 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -54,8 +54,8 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isArray}} {{#isArray}} - final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter<{{{dataType}}}> adapter{{complexType}}List = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType(); + final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); {{/isArray}} {{/oneOf}} {{/composedSchemas}} @@ -74,23 +74,25 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im // check if the actual instance is of the type `{{{dataType}}}` if (value.getActualInstance() instanceof {{#isArray}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) { {{#isPrimitiveType}} - JsonPrimitive primitive = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; - {{/isPrimitiveType}} - {{#isArray}} - List list = (List) value.getActualInstance(); - if(list.get(0) instanceof {{complexType}}) { - JsonArray array = adapter{{{complexType}}}List.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonArray(); - elementAdapter.write(out, array); + JsonPrimitive primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); return; - } + {{/isPrimitiveType}} + {{^isPrimitiveType}} + {{#isArray}} + List list = (List) value.getActualInstance(); + if (list.get(0) instanceof {{{items.dataType}}}) { + JsonArray array = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonArray(); + elementAdapter.write(out, array); + return; + } {{/isArray}} + {{/isPrimitiveType}} {{^isArray}} {{^isPrimitiveType}} - JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance()); + elementAdapter.write(out, element); + return; {{/isPrimitiveType}} {{/isArray}} } @@ -139,62 +141,65 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{^hasVars}} // deserialize {{{dataType}}} try { - // validate the JSON object to see if any exception is thrown + // validate the JSON object to see if any exception is thrown + {{^isArray}} {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; {{/isNumber}} {{^isNumber}} {{#isPrimitiveType}} - if(!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{^isArray}} - {{{dataType}}}.validateJsonElement(jsonElement); - actualAdapter = adapter{{{dataType}}}; - {{/isArray}} + if (!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(jsonElement); + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; {{/isPrimitiveType}} {{/isNumber}} - {{#isArray}} - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } - - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - {{#items}} - {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapter{{{dataType}}}; - {{/isNumber}} - {{^isNumber}} - {{#isPrimitiveType}} - if(!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{{dataType}}}.validateJsonElement(element); - {{/isPrimitiveType}} - {{/isNumber}} - {{/items}} - } - actualAdapter = adapter{{{complexType}}}List; {{/isArray}} - match++; - log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'"); + {{#isArray}} + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + {{#items}} + {{#isNumber}} + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isNumber}} + {{^isNumber}} + {{#isPrimitiveType}} + if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(element); + {{/isPrimitiveType}} + {{/isNumber}} + {{/items}} + } + actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}; + {{/isArray}} + match++; + log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema '{{{dataType}}}'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema '{{{dataType}}}'", e); } {{/hasVars}} {{#hasVars}} @@ -278,10 +283,10 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im if (instance instanceof {{#isArray}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) { {{#isArray}} List list = (List) instance; - if(list.get(0) instanceof {{complexType}}) { - super.setActualInstance(instance); - return; - } + if (list.get(0) instanceof {{{items.dataType}}}) { + super.setActualInstance(instance); + return; + } {{/isArray}} {{^isArray}} super.setActualInstance(instance); @@ -301,6 +306,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im * * @return The actual instance ({{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -316,107 +322,111 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im * @return The actual instance of `{{{dataType}}}` * @throws ClassCastException if the instance is not `{{{dataType}}}` */ - public {{{dataType}}} get{{#isArray}}{{complexType}}List{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException { + public {{{dataType}}} get{{#isArray}}{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException { return ({{{dataType}}})super.getActualInstance(); } {{/vendorExtensions.x-duplicated-data-type}} {{/oneOf}} {{/composedSchemas}} - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to {{classname}} - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - {{#composedSchemas}} - {{#oneOf}} - {{^vendorExtensions.x-duplicated-data-type}} - // validate the json string with {{{dataType}}} - try { - {{^hasVars}} - {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isNumber}} - {{^isNumber}} - {{#isPrimitiveType}} - if(!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{^isArray}} - {{{dataType}}}.validateJsonElement(jsonElement); - {{/isArray}} - {{/isPrimitiveType}} - {{/isNumber}} - {{#isArray}} - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - {{#items}} + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to {{classname}} + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + {{#composedSchemas}} + {{#oneOf}} + {{^vendorExtensions.x-duplicated-data-type}} + // validate the json string with {{{dataType}}} + try { + {{^hasVars}} + {{^isArray}} {{#isNumber}} - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } {{/isNumber}} {{^isNumber}} {{#isPrimitiveType}} - if(!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { - throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); - } - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{{dataType}}}.validateJsonElement(element); + if (!jsonElement.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } {{/isPrimitiveType}} {{/isNumber}} - {{/items}} - } - {{/isArray}} - {{/hasVars}} - {{#hasVars}} - {{{.}}}.validateJsonElement(jsonElement); - validCount++; - {{/hasVars}} - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); - // continue to the next one + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(jsonElement); + {{/isPrimitiveType}} + {{/isNumber}} + {{/isArray}} + {{#isArray}} + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + {{#items}} + {{#isNumber}} + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isNumber}} + {{^isNumber}} + {{#isPrimitiveType}} + if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString())); + } + {{/isPrimitiveType}} + {{/isNumber}} + {{^isNumber}} + {{^isPrimitiveType}} + {{{dataType}}}.validateJsonElement(element); + {{/isPrimitiveType}} + {{/isNumber}} + {{/items}} + } + {{/isArray}} + {{/hasVars}} + {{#hasVars}} + {{{.}}}.validateJsonElement(jsonElement); + validCount++; + {{/hasVars}} + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for {{{dataType}}} failed with `%s`.", e.getMessage())); + // continue to the next one + } + {{/vendorExtensions.x-duplicated-data-type}} + {{/oneOf}} + {{/composedSchemas}} + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for {{classname}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - {{/vendorExtensions.x-duplicated-data-type}} - {{/oneOf}} - {{/composedSchemas}} - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for {{classname}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + + /** + * Create an instance of {{classname}} given an JSON string + * + * @param jsonString JSON string + * @return An instance of {{classname}} + * @throws IOException if the JSON string is invalid with respect to {{classname}} + */ + public static {{{classname}}} fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, {{{classname}}}.class); } - } - /** - * Create an instance of {{classname}} given an JSON string - * - * @param jsonString JSON string - * @return An instance of {{classname}} - * @throws IOException if the JSON string is invalid with respect to {{classname}} - */ - public static {{{classname}}} fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, {{{classname}}}.class); - } - - /** - * Convert an instance of {{classname}} to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of {{classname}} to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml index 9e353005e13..0aff5a7c095 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml @@ -2675,3 +2675,22 @@ components: $ref: '#/components/schemas/Pet/properties/status' xml: name: Pet + ArrayOneOf: + oneOf: + - type: integer + - type: array + items: + type: string + ArrayAnyOf: + anyOf: + - type: integer + - type: array + items: + type: string + ModelWithOneOfAnyOfProperties: + type: object + properties: + oneof_prop: + $ref: '#/components/schemas/ArrayOneOf' + anyof_prop: + $ref: '#/components/schemas/ArrayAnyOf' diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java index 98013b8fac2..cc2e5a0564a 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java @@ -74,9 +74,9 @@ public class MyExamplePostRequest extends AbstractOpenApiSchema { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: String"); } @@ -92,17 +92,17 @@ public class MyExamplePostRequest extends AbstractOpenApiSchema { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - match++; - log.log(Level.FINER, "Input data matches schema 'String'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } if (match == 1) { @@ -161,6 +161,7 @@ public class MyExamplePostRequest extends AbstractOpenApiSchema { * * @return The actual instance (String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -177,49 +178,49 @@ public class MyExamplePostRequest extends AbstractOpenApiSchema { return (String)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to MyExamplePostRequest - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to MyExamplePostRequest + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for MyExamplePostRequest with oneOf schemas: String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for MyExamplePostRequest with oneOf schemas: String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + + /** + * Create an instance of MyExamplePostRequest given an JSON string + * + * @param jsonString JSON string + * @return An instance of MyExamplePostRequest + * @throws IOException if the JSON string is invalid with respect to MyExamplePostRequest + */ + public static MyExamplePostRequest fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, MyExamplePostRequest.class); } - } - /** - * Create an instance of MyExamplePostRequest given an JSON string - * - * @param jsonString JSON string - * @return An instance of MyExamplePostRequest - * @throws IOException if the JSON string is invalid with respect to MyExamplePostRequest - */ - public static MyExamplePostRequest fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, MyExamplePostRequest.class); - } - - /** - * Convert an instance of MyExamplePostRequest to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of MyExamplePostRequest to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java index 5784b0654c7..5d03cef6587 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java @@ -76,15 +76,15 @@ public class SimpleOneOf extends AbstractOpenApiSchema implements Serializable { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } // check if the actual instance is of the type `Integer` if (value.getActualInstance() instanceof Integer) { - JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, String"); } @@ -100,31 +100,31 @@ public class SimpleOneOf extends AbstractOpenApiSchema implements Serializable { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - match++; - log.log(Level.FINER, "Input data matches schema 'String'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } // deserialize Integer try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterInteger; - match++; - log.log(Level.FINER, "Input data matches schema 'Integer'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); } if (match == 1) { @@ -194,6 +194,7 @@ public class SimpleOneOf extends AbstractOpenApiSchema implements Serializable { * * @return The actual instance (Integer, String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -220,59 +221,59 @@ public class SimpleOneOf extends AbstractOpenApiSchema implements Serializable { return (Integer)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to SimpleOneOf - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to SimpleOneOf + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for SimpleOneOf with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Integer - try { - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for SimpleOneOf with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of SimpleOneOf given an JSON string - * - * @param jsonString JSON string - * @return An instance of SimpleOneOf - * @throws IOException if the JSON string is invalid with respect to SimpleOneOf - */ - public static SimpleOneOf fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, SimpleOneOf.class); - } + /** + * Create an instance of SimpleOneOf given an JSON string + * + * @param jsonString JSON string + * @return An instance of SimpleOneOf + * @throws IOException if the JSON string is invalid with respect to SimpleOneOf + */ + public static SimpleOneOf fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, SimpleOneOf.class); + } - /** - * Convert an instance of SimpleOneOf to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of SimpleOneOf to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java index 321998b3fbf..53f12a786d5 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java @@ -75,15 +75,15 @@ public class OneOfStringOrInt extends AbstractOpenApiSchema { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } // check if the actual instance is of the type `Integer` if (value.getActualInstance() instanceof Integer) { - JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, String"); } @@ -99,31 +99,31 @@ public class OneOfStringOrInt extends AbstractOpenApiSchema { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - match++; - log.log(Level.FINER, "Input data matches schema 'String'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } // deserialize Integer try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterInteger; - match++; - log.log(Level.FINER, "Input data matches schema 'Integer'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); } if (match == 1) { @@ -193,6 +193,7 @@ public class OneOfStringOrInt extends AbstractOpenApiSchema { * * @return The actual instance (Integer, String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -219,59 +220,59 @@ public class OneOfStringOrInt extends AbstractOpenApiSchema { return (Integer)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to OneOfStringOrInt - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to OneOfStringOrInt + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for OneOfStringOrInt with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Integer - try { - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for OneOfStringOrInt with oneOf schemas: Integer, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of OneOfStringOrInt given an JSON string - * - * @param jsonString JSON string - * @return An instance of OneOfStringOrInt - * @throws IOException if the JSON string is invalid with respect to OneOfStringOrInt - */ - public static OneOfStringOrInt fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, OneOfStringOrInt.class); - } + /** + * Create an instance of OneOfStringOrInt given an JSON string + * + * @param jsonString JSON string + * @return An instance of OneOfStringOrInt + * @throws IOException if the JSON string is invalid with respect to OneOfStringOrInt + */ + public static OneOfStringOrInt fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, OneOfStringOrInt.class); + } - /** - * Convert an instance of OneOfStringOrInt to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of OneOfStringOrInt to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java index 8b58cc46433..81d27429c54 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java @@ -75,17 +75,17 @@ public class StringOrInt extends AbstractOpenApiSchema { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } // check if the actual instance is of the type `Integer` if (value.getActualInstance() instanceof Integer) { - JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } - throw new IOException("Failed to serialize as the type doesn't match anyOf schemae: Integer, String"); + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: Integer, String"); } @Override @@ -98,33 +98,33 @@ public class StringOrInt extends AbstractOpenApiSchema { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - StringOrInt ret = new StringOrInt(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + StringOrInt ret = new StringOrInt(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } // deserialize Integer try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterInteger; - StringOrInt ret = new StringOrInt(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + StringOrInt ret = new StringOrInt(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); } throw new IOException(String.format("Failed deserialization for StringOrInt: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); @@ -188,6 +188,7 @@ public class StringOrInt extends AbstractOpenApiSchema { * * @return The actual instance (Integer, String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -214,57 +215,56 @@ public class StringOrInt extends AbstractOpenApiSchema { return (Integer)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to StringOrInt - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate anyOf schemas one by one - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to StringOrInt + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for StringOrInt with anyOf schemas: Integer, String. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); } - // validate the json string with Integer - try { - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); - // continue to the next one + + /** + * Create an instance of StringOrInt given an JSON string + * + * @param jsonString JSON string + * @return An instance of StringOrInt + * @throws IOException if the JSON string is invalid with respect to StringOrInt + */ + public static StringOrInt fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, StringOrInt.class); } - throw new IOException(String.format("The JSON string is invalid for StringOrInt with anyOf schemas: Integer, String. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); - - } - /** - * Create an instance of StringOrInt given an JSON string - * - * @param jsonString JSON string - * @return An instance of StringOrInt - * @throws IOException if the JSON string is invalid with respect to StringOrInt - */ - public static StringOrInt fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, StringOrInt.class); - } - - /** - * Convert an instance of StringOrInt to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of StringOrInt to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES index 0eaba6aa617..9dd3140d3e4 100644 --- a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES +++ b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES @@ -15,11 +15,13 @@ docs/Animal.md docs/AnotherFakeApi.md docs/Apple.md docs/AppleReq.md +docs/ArrayAnyOf.md docs/ArrayDefault.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfInlineAllOf.md docs/ArrayOfInlineAllOfArrayAllofDogPropertyInner.md docs/ArrayOfNumberOnly.md +docs/ArrayOneOf.md docs/ArrayTest.md docs/Banana.md docs/BananaReq.md @@ -61,6 +63,7 @@ docs/ModelApiResponse.md docs/ModelFile.md docs/ModelList.md docs/ModelReturn.md +docs/ModelWithOneOfAnyOfProperties.md docs/Name.md docs/NewPet.md docs/NewPetCategoryInlineAllof.md @@ -154,11 +157,13 @@ src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListCol src/main/java/org/openapitools/client/model/Animal.java src/main/java/org/openapitools/client/model/Apple.java src/main/java/org/openapitools/client/model/AppleReq.java +src/main/java/org/openapitools/client/model/ArrayAnyOf.java src/main/java/org/openapitools/client/model/ArrayDefault.java src/main/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnly.java src/main/java/org/openapitools/client/model/ArrayOfInlineAllOf.java src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInner.java src/main/java/org/openapitools/client/model/ArrayOfNumberOnly.java +src/main/java/org/openapitools/client/model/ArrayOneOf.java src/main/java/org/openapitools/client/model/ArrayTest.java src/main/java/org/openapitools/client/model/Banana.java src/main/java/org/openapitools/client/model/BananaReq.java @@ -197,6 +202,7 @@ src/main/java/org/openapitools/client/model/ModelApiResponse.java src/main/java/org/openapitools/client/model/ModelFile.java src/main/java/org/openapitools/client/model/ModelList.java src/main/java/org/openapitools/client/model/ModelReturn.java +src/main/java/org/openapitools/client/model/ModelWithOneOfAnyOfProperties.java src/main/java/org/openapitools/client/model/Name.java src/main/java/org/openapitools/client/model/NewPet.java src/main/java/org/openapitools/client/model/NewPetCategoryInlineAllof.java diff --git a/samples/client/petstore/java/okhttp-gson/README.md b/samples/client/petstore/java/okhttp-gson/README.md index 63c167c60e8..d777df97097 100644 --- a/samples/client/petstore/java/okhttp-gson/README.md +++ b/samples/client/petstore/java/okhttp-gson/README.md @@ -175,11 +175,13 @@ Class | Method | HTTP request | Description - [Animal](docs/Animal.md) - [Apple](docs/Apple.md) - [AppleReq](docs/AppleReq.md) + - [ArrayAnyOf](docs/ArrayAnyOf.md) - [ArrayDefault](docs/ArrayDefault.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfInlineAllOf](docs/ArrayOfInlineAllOf.md) - [ArrayOfInlineAllOfArrayAllofDogPropertyInner](docs/ArrayOfInlineAllOfArrayAllofDogPropertyInner.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) + - [ArrayOneOf](docs/ArrayOneOf.md) - [ArrayTest](docs/ArrayTest.md) - [Banana](docs/Banana.md) - [BananaReq](docs/BananaReq.md) @@ -218,6 +220,7 @@ Class | Method | HTTP request | Description - [ModelFile](docs/ModelFile.md) - [ModelList](docs/ModelList.md) - [ModelReturn](docs/ModelReturn.md) + - [ModelWithOneOfAnyOfProperties](docs/ModelWithOneOfAnyOfProperties.md) - [Name](docs/Name.md) - [NewPet](docs/NewPet.md) - [NewPetCategoryInlineAllof](docs/NewPetCategoryInlineAllof.md) diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 7a956b341e4..131f50a9165 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -2711,6 +2711,25 @@ components: type: object xml: name: Pet + ArrayOneOf: + oneOf: + - type: integer + - items: + type: string + type: array + ArrayAnyOf: + anyOf: + - type: integer + - items: + type: string + type: array + ModelWithOneOfAnyOfProperties: + properties: + oneof_prop: + $ref: '#/components/schemas/ArrayOneOf' + anyof_prop: + $ref: '#/components/schemas/ArrayAnyOf' + type: object _foo_get_default_response: example: string: diff --git a/samples/client/petstore/java/okhttp-gson/docs/ArrayAnyOf.md b/samples/client/petstore/java/okhttp-gson/docs/ArrayAnyOf.md new file mode 100644 index 00000000000..86bb944833a --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/ArrayAnyOf.md @@ -0,0 +1,12 @@ + + +# ArrayAnyOf + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson/docs/ArrayOneOf.md b/samples/client/petstore/java/okhttp-gson/docs/ArrayOneOf.md new file mode 100644 index 00000000000..34727d5f730 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/ArrayOneOf.md @@ -0,0 +1,12 @@ + + +# ArrayOneOf + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| + + + diff --git a/samples/client/petstore/java/okhttp-gson/docs/ModelWithOneOfAnyOfProperties.md b/samples/client/petstore/java/okhttp-gson/docs/ModelWithOneOfAnyOfProperties.md new file mode 100644 index 00000000000..64c1206365f --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/docs/ModelWithOneOfAnyOfProperties.md @@ -0,0 +1,14 @@ + + +# ModelWithOneOfAnyOfProperties + + +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +|**oneofProp** | [**ArrayOneOf**](ArrayOneOf.md) | | [optional] | +|**anyofProp** | [**ArrayAnyOf**](ArrayAnyOf.md) | | [optional] | + + + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index 767d24dc316..60c3ef11d94 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -244,11 +244,13 @@ public class JSON { gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AllOfModelArrayAnyOfAllOfLinkListColumn1Value.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Apple.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.AppleReq.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayAnyOf.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayDefault.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfArrayOfNumberOnly.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfInlineAllOf.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyInner.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOfNumberOnly.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayOneOf.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ArrayTest.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Banana.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.BananaReq.CustomTypeAdapterFactory()); @@ -285,6 +287,7 @@ public class JSON { gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ModelFile.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ModelList.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ModelReturn.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ModelWithOneOfAnyOfProperties.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Name.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.NewPet.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.NewPetCategoryInlineAllof.CustomTypeAdapterFactory()); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java index 094f6dbaea5..bd96c14910d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java @@ -89,15 +89,15 @@ public class AllOfModelArrayAnyOfAllOfAttributesC extends AbstractOpenApiSchema // check if the actual instance is of the type `Pet` if (value.getActualInstance() instanceof Pet) { - JsonElement element = adapterPet.toJsonTree((Pet)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterPet.toJsonTree((Pet)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Order` if (value.getActualInstance() instanceof Order) { - JsonElement element = adapterOrder.toJsonTree((Order)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterOrder.toJsonTree((Order)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Order, Pet"); } @@ -113,27 +113,27 @@ public class AllOfModelArrayAnyOfAllOfAttributesC extends AbstractOpenApiSchema // deserialize Pet try { - // validate the JSON object to see if any exception is thrown - Pet.validateJsonElement(jsonElement); - actualAdapter = adapterPet; - match++; - log.log(Level.FINER, "Input data matches schema 'Pet'"); + // validate the JSON object to see if any exception is thrown + Pet.validateJsonElement(jsonElement); + actualAdapter = adapterPet; + match++; + log.log(Level.FINER, "Input data matches schema 'Pet'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Pet'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Pet'", e); } // deserialize Order try { - // validate the JSON object to see if any exception is thrown - Order.validateJsonElement(jsonElement); - actualAdapter = adapterOrder; - match++; - log.log(Level.FINER, "Input data matches schema 'Order'"); + // validate the JSON object to see if any exception is thrown + Order.validateJsonElement(jsonElement); + actualAdapter = adapterOrder; + match++; + log.log(Level.FINER, "Input data matches schema 'Order'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Order'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Order'", e); } if (match == 1) { @@ -203,6 +203,7 @@ public class AllOfModelArrayAnyOfAllOfAttributesC extends AbstractOpenApiSchema * * @return The actual instance (Order, Pet) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -229,55 +230,55 @@ public class AllOfModelArrayAnyOfAllOfAttributesC extends AbstractOpenApiSchema return (Order)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to AllOfModelArrayAnyOfAllOfAttributesC - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Pet - try { - Pet.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to AllOfModelArrayAnyOfAllOfAttributesC + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Pet + try { + Pet.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Pet failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Order + try { + Order.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for AllOfModelArrayAnyOfAllOfAttributesC with oneOf schemas: Order, Pet. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Order - try { - Order.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Order failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for AllOfModelArrayAnyOfAllOfAttributesC with oneOf schemas: Order, Pet. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of AllOfModelArrayAnyOfAllOfAttributesC given an JSON string - * - * @param jsonString JSON string - * @return An instance of AllOfModelArrayAnyOfAllOfAttributesC - * @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfAttributesC - */ - public static AllOfModelArrayAnyOfAllOfAttributesC fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfAttributesC.class); - } + /** + * Create an instance of AllOfModelArrayAnyOfAllOfAttributesC given an JSON string + * + * @param jsonString JSON string + * @return An instance of AllOfModelArrayAnyOfAllOfAttributesC + * @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfAttributesC + */ + public static AllOfModelArrayAnyOfAllOfAttributesC fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfAttributesC.class); + } - /** - * Convert an instance of AllOfModelArrayAnyOfAllOfAttributesC to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of AllOfModelArrayAnyOfAllOfAttributesC to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java index 6b5f872816a..f610b39d56d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java @@ -85,17 +85,17 @@ public class AllOfModelArrayAnyOfAllOfLinkListColumn1Value extends AbstractOpenA // check if the actual instance is of the type `User` if (value.getActualInstance() instanceof User) { - JsonElement element = adapterUser.toJsonTree((User)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterUser.toJsonTree((User)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Tag` if (value.getActualInstance() instanceof Tag) { - JsonElement element = adapterTag.toJsonTree((Tag)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterTag.toJsonTree((Tag)value.getActualInstance()); + elementAdapter.write(out, element); + return; } - throw new IOException("Failed to serialize as the type doesn't match anyOf schemae: Tag, User"); + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: Tag, User"); } @Override @@ -108,29 +108,29 @@ public class AllOfModelArrayAnyOfAllOfLinkListColumn1Value extends AbstractOpenA // deserialize User try { - // validate the JSON object to see if any exception is thrown - User.validateJsonElement(jsonElement); - actualAdapter = adapterUser; - AllOfModelArrayAnyOfAllOfLinkListColumn1Value ret = new AllOfModelArrayAnyOfAllOfLinkListColumn1Value(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + User.validateJsonElement(jsonElement); + actualAdapter = adapterUser; + AllOfModelArrayAnyOfAllOfLinkListColumn1Value ret = new AllOfModelArrayAnyOfAllOfLinkListColumn1Value(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for User failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'User'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for User failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'User'", e); } // deserialize Tag try { - // validate the JSON object to see if any exception is thrown - Tag.validateJsonElement(jsonElement); - actualAdapter = adapterTag; - AllOfModelArrayAnyOfAllOfLinkListColumn1Value ret = new AllOfModelArrayAnyOfAllOfLinkListColumn1Value(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + Tag.validateJsonElement(jsonElement); + actualAdapter = adapterTag; + AllOfModelArrayAnyOfAllOfLinkListColumn1Value ret = new AllOfModelArrayAnyOfAllOfLinkListColumn1Value(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Tag failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Tag'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Tag failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Tag'", e); } throw new IOException(String.format("Failed deserialization for AllOfModelArrayAnyOfAllOfLinkListColumn1Value: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); @@ -194,6 +194,7 @@ public class AllOfModelArrayAnyOfAllOfLinkListColumn1Value extends AbstractOpenA * * @return The actual instance (Tag, User) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -220,53 +221,52 @@ public class AllOfModelArrayAnyOfAllOfLinkListColumn1Value extends AbstractOpenA return (Tag)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to AllOfModelArrayAnyOfAllOfLinkListColumn1Value - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate anyOf schemas one by one - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with User - try { - User.validateJsonElement(jsonElement); - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for User failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to AllOfModelArrayAnyOfAllOfLinkListColumn1Value + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with User + try { + User.validateJsonElement(jsonElement); + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for User failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Tag + try { + Tag.validateJsonElement(jsonElement); + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Tag failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for AllOfModelArrayAnyOfAllOfLinkListColumn1Value with anyOf schemas: Tag, User. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); } - // validate the json string with Tag - try { - Tag.validateJsonElement(jsonElement); - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Tag failed with `%s`.", e.getMessage())); - // continue to the next one + + /** + * Create an instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value given an JSON string + * + * @param jsonString JSON string + * @return An instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value + * @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfLinkListColumn1Value + */ + public static AllOfModelArrayAnyOfAllOfLinkListColumn1Value fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfLinkListColumn1Value.class); } - throw new IOException(String.format("The JSON string is invalid for AllOfModelArrayAnyOfAllOfLinkListColumn1Value with anyOf schemas: Tag, User. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); - - } - /** - * Create an instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value given an JSON string - * - * @param jsonString JSON string - * @return An instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value - * @throws IOException if the JSON string is invalid with respect to AllOfModelArrayAnyOfAllOfLinkListColumn1Value - */ - public static AllOfModelArrayAnyOfAllOfLinkListColumn1Value fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, AllOfModelArrayAnyOfAllOfLinkListColumn1Value.class); - } - - /** - * Convert an instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of AllOfModelArrayAnyOfAllOfLinkListColumn1Value to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java new file mode 100644 index 00000000000..2d820dbb5e7 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java @@ -0,0 +1,291 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.Objects; +import java.util.List; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.5.0-SNAPSHOT") +public class ArrayAnyOf extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(ArrayAnyOf.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!ArrayAnyOf.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'ArrayAnyOf' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, ArrayAnyOf value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `Integer` + if (value.getActualInstance() instanceof Integer) { + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `List` + if (value.getActualInstance() instanceof List) { + JsonPrimitive primitive = adapterListString.toJsonTree((List)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: Integer, List"); + } + + @Override + public ArrayAnyOf read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize Integer + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + ArrayAnyOf ret = new ArrayAnyOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + } + // deserialize List + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + actualAdapter = adapterListString; + ArrayAnyOf ret = new ArrayAnyOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); + } + + throw new IOException(String.format("Failed deserialization for ArrayAnyOf: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in anyOf + public static final Map> schemas = new HashMap>(); + + public ArrayAnyOf() { + super("anyOf", Boolean.FALSE); + } + + public ArrayAnyOf(Integer o) { + super("anyOf", Boolean.FALSE); + setActualInstance(o); + } + + public ArrayAnyOf(List o) { + super("anyOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("Integer", Integer.class); + schemas.put("List", List.class); + } + + @Override + public Map> getSchemas() { + return ArrayAnyOf.schemas; + } + + /** + * Set the instance that matches the anyOf child schema, check + * the instance parameter is valid against the anyOf child schemas: + * Integer, List + * + * It could be an instance of the 'anyOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof Integer) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof List) { + List list = (List) instance; + if (list.get(0) instanceof String) { + super.setActualInstance(instance); + return; + } + } + + throw new RuntimeException("Invalid instance type. Must be Integer, List"); + } + + /** + * Get the actual instance, which can be the following: + * Integer, List + * + * @return The actual instance (Integer, List) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `Integer`. If the actual instance is not `Integer`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Integer` + * @throws ClassCastException if the instance is not `Integer` + */ + public Integer getInteger() throws ClassCastException { + return (Integer)super.getActualInstance(); + } + /** + * Get the actual instance of `List`. If the actual instance is not `List`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `List` + * @throws ClassCastException if the instance is not `List` + */ + public List getListString() throws ClassCastException { + return (List)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to ArrayAnyOf + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for ArrayAnyOf with anyOf schemas: Integer, List. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); + } + + /** + * Create an instance of ArrayAnyOf given an JSON string + * + * @param jsonString JSON string + * @return An instance of ArrayAnyOf + * @throws IOException if the JSON string is invalid with respect to ArrayAnyOf + */ + public static ArrayAnyOf fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, ArrayAnyOf.class); + } + + /** + * Convert an instance of ArrayAnyOf to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java new file mode 100644 index 00000000000..d575a3841be --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java @@ -0,0 +1,299 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.Objects; +import java.util.List; + + + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonPrimitive; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonParseException; + +import org.openapitools.client.JSON; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.5.0-SNAPSHOT") +public class ArrayOneOf extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(ArrayOneOf.class.getName()); + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!ArrayOneOf.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'ArrayOneOf' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter adapterInteger = gson.getDelegateAdapter(this, TypeToken.get(Integer.class)); + + final Type typeInstance = new TypeToken>(){}.getType(); + final TypeAdapter> adapterListString = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, ArrayOneOf value) throws IOException { + if (value == null || value.getActualInstance() == null) { + elementAdapter.write(out, null); + return; + } + + // check if the actual instance is of the type `Integer` + if (value.getActualInstance() instanceof Integer) { + JsonPrimitive primitive = adapterInteger.toJsonTree((Integer)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + // check if the actual instance is of the type `List` + if (value.getActualInstance() instanceof List) { + JsonPrimitive primitive = adapterListString.toJsonTree((List)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; + } + throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Integer, List"); + } + + @Override + public ArrayOneOf read(JsonReader in) throws IOException { + Object deserialized = null; + JsonElement jsonElement = elementAdapter.read(in); + + int match = 0; + ArrayList errorMessages = new ArrayList<>(); + TypeAdapter actualAdapter = elementAdapter; + + // deserialize Integer + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterInteger; + match++; + log.log(Level.FINER, "Input data matches schema 'Integer'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Integer'", e); + } + // deserialize List + try { + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + actualAdapter = adapterListString; + match++; + log.log(Level.FINER, "Input data matches schema 'List'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); + } + + if (match == 1) { + ArrayOneOf ret = new ArrayOneOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; + } + + throw new IOException(String.format("Failed deserialization for ArrayOneOf: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString())); + } + }.nullSafe(); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap>(); + + public ArrayOneOf() { + super("oneOf", Boolean.FALSE); + } + + public ArrayOneOf(Integer o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public ArrayOneOf(List o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("Integer", Integer.class); + schemas.put("List", List.class); + } + + @Override + public Map> getSchemas() { + return ArrayOneOf.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check + * the instance parameter is valid against the oneOf child schemas: + * Integer, List + * + * It could be an instance of the 'oneOf' schemas. + */ + @Override + public void setActualInstance(Object instance) { + if (instance instanceof Integer) { + super.setActualInstance(instance); + return; + } + + if (instance instanceof List) { + List list = (List) instance; + if (list.get(0) instanceof String) { + super.setActualInstance(instance); + return; + } + } + + throw new RuntimeException("Invalid instance type. Must be Integer, List"); + } + + /** + * Get the actual instance, which can be the following: + * Integer, List + * + * @return The actual instance (Integer, List) + */ + @SuppressWarnings("unchecked") + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `Integer`. If the actual instance is not `Integer`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Integer` + * @throws ClassCastException if the instance is not `Integer` + */ + public Integer getInteger() throws ClassCastException { + return (Integer)super.getActualInstance(); + } + /** + * Get the actual instance of `List`. If the actual instance is not `List`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `List` + * @throws ClassCastException if the instance is not `List` + */ + public List getListString() throws ClassCastException { + return (List)super.getActualInstance(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to ArrayOneOf + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Integer + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Integer failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + if (!element.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected array items to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for ArrayOneOf with oneOf schemas: Integer, List. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } + } + + /** + * Create an instance of ArrayOneOf given an JSON string + * + * @param jsonString JSON string + * @return An instance of ArrayOneOf + * @throws IOException if the JSON string is invalid with respect to ArrayOneOf + */ + public static ArrayOneOf fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, ArrayOneOf.class); + } + + /** + * Convert an instance of ArrayOneOf to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java index f7755a88b18..1c42830908a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java @@ -85,15 +85,15 @@ public class Fruit extends AbstractOpenApiSchema { // check if the actual instance is of the type `Apple` if (value.getActualInstance() instanceof Apple) { - JsonElement element = adapterApple.toJsonTree((Apple)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterApple.toJsonTree((Apple)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Banana` if (value.getActualInstance() instanceof Banana) { - JsonElement element = adapterBanana.toJsonTree((Banana)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBanana.toJsonTree((Banana)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Apple, Banana"); } @@ -109,27 +109,27 @@ public class Fruit extends AbstractOpenApiSchema { // deserialize Apple try { - // validate the JSON object to see if any exception is thrown - Apple.validateJsonElement(jsonElement); - actualAdapter = adapterApple; - match++; - log.log(Level.FINER, "Input data matches schema 'Apple'"); + // validate the JSON object to see if any exception is thrown + Apple.validateJsonElement(jsonElement); + actualAdapter = adapterApple; + match++; + log.log(Level.FINER, "Input data matches schema 'Apple'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Apple'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Apple'", e); } // deserialize Banana try { - // validate the JSON object to see if any exception is thrown - Banana.validateJsonElement(jsonElement); - actualAdapter = adapterBanana; - match++; - log.log(Level.FINER, "Input data matches schema 'Banana'"); + // validate the JSON object to see if any exception is thrown + Banana.validateJsonElement(jsonElement); + actualAdapter = adapterBanana; + match++; + log.log(Level.FINER, "Input data matches schema 'Banana'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Banana'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Banana'", e); } if (match == 1) { @@ -199,6 +199,7 @@ public class Fruit extends AbstractOpenApiSchema { * * @return The actual instance (Apple, Banana) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -225,55 +226,55 @@ public class Fruit extends AbstractOpenApiSchema { return (Banana)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Fruit - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Apple - try { - Apple.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Fruit + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Apple + try { + Apple.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Banana + try { + Banana.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Fruit with oneOf schemas: Apple, Banana. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Banana - try { - Banana.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Fruit with oneOf schemas: Apple, Banana. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Fruit given an JSON string - * - * @param jsonString JSON string - * @return An instance of Fruit - * @throws IOException if the JSON string is invalid with respect to Fruit - */ - public static Fruit fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Fruit.class); - } + /** + * Create an instance of Fruit given an JSON string + * + * @param jsonString JSON string + * @return An instance of Fruit + * @throws IOException if the JSON string is invalid with respect to Fruit + */ + public static Fruit fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Fruit.class); + } - /** - * Convert an instance of Fruit to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Fruit to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java index 82b02f4b698..a008129f8a2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java @@ -85,15 +85,15 @@ public class FruitReq extends AbstractOpenApiSchema { // check if the actual instance is of the type `AppleReq` if (value.getActualInstance() instanceof AppleReq) { - JsonElement element = adapterAppleReq.toJsonTree((AppleReq)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterAppleReq.toJsonTree((AppleReq)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `BananaReq` if (value.getActualInstance() instanceof BananaReq) { - JsonElement element = adapterBananaReq.toJsonTree((BananaReq)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBananaReq.toJsonTree((BananaReq)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: AppleReq, BananaReq"); } @@ -109,27 +109,27 @@ public class FruitReq extends AbstractOpenApiSchema { // deserialize AppleReq try { - // validate the JSON object to see if any exception is thrown - AppleReq.validateJsonElement(jsonElement); - actualAdapter = adapterAppleReq; - match++; - log.log(Level.FINER, "Input data matches schema 'AppleReq'"); + // validate the JSON object to see if any exception is thrown + AppleReq.validateJsonElement(jsonElement); + actualAdapter = adapterAppleReq; + match++; + log.log(Level.FINER, "Input data matches schema 'AppleReq'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for AppleReq failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'AppleReq'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for AppleReq failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'AppleReq'", e); } // deserialize BananaReq try { - // validate the JSON object to see if any exception is thrown - BananaReq.validateJsonElement(jsonElement); - actualAdapter = adapterBananaReq; - match++; - log.log(Level.FINER, "Input data matches schema 'BananaReq'"); + // validate the JSON object to see if any exception is thrown + BananaReq.validateJsonElement(jsonElement); + actualAdapter = adapterBananaReq; + match++; + log.log(Level.FINER, "Input data matches schema 'BananaReq'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for BananaReq failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'BananaReq'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for BananaReq failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'BananaReq'", e); } if (match == 1) { @@ -204,6 +204,7 @@ public class FruitReq extends AbstractOpenApiSchema { * * @return The actual instance (AppleReq, BananaReq) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -230,55 +231,55 @@ public class FruitReq extends AbstractOpenApiSchema { return (BananaReq)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to FruitReq - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with AppleReq - try { - AppleReq.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for AppleReq failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to FruitReq + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with AppleReq + try { + AppleReq.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for AppleReq failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with BananaReq + try { + BananaReq.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for BananaReq failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for FruitReq with oneOf schemas: AppleReq, BananaReq. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with BananaReq - try { - BananaReq.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for BananaReq failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for FruitReq with oneOf schemas: AppleReq, BananaReq. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of FruitReq given an JSON string - * - * @param jsonString JSON string - * @return An instance of FruitReq - * @throws IOException if the JSON string is invalid with respect to FruitReq - */ - public static FruitReq fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, FruitReq.class); - } + /** + * Create an instance of FruitReq given an JSON string + * + * @param jsonString JSON string + * @return An instance of FruitReq + * @throws IOException if the JSON string is invalid with respect to FruitReq + */ + public static FruitReq fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, FruitReq.class); + } - /** - * Convert an instance of FruitReq to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of FruitReq to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java index c1ba3346850..1def104f647 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java @@ -85,17 +85,17 @@ public class GmFruit extends AbstractOpenApiSchema { // check if the actual instance is of the type `Apple` if (value.getActualInstance() instanceof Apple) { - JsonElement element = adapterApple.toJsonTree((Apple)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterApple.toJsonTree((Apple)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Banana` if (value.getActualInstance() instanceof Banana) { - JsonElement element = adapterBanana.toJsonTree((Banana)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBanana.toJsonTree((Banana)value.getActualInstance()); + elementAdapter.write(out, element); + return; } - throw new IOException("Failed to serialize as the type doesn't match anyOf schemae: Apple, Banana"); + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: Apple, Banana"); } @Override @@ -108,29 +108,29 @@ public class GmFruit extends AbstractOpenApiSchema { // deserialize Apple try { - // validate the JSON object to see if any exception is thrown - Apple.validateJsonElement(jsonElement); - actualAdapter = adapterApple; - GmFruit ret = new GmFruit(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + Apple.validateJsonElement(jsonElement); + actualAdapter = adapterApple; + GmFruit ret = new GmFruit(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Apple'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Apple'", e); } // deserialize Banana try { - // validate the JSON object to see if any exception is thrown - Banana.validateJsonElement(jsonElement); - actualAdapter = adapterBanana; - GmFruit ret = new GmFruit(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + Banana.validateJsonElement(jsonElement); + actualAdapter = adapterBanana; + GmFruit ret = new GmFruit(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Banana'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Banana'", e); } throw new IOException(String.format("Failed deserialization for GmFruit: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); @@ -194,6 +194,7 @@ public class GmFruit extends AbstractOpenApiSchema { * * @return The actual instance (Apple, Banana) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -220,53 +221,52 @@ public class GmFruit extends AbstractOpenApiSchema { return (Banana)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to GmFruit - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate anyOf schemas one by one - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Apple - try { - Apple.validateJsonElement(jsonElement); - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to GmFruit + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Apple + try { + Apple.validateJsonElement(jsonElement); + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Apple failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Banana + try { + Banana.validateJsonElement(jsonElement); + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for GmFruit with anyOf schemas: Apple, Banana. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); } - // validate the json string with Banana - try { - Banana.validateJsonElement(jsonElement); - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Banana failed with `%s`.", e.getMessage())); - // continue to the next one + + /** + * Create an instance of GmFruit given an JSON string + * + * @param jsonString JSON string + * @return An instance of GmFruit + * @throws IOException if the JSON string is invalid with respect to GmFruit + */ + public static GmFruit fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, GmFruit.class); } - throw new IOException(String.format("The JSON string is invalid for GmFruit with anyOf schemas: Apple, Banana. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); - - } - /** - * Create an instance of GmFruit given an JSON string - * - * @param jsonString JSON string - * @return An instance of GmFruit - * @throws IOException if the JSON string is invalid with respect to GmFruit - */ - public static GmFruit fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, GmFruit.class); - } - - /** - * Convert an instance of GmFruit to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of GmFruit to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java index 4db3b05c747..deb6d7ec978 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java @@ -86,21 +86,21 @@ public class Mammal extends AbstractOpenApiSchema { // check if the actual instance is of the type `Whale` if (value.getActualInstance() instanceof Whale) { - JsonElement element = adapterWhale.toJsonTree((Whale)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterWhale.toJsonTree((Whale)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Zebra` if (value.getActualInstance() instanceof Zebra) { - JsonElement element = adapterZebra.toJsonTree((Zebra)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterZebra.toJsonTree((Zebra)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Pig` if (value.getActualInstance() instanceof Pig) { - JsonElement element = adapterPig.toJsonTree((Pig)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterPig.toJsonTree((Pig)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Pig, Whale, Zebra"); } @@ -142,39 +142,39 @@ public class Mammal extends AbstractOpenApiSchema { // deserialize Whale try { - // validate the JSON object to see if any exception is thrown - Whale.validateJsonElement(jsonElement); - actualAdapter = adapterWhale; - match++; - log.log(Level.FINER, "Input data matches schema 'Whale'"); + // validate the JSON object to see if any exception is thrown + Whale.validateJsonElement(jsonElement); + actualAdapter = adapterWhale; + match++; + log.log(Level.FINER, "Input data matches schema 'Whale'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Whale failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Whale'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Whale failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Whale'", e); } // deserialize Zebra try { - // validate the JSON object to see if any exception is thrown - Zebra.validateJsonElement(jsonElement); - actualAdapter = adapterZebra; - match++; - log.log(Level.FINER, "Input data matches schema 'Zebra'"); + // validate the JSON object to see if any exception is thrown + Zebra.validateJsonElement(jsonElement); + actualAdapter = adapterZebra; + match++; + log.log(Level.FINER, "Input data matches schema 'Zebra'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Zebra failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Zebra'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Zebra failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Zebra'", e); } // deserialize Pig try { - // validate the JSON object to see if any exception is thrown - Pig.validateJsonElement(jsonElement); - actualAdapter = adapterPig; - match++; - log.log(Level.FINER, "Input data matches schema 'Pig'"); + // validate the JSON object to see if any exception is thrown + Pig.validateJsonElement(jsonElement); + actualAdapter = adapterPig; + match++; + log.log(Level.FINER, "Input data matches schema 'Pig'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Pig failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Pig'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Pig failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Pig'", e); } if (match == 1) { @@ -255,6 +255,7 @@ public class Mammal extends AbstractOpenApiSchema { * * @return The actual instance (Pig, Whale, Zebra) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -291,63 +292,63 @@ public class Mammal extends AbstractOpenApiSchema { return (Pig)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Mammal - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Whale - try { - Whale.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Whale failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Mammal + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Whale + try { + Whale.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Whale failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Zebra + try { + Zebra.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Zebra failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Pig + try { + Pig.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Pig failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Mammal with oneOf schemas: Pig, Whale, Zebra. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Zebra - try { - Zebra.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Zebra failed with `%s`.", e.getMessage())); - // continue to the next one - } - // validate the json string with Pig - try { - Pig.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Pig failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Mammal with oneOf schemas: Pig, Whale, Zebra. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Mammal given an JSON string - * - * @param jsonString JSON string - * @return An instance of Mammal - * @throws IOException if the JSON string is invalid with respect to Mammal - */ - public static Mammal fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Mammal.class); - } + /** + * Create an instance of Mammal given an JSON string + * + * @param jsonString JSON string + * @return An instance of Mammal + * @throws IOException if the JSON string is invalid with respect to Mammal + */ + public static Mammal fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Mammal.class); + } - /** - * Convert an instance of Mammal to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Mammal to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ModelWithOneOfAnyOfProperties.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ModelWithOneOfAnyOfProperties.java new file mode 100644 index 00000000000..9678ef3da5d --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ModelWithOneOfAnyOfProperties.java @@ -0,0 +1,320 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import org.openapitools.client.model.ArrayAnyOf; +import org.openapitools.client.model.ArrayOneOf; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.openapitools.client.JSON; + +/** + * ModelWithOneOfAnyOfProperties + */ +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.5.0-SNAPSHOT") +public class ModelWithOneOfAnyOfProperties { + public static final String SERIALIZED_NAME_ONEOF_PROP = "oneof_prop"; + @SerializedName(SERIALIZED_NAME_ONEOF_PROP) + private ArrayOneOf oneofProp; + + public static final String SERIALIZED_NAME_ANYOF_PROP = "anyof_prop"; + @SerializedName(SERIALIZED_NAME_ANYOF_PROP) + private ArrayAnyOf anyofProp; + + public ModelWithOneOfAnyOfProperties() { + } + + public ModelWithOneOfAnyOfProperties oneofProp(ArrayOneOf oneofProp) { + this.oneofProp = oneofProp; + return this; + } + + /** + * Get oneofProp + * @return oneofProp + **/ + @javax.annotation.Nullable + public ArrayOneOf getOneofProp() { + return oneofProp; + } + + public void setOneofProp(ArrayOneOf oneofProp) { + this.oneofProp = oneofProp; + } + + + public ModelWithOneOfAnyOfProperties anyofProp(ArrayAnyOf anyofProp) { + this.anyofProp = anyofProp; + return this; + } + + /** + * Get anyofProp + * @return anyofProp + **/ + @javax.annotation.Nullable + public ArrayAnyOf getAnyofProp() { + return anyofProp; + } + + public void setAnyofProp(ArrayAnyOf anyofProp) { + this.anyofProp = anyofProp; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the ModelWithOneOfAnyOfProperties instance itself + */ + public ModelWithOneOfAnyOfProperties putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelWithOneOfAnyOfProperties modelWithOneOfAnyOfProperties = (ModelWithOneOfAnyOfProperties) o; + return Objects.equals(this.oneofProp, modelWithOneOfAnyOfProperties.oneofProp) && + Objects.equals(this.anyofProp, modelWithOneOfAnyOfProperties.anyofProp)&& + Objects.equals(this.additionalProperties, modelWithOneOfAnyOfProperties.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(oneofProp, anyofProp, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelWithOneOfAnyOfProperties {\n"); + sb.append(" oneofProp: ").append(toIndentedString(oneofProp)).append("\n"); + sb.append(" anyofProp: ").append(toIndentedString(anyofProp)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(); + openapiFields.add("oneof_prop"); + openapiFields.add("anyof_prop"); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to ModelWithOneOfAnyOfProperties + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!ModelWithOneOfAnyOfProperties.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format("The required field(s) %s in ModelWithOneOfAnyOfProperties is not found in the empty JSON string", ModelWithOneOfAnyOfProperties.openapiRequiredFields.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // validate the optional field `oneof_prop` + if (jsonObj.get("oneof_prop") != null && !jsonObj.get("oneof_prop").isJsonNull()) { + ArrayOneOf.validateJsonElement(jsonObj.get("oneof_prop")); + } + // validate the optional field `anyof_prop` + if (jsonObj.get("anyof_prop") != null && !jsonObj.get("anyof_prop").isJsonNull()) { + ArrayAnyOf.validateJsonElement(jsonObj.get("anyof_prop")); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!ModelWithOneOfAnyOfProperties.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'ModelWithOneOfAnyOfProperties' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(ModelWithOneOfAnyOfProperties.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, ModelWithOneOfAnyOfProperties value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public ModelWithOneOfAnyOfProperties read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + ModelWithOneOfAnyOfProperties instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of ModelWithOneOfAnyOfProperties given an JSON string + * + * @param jsonString JSON string + * @return An instance of ModelWithOneOfAnyOfProperties + * @throws IOException if the JSON string is invalid with respect to ModelWithOneOfAnyOfProperties + */ + public static ModelWithOneOfAnyOfProperties fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, ModelWithOneOfAnyOfProperties.class); + } + + /** + * Convert an instance of ModelWithOneOfAnyOfProperties to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java index 82bd4c82bea..19d439e1c07 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java @@ -84,15 +84,15 @@ public class NullableShape extends AbstractOpenApiSchema { // check if the actual instance is of the type `Triangle` if (value.getActualInstance() instanceof Triangle) { - JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Quadrilateral` if (value.getActualInstance() instanceof Quadrilateral) { - JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Quadrilateral, Triangle"); } @@ -130,27 +130,27 @@ public class NullableShape extends AbstractOpenApiSchema { // deserialize Triangle try { - // validate the JSON object to see if any exception is thrown - Triangle.validateJsonElement(jsonElement); - actualAdapter = adapterTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'Triangle'"); + // validate the JSON object to see if any exception is thrown + Triangle.validateJsonElement(jsonElement); + actualAdapter = adapterTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'Triangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } // deserialize Quadrilateral try { - // validate the JSON object to see if any exception is thrown - Quadrilateral.validateJsonElement(jsonElement); - actualAdapter = adapterQuadrilateral; - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + // validate the JSON object to see if any exception is thrown + Quadrilateral.validateJsonElement(jsonElement); + actualAdapter = adapterQuadrilateral; + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); } if (match == 1) { @@ -225,6 +225,7 @@ public class NullableShape extends AbstractOpenApiSchema { * * @return The actual instance (Quadrilateral, Triangle) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -251,55 +252,55 @@ public class NullableShape extends AbstractOpenApiSchema { return (Quadrilateral)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to NullableShape - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Triangle - try { - Triangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to NullableShape + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Triangle + try { + Triangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Quadrilateral + try { + Quadrilateral.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for NullableShape with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Quadrilateral - try { - Quadrilateral.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for NullableShape with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of NullableShape given an JSON string - * - * @param jsonString JSON string - * @return An instance of NullableShape - * @throws IOException if the JSON string is invalid with respect to NullableShape - */ - public static NullableShape fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, NullableShape.class); - } + /** + * Create an instance of NullableShape given an JSON string + * + * @param jsonString JSON string + * @return An instance of NullableShape + * @throws IOException if the JSON string is invalid with respect to NullableShape + */ + public static NullableShape fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, NullableShape.class); + } - /** - * Convert an instance of NullableShape to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of NullableShape to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java index 5c8c3642175..79e62f6dad1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java @@ -84,15 +84,15 @@ public class Pig extends AbstractOpenApiSchema { // check if the actual instance is of the type `BasquePig` if (value.getActualInstance() instanceof BasquePig) { - JsonElement element = adapterBasquePig.toJsonTree((BasquePig)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBasquePig.toJsonTree((BasquePig)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `DanishPig` if (value.getActualInstance() instanceof DanishPig) { - JsonElement element = adapterDanishPig.toJsonTree((DanishPig)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterDanishPig.toJsonTree((DanishPig)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: BasquePig, DanishPig"); } @@ -130,27 +130,27 @@ public class Pig extends AbstractOpenApiSchema { // deserialize BasquePig try { - // validate the JSON object to see if any exception is thrown - BasquePig.validateJsonElement(jsonElement); - actualAdapter = adapterBasquePig; - match++; - log.log(Level.FINER, "Input data matches schema 'BasquePig'"); + // validate the JSON object to see if any exception is thrown + BasquePig.validateJsonElement(jsonElement); + actualAdapter = adapterBasquePig; + match++; + log.log(Level.FINER, "Input data matches schema 'BasquePig'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for BasquePig failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'BasquePig'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for BasquePig failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'BasquePig'", e); } // deserialize DanishPig try { - // validate the JSON object to see if any exception is thrown - DanishPig.validateJsonElement(jsonElement); - actualAdapter = adapterDanishPig; - match++; - log.log(Level.FINER, "Input data matches schema 'DanishPig'"); + // validate the JSON object to see if any exception is thrown + DanishPig.validateJsonElement(jsonElement); + actualAdapter = adapterDanishPig; + match++; + log.log(Level.FINER, "Input data matches schema 'DanishPig'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for DanishPig failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'DanishPig'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for DanishPig failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'DanishPig'", e); } if (match == 1) { @@ -220,6 +220,7 @@ public class Pig extends AbstractOpenApiSchema { * * @return The actual instance (BasquePig, DanishPig) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -246,55 +247,55 @@ public class Pig extends AbstractOpenApiSchema { return (DanishPig)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Pig - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with BasquePig - try { - BasquePig.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for BasquePig failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Pig + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with BasquePig + try { + BasquePig.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for BasquePig failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with DanishPig + try { + DanishPig.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for DanishPig failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Pig with oneOf schemas: BasquePig, DanishPig. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with DanishPig - try { - DanishPig.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for DanishPig failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Pig with oneOf schemas: BasquePig, DanishPig. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Pig given an JSON string - * - * @param jsonString JSON string - * @return An instance of Pig - * @throws IOException if the JSON string is invalid with respect to Pig - */ - public static Pig fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Pig.class); - } + /** + * Create an instance of Pig given an JSON string + * + * @param jsonString JSON string + * @return An instance of Pig + * @throws IOException if the JSON string is invalid with respect to Pig + */ + public static Pig fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Pig.class); + } - /** - * Convert an instance of Pig to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Pig to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java index 9b510e735b3..21e8627115e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -84,15 +84,15 @@ public class Quadrilateral extends AbstractOpenApiSchema { // check if the actual instance is of the type `SimpleQuadrilateral` if (value.getActualInstance() instanceof SimpleQuadrilateral) { - JsonElement element = adapterSimpleQuadrilateral.toJsonTree((SimpleQuadrilateral)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterSimpleQuadrilateral.toJsonTree((SimpleQuadrilateral)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `ComplexQuadrilateral` if (value.getActualInstance() instanceof ComplexQuadrilateral) { - JsonElement element = adapterComplexQuadrilateral.toJsonTree((ComplexQuadrilateral)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterComplexQuadrilateral.toJsonTree((ComplexQuadrilateral)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: ComplexQuadrilateral, SimpleQuadrilateral"); } @@ -130,27 +130,27 @@ public class Quadrilateral extends AbstractOpenApiSchema { // deserialize SimpleQuadrilateral try { - // validate the JSON object to see if any exception is thrown - SimpleQuadrilateral.validateJsonElement(jsonElement); - actualAdapter = adapterSimpleQuadrilateral; - match++; - log.log(Level.FINER, "Input data matches schema 'SimpleQuadrilateral'"); + // validate the JSON object to see if any exception is thrown + SimpleQuadrilateral.validateJsonElement(jsonElement); + actualAdapter = adapterSimpleQuadrilateral; + match++; + log.log(Level.FINER, "Input data matches schema 'SimpleQuadrilateral'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for SimpleQuadrilateral failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'SimpleQuadrilateral'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for SimpleQuadrilateral failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'SimpleQuadrilateral'", e); } // deserialize ComplexQuadrilateral try { - // validate the JSON object to see if any exception is thrown - ComplexQuadrilateral.validateJsonElement(jsonElement); - actualAdapter = adapterComplexQuadrilateral; - match++; - log.log(Level.FINER, "Input data matches schema 'ComplexQuadrilateral'"); + // validate the JSON object to see if any exception is thrown + ComplexQuadrilateral.validateJsonElement(jsonElement); + actualAdapter = adapterComplexQuadrilateral; + match++; + log.log(Level.FINER, "Input data matches schema 'ComplexQuadrilateral'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for ComplexQuadrilateral failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'ComplexQuadrilateral'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for ComplexQuadrilateral failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'ComplexQuadrilateral'", e); } if (match == 1) { @@ -220,6 +220,7 @@ public class Quadrilateral extends AbstractOpenApiSchema { * * @return The actual instance (ComplexQuadrilateral, SimpleQuadrilateral) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -246,55 +247,55 @@ public class Quadrilateral extends AbstractOpenApiSchema { return (ComplexQuadrilateral)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Quadrilateral - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with SimpleQuadrilateral - try { - SimpleQuadrilateral.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for SimpleQuadrilateral failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Quadrilateral + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with SimpleQuadrilateral + try { + SimpleQuadrilateral.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for SimpleQuadrilateral failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with ComplexQuadrilateral + try { + ComplexQuadrilateral.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for ComplexQuadrilateral failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Quadrilateral with oneOf schemas: ComplexQuadrilateral, SimpleQuadrilateral. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with ComplexQuadrilateral - try { - ComplexQuadrilateral.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for ComplexQuadrilateral failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Quadrilateral with oneOf schemas: ComplexQuadrilateral, SimpleQuadrilateral. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Quadrilateral given an JSON string - * - * @param jsonString JSON string - * @return An instance of Quadrilateral - * @throws IOException if the JSON string is invalid with respect to Quadrilateral - */ - public static Quadrilateral fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Quadrilateral.class); - } + /** + * Create an instance of Quadrilateral given an JSON string + * + * @param jsonString JSON string + * @return An instance of Quadrilateral + * @throws IOException if the JSON string is invalid with respect to Quadrilateral + */ + public static Quadrilateral fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Quadrilateral.class); + } - /** - * Convert an instance of Quadrilateral to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Quadrilateral to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java index 9e6d1e4a996..157a0641f36 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java @@ -77,21 +77,21 @@ public class Scalar extends AbstractOpenApiSchema { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } // check if the actual instance is of the type `BigDecimal` if (value.getActualInstance() instanceof BigDecimal) { - JsonElement element = adapterBigDecimal.toJsonTree((BigDecimal)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBigDecimal.toJsonTree((BigDecimal)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Boolean` if (value.getActualInstance() instanceof Boolean) { - JsonPrimitive primitive = adapterBoolean.toJsonTree((Boolean)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterBoolean.toJsonTree((Boolean)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: BigDecimal, Boolean, String"); } @@ -107,45 +107,45 @@ public class Scalar extends AbstractOpenApiSchema { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - match++; - log.log(Level.FINER, "Input data matches schema 'String'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + match++; + log.log(Level.FINER, "Input data matches schema 'String'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } // deserialize BigDecimal try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterBigDecimal; - match++; - log.log(Level.FINER, "Input data matches schema 'BigDecimal'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterBigDecimal; + match++; + log.log(Level.FINER, "Input data matches schema 'BigDecimal'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'BigDecimal'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'BigDecimal'", e); } // deserialize Boolean try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isBoolean()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterBoolean; - match++; - log.log(Level.FINER, "Input data matches schema 'Boolean'"); + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isBoolean()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterBoolean; + match++; + log.log(Level.FINER, "Input data matches schema 'Boolean'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Boolean'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Boolean'", e); } if (match == 1) { @@ -226,6 +226,7 @@ public class Scalar extends AbstractOpenApiSchema { * * @return The actual instance (BigDecimal, Boolean, String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -262,69 +263,69 @@ public class Scalar extends AbstractOpenApiSchema { return (Boolean)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Scalar - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Scalar + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with BigDecimal + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Boolean + try { + if (!jsonElement.getAsJsonPrimitive().isBoolean()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Scalar with oneOf schemas: BigDecimal, Boolean, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with BigDecimal - try { - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); - // continue to the next one - } - // validate the json string with Boolean - try { - if(!jsonElement.getAsJsonPrimitive().isBoolean()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Scalar with oneOf schemas: BigDecimal, Boolean, String. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Scalar given an JSON string - * - * @param jsonString JSON string - * @return An instance of Scalar - * @throws IOException if the JSON string is invalid with respect to Scalar - */ - public static Scalar fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Scalar.class); - } + /** + * Create an instance of Scalar given an JSON string + * + * @param jsonString JSON string + * @return An instance of Scalar + * @throws IOException if the JSON string is invalid with respect to Scalar + */ + public static Scalar fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Scalar.class); + } - /** - * Convert an instance of Scalar to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Scalar to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java index 3054066726d..1a9318c19ca 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java @@ -77,23 +77,23 @@ public class ScalarAnyOf extends AbstractOpenApiSchema { // check if the actual instance is of the type `String` if (value.getActualInstance() instanceof String) { - JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterString.toJsonTree((String)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } // check if the actual instance is of the type `BigDecimal` if (value.getActualInstance() instanceof BigDecimal) { - JsonElement element = adapterBigDecimal.toJsonTree((BigDecimal)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterBigDecimal.toJsonTree((BigDecimal)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Boolean` if (value.getActualInstance() instanceof Boolean) { - JsonPrimitive primitive = adapterBoolean.toJsonTree((Boolean)value.getActualInstance()).getAsJsonPrimitive(); - elementAdapter.write(out, primitive); - return; + JsonPrimitive primitive = adapterBoolean.toJsonTree((Boolean)value.getActualInstance()).getAsJsonPrimitive(); + elementAdapter.write(out, primitive); + return; } - throw new IOException("Failed to serialize as the type doesn't match anyOf schemae: BigDecimal, Boolean, String"); + throw new IOException("Failed to serialize as the type doesn't match anyOf schemas: BigDecimal, Boolean, String"); } @Override @@ -106,48 +106,48 @@ public class ScalarAnyOf extends AbstractOpenApiSchema { // deserialize String try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterString; - ScalarAnyOf ret = new ScalarAnyOf(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterString; + ScalarAnyOf ret = new ScalarAnyOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'String'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'String'", e); } // deserialize BigDecimal try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterBigDecimal; - ScalarAnyOf ret = new ScalarAnyOf(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterBigDecimal; + ScalarAnyOf ret = new ScalarAnyOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'BigDecimal'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'BigDecimal'", e); } // deserialize Boolean try { - // validate the JSON object to see if any exception is thrown - if(!jsonElement.getAsJsonPrimitive().isBoolean()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); - } - actualAdapter = adapterBoolean; - ScalarAnyOf ret = new ScalarAnyOf(); - ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); - return ret; + // validate the JSON object to see if any exception is thrown + if (!jsonElement.getAsJsonPrimitive().isBoolean()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); + } + actualAdapter = adapterBoolean; + ScalarAnyOf ret = new ScalarAnyOf(); + ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement)); + return ret; } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Boolean'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Boolean'", e); } throw new IOException(String.format("Failed deserialization for ScalarAnyOf: no class matches result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); @@ -222,6 +222,7 @@ public class ScalarAnyOf extends AbstractOpenApiSchema { * * @return The actual instance (BigDecimal, Boolean, String) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -258,67 +259,66 @@ public class ScalarAnyOf extends AbstractOpenApiSchema { return (Boolean)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to ScalarAnyOf - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate anyOf schemas one by one - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with String - try { - if(!jsonElement.getAsJsonPrimitive().isString()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); - } - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to ScalarAnyOf + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate anyOf schemas one by one + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with String + try { + if (!jsonElement.getAsJsonPrimitive().isString()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type String in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for String failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with BigDecimal + try { + if (!jsonElement.getAsJsonPrimitive().isNumber()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Boolean + try { + if (!jsonElement.getAsJsonPrimitive().isBoolean()) { + throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); + } + return; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); + // continue to the next one + } + throw new IOException(String.format("The JSON string is invalid for ScalarAnyOf with anyOf schemas: BigDecimal, Boolean, String. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); } - // validate the json string with BigDecimal - try { - if(!jsonElement.getAsJsonPrimitive().isNumber()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString())); - } - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for BigDecimal failed with `%s`.", e.getMessage())); - // continue to the next one - } - // validate the json string with Boolean - try { - if(!jsonElement.getAsJsonPrimitive().isBoolean()) { - throw new IllegalArgumentException(String.format("Expected json element to be of type Boolean in the JSON string but got `%s`", jsonElement.toString())); - } - return; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Boolean failed with `%s`.", e.getMessage())); - // continue to the next one - } - throw new IOException(String.format("The JSON string is invalid for ScalarAnyOf with anyOf schemas: BigDecimal, Boolean, String. no class match the result, expected at least 1. Detailed failure message for anyOf schemas: %s. JSON: %s", errorMessages, jsonElement.toString())); - - } - /** - * Create an instance of ScalarAnyOf given an JSON string - * - * @param jsonString JSON string - * @return An instance of ScalarAnyOf - * @throws IOException if the JSON string is invalid with respect to ScalarAnyOf - */ - public static ScalarAnyOf fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, ScalarAnyOf.class); - } + /** + * Create an instance of ScalarAnyOf given an JSON string + * + * @param jsonString JSON string + * @return An instance of ScalarAnyOf + * @throws IOException if the JSON string is invalid with respect to ScalarAnyOf + */ + public static ScalarAnyOf fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, ScalarAnyOf.class); + } - /** - * Convert an instance of ScalarAnyOf to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of ScalarAnyOf to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java index 146c99d6483..58f3e405613 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java @@ -84,15 +84,15 @@ public class Shape extends AbstractOpenApiSchema { // check if the actual instance is of the type `Triangle` if (value.getActualInstance() instanceof Triangle) { - JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Quadrilateral` if (value.getActualInstance() instanceof Quadrilateral) { - JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Quadrilateral, Triangle"); } @@ -130,27 +130,27 @@ public class Shape extends AbstractOpenApiSchema { // deserialize Triangle try { - // validate the JSON object to see if any exception is thrown - Triangle.validateJsonElement(jsonElement); - actualAdapter = adapterTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'Triangle'"); + // validate the JSON object to see if any exception is thrown + Triangle.validateJsonElement(jsonElement); + actualAdapter = adapterTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'Triangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } // deserialize Quadrilateral try { - // validate the JSON object to see if any exception is thrown - Quadrilateral.validateJsonElement(jsonElement); - actualAdapter = adapterQuadrilateral; - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + // validate the JSON object to see if any exception is thrown + Quadrilateral.validateJsonElement(jsonElement); + actualAdapter = adapterQuadrilateral; + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); } if (match == 1) { @@ -220,6 +220,7 @@ public class Shape extends AbstractOpenApiSchema { * * @return The actual instance (Quadrilateral, Triangle) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -246,55 +247,55 @@ public class Shape extends AbstractOpenApiSchema { return (Quadrilateral)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Shape - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Triangle - try { - Triangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Shape + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Triangle + try { + Triangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Quadrilateral + try { + Quadrilateral.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Shape with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Quadrilateral - try { - Quadrilateral.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Shape with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Shape given an JSON string - * - * @param jsonString JSON string - * @return An instance of Shape - * @throws IOException if the JSON string is invalid with respect to Shape - */ - public static Shape fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Shape.class); - } + /** + * Create an instance of Shape given an JSON string + * + * @param jsonString JSON string + * @return An instance of Shape + * @throws IOException if the JSON string is invalid with respect to Shape + */ + public static Shape fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Shape.class); + } - /** - * Convert an instance of Shape to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Shape to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java index 0253511147e..c149995febd 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -84,15 +84,15 @@ public class ShapeOrNull extends AbstractOpenApiSchema { // check if the actual instance is of the type `Triangle` if (value.getActualInstance() instanceof Triangle) { - JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterTriangle.toJsonTree((Triangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `Quadrilateral` if (value.getActualInstance() instanceof Quadrilateral) { - JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterQuadrilateral.toJsonTree((Quadrilateral)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Quadrilateral, Triangle"); } @@ -130,27 +130,27 @@ public class ShapeOrNull extends AbstractOpenApiSchema { // deserialize Triangle try { - // validate the JSON object to see if any exception is thrown - Triangle.validateJsonElement(jsonElement); - actualAdapter = adapterTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'Triangle'"); + // validate the JSON object to see if any exception is thrown + Triangle.validateJsonElement(jsonElement); + actualAdapter = adapterTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'Triangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } // deserialize Quadrilateral try { - // validate the JSON object to see if any exception is thrown - Quadrilateral.validateJsonElement(jsonElement); - actualAdapter = adapterQuadrilateral; - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + // validate the JSON object to see if any exception is thrown + Quadrilateral.validateJsonElement(jsonElement); + actualAdapter = adapterQuadrilateral; + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); } if (match == 1) { @@ -225,6 +225,7 @@ public class ShapeOrNull extends AbstractOpenApiSchema { * * @return The actual instance (Quadrilateral, Triangle) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -251,55 +252,55 @@ public class ShapeOrNull extends AbstractOpenApiSchema { return (Quadrilateral)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to ShapeOrNull - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Triangle - try { - Triangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to ShapeOrNull + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Triangle + try { + Triangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Triangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with Quadrilateral + try { + Quadrilateral.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for ShapeOrNull with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with Quadrilateral - try { - Quadrilateral.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Quadrilateral failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for ShapeOrNull with oneOf schemas: Quadrilateral, Triangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of ShapeOrNull given an JSON string - * - * @param jsonString JSON string - * @return An instance of ShapeOrNull - * @throws IOException if the JSON string is invalid with respect to ShapeOrNull - */ - public static ShapeOrNull fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, ShapeOrNull.class); - } + /** + * Create an instance of ShapeOrNull given an JSON string + * + * @param jsonString JSON string + * @return An instance of ShapeOrNull + * @throws IOException if the JSON string is invalid with respect to ShapeOrNull + */ + public static ShapeOrNull fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, ShapeOrNull.class); + } - /** - * Convert an instance of ShapeOrNull to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of ShapeOrNull to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java index 8d96ac0dcd2..131c1ce71cf 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java @@ -86,21 +86,21 @@ public class Triangle extends AbstractOpenApiSchema { // check if the actual instance is of the type `EquilateralTriangle` if (value.getActualInstance() instanceof EquilateralTriangle) { - JsonElement element = adapterEquilateralTriangle.toJsonTree((EquilateralTriangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterEquilateralTriangle.toJsonTree((EquilateralTriangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `IsoscelesTriangle` if (value.getActualInstance() instanceof IsoscelesTriangle) { - JsonElement element = adapterIsoscelesTriangle.toJsonTree((IsoscelesTriangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterIsoscelesTriangle.toJsonTree((IsoscelesTriangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `ScaleneTriangle` if (value.getActualInstance() instanceof ScaleneTriangle) { - JsonElement element = adapterScaleneTriangle.toJsonTree((ScaleneTriangle)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterScaleneTriangle.toJsonTree((ScaleneTriangle)value.getActualInstance()); + elementAdapter.write(out, element); + return; } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle"); } @@ -142,39 +142,39 @@ public class Triangle extends AbstractOpenApiSchema { // deserialize EquilateralTriangle try { - // validate the JSON object to see if any exception is thrown - EquilateralTriangle.validateJsonElement(jsonElement); - actualAdapter = adapterEquilateralTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'EquilateralTriangle'"); + // validate the JSON object to see if any exception is thrown + EquilateralTriangle.validateJsonElement(jsonElement); + actualAdapter = adapterEquilateralTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'EquilateralTriangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for EquilateralTriangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'EquilateralTriangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for EquilateralTriangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'EquilateralTriangle'", e); } // deserialize IsoscelesTriangle try { - // validate the JSON object to see if any exception is thrown - IsoscelesTriangle.validateJsonElement(jsonElement); - actualAdapter = adapterIsoscelesTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'IsoscelesTriangle'"); + // validate the JSON object to see if any exception is thrown + IsoscelesTriangle.validateJsonElement(jsonElement); + actualAdapter = adapterIsoscelesTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'IsoscelesTriangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for IsoscelesTriangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'IsoscelesTriangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for IsoscelesTriangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'IsoscelesTriangle'", e); } // deserialize ScaleneTriangle try { - // validate the JSON object to see if any exception is thrown - ScaleneTriangle.validateJsonElement(jsonElement); - actualAdapter = adapterScaleneTriangle; - match++; - log.log(Level.FINER, "Input data matches schema 'ScaleneTriangle'"); + // validate the JSON object to see if any exception is thrown + ScaleneTriangle.validateJsonElement(jsonElement); + actualAdapter = adapterScaleneTriangle; + match++; + log.log(Level.FINER, "Input data matches schema 'ScaleneTriangle'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for ScaleneTriangle failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'ScaleneTriangle'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for ScaleneTriangle failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'ScaleneTriangle'", e); } if (match == 1) { @@ -255,6 +255,7 @@ public class Triangle extends AbstractOpenApiSchema { * * @return The actual instance (EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -291,63 +292,63 @@ public class Triangle extends AbstractOpenApiSchema { return (ScaleneTriangle)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Triangle - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with EquilateralTriangle - try { - EquilateralTriangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for EquilateralTriangle failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Triangle + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with EquilateralTriangle + try { + EquilateralTriangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for EquilateralTriangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with IsoscelesTriangle + try { + IsoscelesTriangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for IsoscelesTriangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with ScaleneTriangle + try { + ScaleneTriangle.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for ScaleneTriangle failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Triangle with oneOf schemas: EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with IsoscelesTriangle - try { - IsoscelesTriangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for IsoscelesTriangle failed with `%s`.", e.getMessage())); - // continue to the next one - } - // validate the json string with ScaleneTriangle - try { - ScaleneTriangle.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for ScaleneTriangle failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Triangle with oneOf schemas: EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Triangle given an JSON string - * - * @param jsonString JSON string - * @return An instance of Triangle - * @throws IOException if the JSON string is invalid with respect to Triangle - */ - public static Triangle fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Triangle.class); - } + /** + * Create an instance of Triangle given an JSON string + * + * @param jsonString JSON string + * @return An instance of Triangle + * @throws IOException if the JSON string is invalid with respect to Triangle + */ + public static Triangle fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Triangle.class); + } - /** - * Convert an instance of Triangle to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Triangle to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java index 9d9b01ad3d5..854593c8505 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java @@ -67,7 +67,7 @@ public class Value extends AbstractOpenApiSchema { final TypeAdapter adapterScalar = gson.getDelegateAdapter(this, TypeToken.get(Scalar.class)); final Type typeInstance = new TypeToken>(){}.getType(); - final TypeAdapter> adapterScalarList = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); + final TypeAdapter> adapterListScalar = (TypeAdapter>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance)); return (TypeAdapter) new TypeAdapter() { @Override @@ -79,18 +79,18 @@ public class Value extends AbstractOpenApiSchema { // check if the actual instance is of the type `Scalar` if (value.getActualInstance() instanceof Scalar) { - JsonElement element = adapterScalar.toJsonTree((Scalar)value.getActualInstance()); - elementAdapter.write(out, element); - return; + JsonElement element = adapterScalar.toJsonTree((Scalar)value.getActualInstance()); + elementAdapter.write(out, element); + return; } // check if the actual instance is of the type `List` if (value.getActualInstance() instanceof List) { - List list = (List) value.getActualInstance(); - if(list.get(0) instanceof Scalar) { - JsonArray array = adapterScalarList.toJsonTree((List)value.getActualInstance()).getAsJsonArray(); - elementAdapter.write(out, array); - return; - } + List list = (List) value.getActualInstance(); + if (list.get(0) instanceof Scalar) { + JsonArray array = adapterListScalar.toJsonTree((List)value.getActualInstance()).getAsJsonArray(); + elementAdapter.write(out, array); + return; + } } throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: List, Scalar"); } @@ -106,35 +106,35 @@ public class Value extends AbstractOpenApiSchema { // deserialize Scalar try { - // validate the JSON object to see if any exception is thrown - Scalar.validateJsonElement(jsonElement); - actualAdapter = adapterScalar; - match++; - log.log(Level.FINER, "Input data matches schema 'Scalar'"); + // validate the JSON object to see if any exception is thrown + Scalar.validateJsonElement(jsonElement); + actualAdapter = adapterScalar; + match++; + log.log(Level.FINER, "Input data matches schema 'Scalar'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for Scalar failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'Scalar'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for Scalar failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'Scalar'", e); } // deserialize List try { - // validate the JSON object to see if any exception is thrown - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } + // validate the JSON object to see if any exception is thrown + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - Scalar.validateJsonElement(element); - } - actualAdapter = adapterScalarList; - match++; - log.log(Level.FINER, "Input data matches schema 'List'"); + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + Scalar.validateJsonElement(element); + } + actualAdapter = adapterListScalar; + match++; + log.log(Level.FINER, "Input data matches schema 'List'"); } catch (Exception e) { - // deserialization failed, continue - errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); - log.log(Level.FINER, "Input data does not match schema 'List'", e); + // deserialization failed, continue + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'List'", e); } if (match == 1) { @@ -192,10 +192,10 @@ public class Value extends AbstractOpenApiSchema { if (instance instanceof List) { List list = (List) instance; - if(list.get(0) instanceof Scalar) { - super.setActualInstance(instance); - return; - } + if (list.get(0) instanceof Scalar) { + super.setActualInstance(instance); + return; + } } throw new RuntimeException("Invalid instance type. Must be List, Scalar"); @@ -207,6 +207,7 @@ public class Value extends AbstractOpenApiSchema { * * @return The actual instance (List, Scalar) */ + @SuppressWarnings("unchecked") @Override public Object getActualInstance() { return super.getActualInstance(); @@ -229,66 +230,66 @@ public class Value extends AbstractOpenApiSchema { * @return The actual instance of `List` * @throws ClassCastException if the instance is not `List` */ - public List getScalarList() throws ClassCastException { + public List getListScalar() throws ClassCastException { return (List)super.getActualInstance(); } - /** - * Validates the JSON Element and throws an exception if issues found - * - * @param jsonElement JSON Element - * @throws IOException if the JSON Element is invalid with respect to Value - */ - public static void validateJsonElement(JsonElement jsonElement) throws IOException { - // validate oneOf schemas one by one - int validCount = 0; - ArrayList errorMessages = new ArrayList<>(); - // validate the json string with Scalar - try { - Scalar.validateJsonElement(jsonElement); - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for Scalar failed with `%s`.", e.getMessage())); - // continue to the next one + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to Value + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + // validate oneOf schemas one by one + int validCount = 0; + ArrayList errorMessages = new ArrayList<>(); + // validate the json string with Scalar + try { + Scalar.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for Scalar failed with `%s`.", e.getMessage())); + // continue to the next one + } + // validate the json string with List + try { + if (!jsonElement.isJsonArray()) { + throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); + } + JsonArray array = jsonElement.getAsJsonArray(); + // validate array items + for(JsonElement element : array) { + Scalar.validateJsonElement(element); + } + validCount++; + } catch (Exception e) { + errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); + // continue to the next one + } + if (validCount != 1) { + throw new IOException(String.format("The JSON string is invalid for Value with oneOf schemas: List, Scalar. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); + } } - // validate the json string with List - try { - if (!jsonElement.isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString())); - } - JsonArray array = jsonElement.getAsJsonArray(); - // validate array items - for(JsonElement element : array) { - Scalar.validateJsonElement(element); - } - validCount++; - } catch (Exception e) { - errorMessages.add(String.format("Deserialization for List failed with `%s`.", e.getMessage())); - // continue to the next one - } - if (validCount != 1) { - throw new IOException(String.format("The JSON string is invalid for Value with oneOf schemas: List, Scalar. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); - } - } - /** - * Create an instance of Value given an JSON string - * - * @param jsonString JSON string - * @return An instance of Value - * @throws IOException if the JSON string is invalid with respect to Value - */ - public static Value fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Value.class); - } + /** + * Create an instance of Value given an JSON string + * + * @param jsonString JSON string + * @return An instance of Value + * @throws IOException if the JSON string is invalid with respect to Value + */ + public static Value fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, Value.class); + } - /** - * Convert an instance of Value to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } + /** + * Convert an instance of Value to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java index ef72b6b4aca..978195ccf6d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java @@ -17,13 +17,7 @@ import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; +import java.util.*; import okio.ByteString; import org.junit.jupiter.api.*; @@ -615,4 +609,44 @@ public class JSONTest { z.putAdditionalProperty("new_object_array", Arrays.asList(t)); assertEquals(z.toJson(), "{\"className\":\"zebra\",\"object_array\":[{\"id\":34.0,\"name\":\"just a tag\"}],\"empty_array\":[],\"array\":[\"1\",\"2\",\"3\"],\"new_array\":[\"1\",\"2\",\"3\"],\"new_empty_array\":[],\"new_object_array\":[{\"id\":34,\"name\":\"just a tag\"}]}"); } + + /** + * Validate a oneOf, anyOf schema with array sub-schema can be deserialized into the expected class. + */ + @Test + public void testOneOfAnyOfArray() throws Exception { + { + String str = "{\"oneof_prop\":23,\"anyof_prop\":45}"; + + ModelWithOneOfAnyOfProperties m = json.getGson().fromJson(str, ModelWithOneOfAnyOfProperties.class); + Integer anyofProp = (Integer) m.getAnyofProp().getActualInstance(); + assertEquals(anyofProp, 45); + Integer oneofProp = (Integer) m.getOneofProp().getActualInstance(); + assertEquals(oneofProp, 23); + + String str2 = "{ \"oneof_prop\": [\"test oneof\"], \"anyof_prop\": [\"test anyof\"] }"; + + ModelWithOneOfAnyOfProperties m2 = json.getGson().fromJson(str2, ModelWithOneOfAnyOfProperties.class); + List anyofProp2 = (List) m2.getAnyofProp().getActualInstance(); + assertEquals(anyofProp2, Arrays.asList("test anyof")); + List oneofProp2 = (List) m2.getOneofProp().getActualInstance(); + assertEquals(oneofProp2, Arrays.asList("test oneof")); + } + { + // incorrect payload results in exception + String str = "{ \"oneof_prop\": \"23\", \"anyof_prop\": \"45\" }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + ModelWithOneOfAnyOfProperties o = json.getGson().fromJson(str, ModelWithOneOfAnyOfProperties.class); + }); + assertTrue(exception.getMessage().contains("java.io.IOException: The JSON string is invalid for")); + } + { + // incorrect payload (array item type mismatch) results in exception + String str = "{ \"oneof_prop\": [23], \"anyof_prop\": [true] }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + ModelWithOneOfAnyOfProperties o = json.getGson().fromJson(str, ModelWithOneOfAnyOfProperties.class); + }); + assertTrue(exception.getMessage().contains("java.io.IOException: The JSON string is invalid for")); + } + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayAnyOfTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayAnyOfTest.java new file mode 100644 index 00000000000..ab635fd6b72 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayAnyOfTest.java @@ -0,0 +1,34 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for ArrayAnyOf + */ +public class ArrayAnyOfTest { + private final ArrayAnyOf model = new ArrayAnyOf(); + + /** + * Model tests for ArrayAnyOf + */ + @Test + public void testArrayAnyOf() { + // TODO: test ArrayAnyOf + } + +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOneOfTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOneOfTest.java new file mode 100644 index 00000000000..7f9af8d893c --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOneOfTest.java @@ -0,0 +1,34 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for ArrayOneOf + */ +public class ArrayOneOfTest { + private final ArrayOneOf model = new ArrayOneOf(); + + /** + * Model tests for ArrayOneOf + */ + @Test + public void testArrayOneOf() { + // TODO: test ArrayOneOf + } + +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelWithOneOfAnyOfPropertiesTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelWithOneOfAnyOfPropertiesTest.java new file mode 100644 index 00000000000..ffe5a18d7a3 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelWithOneOfAnyOfPropertiesTest.java @@ -0,0 +1,58 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import org.openapitools.client.model.ArrayAnyOf; +import org.openapitools.client.model.ArrayOneOf; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Model tests for ModelWithOneOfAnyOfProperties + */ +public class ModelWithOneOfAnyOfPropertiesTest { + private final ModelWithOneOfAnyOfProperties model = new ModelWithOneOfAnyOfProperties(); + + /** + * Model tests for ModelWithOneOfAnyOfProperties + */ + @Test + public void testModelWithOneOfAnyOfProperties() { + // TODO: test ModelWithOneOfAnyOfProperties + } + + /** + * Test the property 'oneofProp' + */ + @Test + public void oneofPropTest() { + // TODO: test oneofProp + } + + /** + * Test the property 'anyofProp' + */ + @Test + public void anyofPropTest() { + // TODO: test anyofProp + } + +}