From cc4698c027f4eb675dcde93ba8e0f4a9e97089a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rgvin?= <bjorgvino@gmail.com> Date: Fri, 20 Jan 2023 14:33:49 +0100 Subject: [PATCH] [java] Fix template logic related to supportUrlQuery Generated models for arrays marked with uniqueItems: true (which end up as a Set<> in java) won't compile because the templates are in some places using .get(i) on the sets. Also, when the supportUrlQuery property is present in the additionalProperties map the resulting value will be read using the key SUPPORT_STREAMING instead of 'supportUrlQuery'. --- .../openapitools/codegen/languages/JavaClientCodegen.java | 7 ++++--- .../resources/Java/libraries/native/oneof_model.mustache | 2 +- .../src/main/resources/Java/libraries/native/pojo.mustache | 2 +- .../src/main/resources/Java/pojo.mustache | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 1e97033d626..56bcef1eb32 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -68,6 +68,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles"; public static final String DYNAMIC_OPERATIONS = "dynamicOperations"; public static final String SUPPORT_STREAMING = "supportStreaming"; + public static final String SUPPORT_URL_QUERY = "supportUrlQuery"; public static final String GRADLE_PROPERTIES = "gradleProperties"; public static final String ERROR_OBJECT_TYPE = "errorObjectType"; @@ -428,10 +429,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen } // add URL query deepObject support to native, apache-httpclient by default - if (!additionalProperties.containsKey("supportUrlQuery") && (isLibrary(NATIVE) || isLibrary(APACHE))) { - additionalProperties.put("supportUrlQuery", true); + if (!additionalProperties.containsKey(SUPPORT_URL_QUERY) && (isLibrary(NATIVE) || isLibrary(APACHE))) { + additionalProperties.put(SUPPORT_URL_QUERY, true); } else { - additionalProperties.put("supportUrlQuery", Boolean.parseBoolean(additionalProperties.get(SUPPORT_STREAMING).toString())); + additionalProperties.put(SUPPORT_URL_QUERY, Boolean.parseBoolean(additionalProperties.get(SUPPORT_URL_QUERY).toString())); } final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/"); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache index b04c3d1dbcf..27fbd1fdfe6 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache @@ -294,7 +294,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im if (getActualInstance() != null) { int i = 0; for ({{items.dataType}} _item : ({{{dataType}}})getActualInstance()) { - if ((({{{dataType}}})getActualInstance()).get(i) != null) { + if (_item != null) { joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix, "".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix)))); } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache index 79c5e846113..82e5582a11e 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache @@ -413,7 +413,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens if ({{getter}}() != null) { int i = 0; for ({{items.dataType}} _item : {{getter}}()) { - if ({{getter}}().get(i) != null) { + if (_item != null) { joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix, "".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix)))); } diff --git a/modules/openapi-generator/src/main/resources/Java/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/pojo.mustache index 057c62d6623..45c8174e4d4 100644 --- a/modules/openapi-generator/src/main/resources/Java/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/pojo.mustache @@ -411,7 +411,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens if ({{getter}}() != null) { int i = 0; for ({{items.dataType}} _item : {{getter}}()) { - if ({{getter}}().get(i) != null) { + if (_item != null) { joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix, "".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix)))); } -- GitLab