[java][okhttp-gson] fix validateJsonObject (#13630)

* fix required check in java okhttp client

* fix validateJsonObject in okhttp-gson, add test

* move java-micronaut-client to test circleci
This commit is contained in:
William Cheng
2022-10-07 23:06:34 +08:00
committed by GitHub
parent 0060dfd195
commit 3ae37e27a5
168 changed files with 276 additions and 598 deletions

View File

@@ -206,9 +206,7 @@ public class Category {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Category.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!Category.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in Category is not found in the empty JSON string", Category.openapiRequiredFields.toString()));
}
}

View File

@@ -236,9 +236,7 @@ public class ModelApiResponse {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (ModelApiResponse.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!ModelApiResponse.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in ModelApiResponse is not found in the empty JSON string", ModelApiResponse.openapiRequiredFields.toString()));
}
}

View File

@@ -376,9 +376,7 @@ public class Order {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Order.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!Order.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in Order is not found in the empty JSON string", Order.openapiRequiredFields.toString()));
}
}

View File

@@ -396,9 +396,7 @@ public class Pet {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Pet.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!Pet.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in Pet is not found in the empty JSON string", Pet.openapiRequiredFields.toString()));
}
}
@@ -413,7 +411,7 @@ public class Pet {
if (jsonObj.get("category") != null && !jsonObj.get("category").isJsonNull()) {
Category.validateJsonObject(jsonObj.getAsJsonObject("category"));
}
if ((jsonObj.get("name") != null && !jsonObj.get("name").isJsonNull()) && !jsonObj.get("name").isJsonPrimitive()) {
if (!jsonObj.get("name").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
}
// ensure the json data is an array

View File

@@ -206,9 +206,7 @@ public class Tag {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (Tag.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!Tag.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in Tag is not found in the empty JSON string", Tag.openapiRequiredFields.toString()));
}
}

View File

@@ -386,9 +386,7 @@ public class User {
*/
public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj == null) {
if (User.openapiRequiredFields.isEmpty()) {
return;
} else { // has required fields
if (!User.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
throw new IllegalArgumentException(String.format("The required field(s) %s in User is not found in the empty JSON string", User.openapiRequiredFields.toString()));
}
}