Skip to content

Commit d6b3243

Browse files
Marcel JacekMarcel Jacek
authored andcommitted
review feedback
1 parent 44843b6 commit d6b3243

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,16 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
385385
{{#isArray}}
386386
{{#items.isModel}}
387387
{{#required}}
388-
// ensure the json data is an array
389-
if (!jsonObj.get("{{{baseName}}}").isJsonArray(){{#isNullable}} && !jsonObj.get("{{baseName}}").isJsonNull(){{/isNullable}}) {
390-
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
388+
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) {
389+
if (!jsonObj.get("{{{baseName}}}").isJsonArray()) {
390+
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
391+
}
392+
JsonArray jsonArray{{name}} = jsonObj.getAsJsonArray("{{{baseName}}}");
393+
// validate the required field `{{{baseName}}}` (array)
394+
for (int i = 0; i < jsonArray{{name}}.size(); i++) {
395+
{{{items.dataType}}}.validateJsonElement(jsonArray{{name}}.get(i));
396+
}
391397
}
392-
393-
JsonArray jsonArray{{name}} = jsonObj.getAsJsonArray("{{{baseName}}}");
394-
// validate the required field `{{{baseName}}}` (array)
395-
for (int i = 0; i < jsonArray{{name}}.size(); i++) {
396-
{{{items.dataType}}}.validateJsonElement(jsonArray{{name}}.get(i));
397-
};
398398
{{/required}}
399399
{{^required}}
400400
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) {

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
204204
}
205205
}
206206
JsonObject jsonObj = jsonElement.getAsJsonObject();
207-
// ensure the json data is an array
208-
if (!jsonObj.get("value").isJsonArray()) {
209-
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be an array in the JSON string but got `%s`", jsonObj.get("value").toString()));
207+
if (jsonObj.get("value") != null && !jsonObj.get("value").isJsonNull()) {
208+
if (!jsonObj.get("value").isJsonArray()) {
209+
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be an array in the JSON string but got `%s`", jsonObj.get("value").toString()));
210+
}
211+
JsonArray jsonArrayvalue = jsonObj.getAsJsonArray("value");
212+
// validate the required field `value` (array)
213+
for (int i = 0; i < jsonArrayvalue.size(); i++) {
214+
AllOfModelArrayAnyOfAllOfLinkListColumn1Value.validateJsonElement(jsonArrayvalue.get(i));
215+
}
210216
}
211-
212-
JsonArray jsonArrayvalue = jsonObj.getAsJsonArray("value");
213-
// validate the required field `value` (array)
214-
for (int i = 0; i < jsonArrayvalue.size(); i++) {
215-
AllOfModelArrayAnyOfAllOfLinkListColumn1Value.validateJsonElement(jsonArrayvalue.get(i));
216-
};
217217
}
218218

219219
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/PetWithRequiredTags.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,16 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
410410
} else if (!jsonObj.get("photoUrls").isJsonArray()) {
411411
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `photoUrls` to be an array in the JSON string but got `%s`", jsonObj.get("photoUrls").toString()));
412412
}
413-
// ensure the json data is an array
414-
if (!jsonObj.get("tags").isJsonArray()) {
415-
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
413+
if (jsonObj.get("tags") != null && !jsonObj.get("tags").isJsonNull()) {
414+
if (!jsonObj.get("tags").isJsonArray()) {
415+
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
416+
}
417+
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
418+
// validate the required field `tags` (array)
419+
for (int i = 0; i < jsonArraytags.size(); i++) {
420+
Tag.validateJsonElement(jsonArraytags.get(i));
421+
}
416422
}
417-
418-
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
419-
// validate the required field `tags` (array)
420-
for (int i = 0; i < jsonArraytags.size(); i++) {
421-
Tag.validateJsonElement(jsonArraytags.get(i));
422-
};
423423
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
424424
throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));
425425
}

0 commit comments

Comments
 (0)