Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void write(JsonWriter out, MyExamplePostRequest value) throws IOException

// 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");
}
Expand All @@ -92,17 +92,17 @@ public MyExamplePostRequest read(JsonReader in) throws IOException {

// 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) {
Expand Down Expand Up @@ -161,6 +161,7 @@ public void setActualInstance(Object instance) {
*
* @return The actual instance (String)
*/
@SuppressWarnings("unchecked")
@Override
public Object getActualInstance() {
return super.getActualInstance();
Expand All @@ -177,49 +178,49 @@ public String getString() throws ClassCastException {
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<String> 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<String> 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()));
}
}

/**
* 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);
}
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()));

/**
* Convert an instance of MyExamplePostRequest to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

/**
* 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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public void write(JsonWriter out, SimpleOneOf value) throws IOException {

// 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");
}
Expand All @@ -100,31 +100,31 @@ public SimpleOneOf read(JsonReader in) throws IOException {

// 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) {
Expand Down Expand Up @@ -194,6 +194,7 @@ public void setActualInstance(Object instance) {
*
* @return The actual instance (Integer, String)
*/
@SuppressWarnings("unchecked")
@Override
public Object getActualInstance() {
return super.getActualInstance();
Expand All @@ -220,59 +221,59 @@ public Integer getInteger() throws ClassCastException {
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<String> 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<String> 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

/**
* 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);
}
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()));

/**
* Convert an instance of SimpleOneOf to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

/**
* 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);
}
}

Loading