forked from loafle/openapi-generator-original
[Java][okhttp-gson] validateJsonElement does not validate enum values (#16865)
* validate enum properties in validateJsonElement * regenerate samples * add test for enum validation in okhttp-gson models
This commit is contained in:
@@ -115,6 +115,11 @@ public class Order {
|
||||
return StatusEnum.fromValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
||||
String value = jsonElement.getAsString();
|
||||
StatusEnum.fromValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String SERIALIZED_NAME_STATUS = "status";
|
||||
@@ -382,6 +387,10 @@ public class Order {
|
||||
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));
|
||||
}
|
||||
// validate the optional field `status`
|
||||
if (jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) {
|
||||
StatusEnum.validateJsonElement(jsonObj.get("status"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
||||
|
||||
@@ -122,6 +122,11 @@ public class Pet {
|
||||
return StatusEnum.fromValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
||||
String value = jsonElement.getAsString();
|
||||
StatusEnum.fromValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String SERIALIZED_NAME_STATUS = "status";
|
||||
@@ -442,6 +447,10 @@ public class Pet {
|
||||
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));
|
||||
}
|
||||
// validate the optional field `status`
|
||||
if (jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) {
|
||||
StatusEnum.validateJsonElement(jsonObj.get("status"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
||||
|
||||
Reference in New Issue
Block a user