Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

fix: validate enum values in nested models #163

Merged
merged 4 commits into from
Oct 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException {
return TypeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
TypeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_TYPE = "type";
Expand Down Expand Up @@ -880,6 +885,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("type") != null && !jsonObj.get("type").isJsonNull()) && !jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
// validate the optional field `type`
if (jsonObj.get("type") != null && !jsonObj.get("type").isJsonNull()) {
TypeEnum.validateJsonElement(jsonObj.get("type"));
}
// ensure the optional json data is an array if present
if (jsonObj.get("tags") != null && !jsonObj.get("tags").isJsonNull() && !jsonObj.get("tags").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public AddressFamilyEnum read(final JsonReader jsonReader) throws IOException {
return AddressFamilyEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
AddressFamilyEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_ADDRESS_FAMILY = "address_family";
Expand Down Expand Up @@ -268,6 +273,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("address_family") != null && !jsonObj.get("address_family").isJsonNull()) && !jsonObj.get("address_family").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `address_family` to be a primitive type in the JSON string but got `%s`", jsonObj.get("address_family").toString()));
}
// validate the optional field `address_family`
if (jsonObj.get("address_family") != null && !jsonObj.get("address_family").isJsonNull()) {
AddressFamilyEnum.validateJsonElement(jsonObj.get("address_family"));
}
}

public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public DeploymentTypeEnum read(final JsonReader jsonReader) throws IOException {
return DeploymentTypeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
DeploymentTypeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_DEPLOYMENT_TYPE = "deployment_type";
Expand Down Expand Up @@ -202,6 +207,11 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
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";
Expand Down Expand Up @@ -660,6 +670,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("deployment_type") != null && !jsonObj.get("deployment_type").isJsonNull()) && !jsonObj.get("deployment_type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `deployment_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("deployment_type").toString()));
}
// validate the optional field `deployment_type`
if (jsonObj.get("deployment_type") != null && !jsonObj.get("deployment_type").isJsonNull()) {
DeploymentTypeEnum.validateJsonElement(jsonObj.get("deployment_type"));
}
if ((jsonObj.get("href") != null && !jsonObj.get("href").isJsonNull()) && !jsonObj.get("href").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `href` to be a primitive type in the JSON string but got `%s`", jsonObj.get("href").toString()));
}
Expand Down Expand Up @@ -707,6 +721,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public DeploymentTypeEnum read(final JsonReader jsonReader) throws IOException {
return DeploymentTypeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
DeploymentTypeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_DEPLOYMENT_TYPE = "deployment_type";
Expand Down Expand Up @@ -335,6 +340,8 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if (!jsonObj.get("deployment_type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `deployment_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("deployment_type").toString()));
}
// validate the required field `deployment_type`
DeploymentTypeEnum.validateJsonElement(jsonObj.get("deployment_type"));
if ((jsonObj.get("md5") != null && !jsonObj.get("md5").isJsonNull()) && !jsonObj.get("md5").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `md5` to be a primitive type in the JSON string but got `%s`", jsonObj.get("md5").toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public StateEnum read(final JsonReader jsonReader) throws IOException {
return StateEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
StateEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_STATE = "state";
Expand Down Expand Up @@ -491,6 +496,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) && !jsonObj.get("state").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `state` to be a primitive type in the JSON string but got `%s`", jsonObj.get("state").toString()));
}
// validate the optional field `state`
if (jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) {
StateEnum.validateJsonElement(jsonObj.get("state"));
}
if ((jsonObj.get("href") != null && !jsonObj.get("href").isJsonNull()) && !jsonObj.get("href").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `href` to be a primitive type in the JSON string but got `%s`", jsonObj.get("href").toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public AddressFamilyEnum read(final JsonReader jsonReader) throws IOException {
return AddressFamilyEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
AddressFamilyEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_ADDRESS_FAMILY = "address_family";
Expand Down Expand Up @@ -179,6 +184,11 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
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";
Expand Down Expand Up @@ -534,6 +544,8 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if (!jsonObj.get("address_family").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `address_family` to be a primitive type in the JSON string but got `%s`", jsonObj.get("address_family").toString()));
}
// validate the required field `address_family`
AddressFamilyEnum.validateJsonElement(jsonObj.get("address_family"));
// validate the optional field `device`
if (jsonObj.get("device") != null && !jsonObj.get("device").isJsonNull()) {
Href.validateJsonElement(jsonObj.get("device"));
Expand All @@ -551,6 +563,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public CountEnum read(final JsonReader jsonReader) throws IOException {
return CountEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
Integer value = jsonElement.getAsInt();
CountEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_COUNT = "count";
Expand Down Expand Up @@ -146,6 +151,11 @@ public UnitEnum read(final JsonReader jsonReader) throws IOException {
return UnitEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
UnitEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_UNIT = "unit";
Expand Down Expand Up @@ -310,9 +320,17 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
// validate the optional field `count`
if (jsonObj.get("count") != null && !jsonObj.get("count").isJsonNull()) {
CountEnum.validateJsonElement(jsonObj.get("count"));
}
if ((jsonObj.get("unit") != null && !jsonObj.get("unit").isJsonNull()) && !jsonObj.get("unit").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `unit` to be a primitive type in the JSON string but got `%s`", jsonObj.get("unit").toString()));
}
// validate the optional field `unit`
if (jsonObj.get("unit") != null && !jsonObj.get("unit").isJsonNull()) {
UnitEnum.validateJsonElement(jsonObj.get("unit"));
}
}

public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public ModeEnum read(final JsonReader jsonReader) throws IOException {
return ModeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
ModeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_MODE = "mode";
Expand Down Expand Up @@ -184,6 +189,11 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException {
return TypeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
TypeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_TYPE = "type";
Expand Down Expand Up @@ -626,6 +636,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("mode") != null && !jsonObj.get("mode").isJsonNull()) && !jsonObj.get("mode").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `mode` to be a primitive type in the JSON string but got `%s`", jsonObj.get("mode").toString()));
}
// validate the optional field `mode`
if (jsonObj.get("mode") != null && !jsonObj.get("mode").isJsonNull()) {
ModeEnum.validateJsonElement(jsonObj.get("mode"));
}
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()));
}
Expand All @@ -642,6 +656,8 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if (!jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
// validate the required field `type`
TypeEnum.validateJsonElement(jsonObj.get("type"));
if ((jsonObj.get("use_case") != null && !jsonObj.get("use_case").isJsonNull()) && !jsonObj.get("use_case").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `use_case` to be a primitive type in the JSON string but got `%s`", jsonObj.get("use_case").toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ public StateEnum read(final JsonReader jsonReader) throws IOException {
return StateEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
StateEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_STATE = "state";
Expand Down Expand Up @@ -1651,6 +1656,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) && !jsonObj.get("state").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `state` to be a primitive type in the JSON string but got `%s`", jsonObj.get("state").toString()));
}
// validate the optional field `state`
if (jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) {
StateEnum.validateJsonElement(jsonObj.get("state"));
}
// validate the optional field `storage`
if (jsonObj.get("storage") != null && !jsonObj.get("storage").isJsonNull()) {
Storage.validateJsonElement(jsonObj.get("storage"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException {
return TypeEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
TypeEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_TYPE = "type";
Expand Down Expand Up @@ -394,6 +399,8 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if (!jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
// validate the required field `type`
TypeEnum.validateJsonElement(jsonObj.get("type"));
if ((jsonObj.get("operating_system") != null && !jsonObj.get("operating_system").isJsonNull()) && !jsonObj.get("operating_system").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `operating_system` to be a primitive type in the JSON string but got `%s`", jsonObj.get("operating_system").toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public BillingCycleEnum read(final JsonReader jsonReader) throws IOException {
return BillingCycleEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
BillingCycleEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_BILLING_CYCLE = "billing_cycle";
Expand Down Expand Up @@ -1038,6 +1043,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("billing_cycle") != null && !jsonObj.get("billing_cycle").isJsonNull()) && !jsonObj.get("billing_cycle").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `billing_cycle` to be a primitive type in the JSON string but got `%s`", jsonObj.get("billing_cycle").toString()));
}
// validate the optional field `billing_cycle`
if (jsonObj.get("billing_cycle") != null && !jsonObj.get("billing_cycle").isJsonNull()) {
BillingCycleEnum.validateJsonElement(jsonObj.get("billing_cycle"));
}
if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public BillingCycleEnum read(final JsonReader jsonReader) throws IOException {
return BillingCycleEnum.fromValue(value);
}
}

public static void validateJsonElement(JsonElement jsonElement) throws IOException {
String value = jsonElement.getAsString();
BillingCycleEnum.fromValue(value);
}
}

public static final String SERIALIZED_NAME_BILLING_CYCLE = "billing_cycle";
Expand Down Expand Up @@ -1022,6 +1027,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
if ((jsonObj.get("billing_cycle") != null && !jsonObj.get("billing_cycle").isJsonNull()) && !jsonObj.get("billing_cycle").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `billing_cycle` to be a primitive type in the JSON string but got `%s`", jsonObj.get("billing_cycle").toString()));
}
// validate the optional field `billing_cycle`
if (jsonObj.get("billing_cycle") != null && !jsonObj.get("billing_cycle").isJsonNull()) {
BillingCycleEnum.validateJsonElement(jsonObj.get("billing_cycle"));
}
if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString()));
}
Expand Down
Loading