Skip to content

Commit 90e468b

Browse files
wing328bjorgvino
andauthored
[java] Fix template logic related to supportUrlQuery (#14496)
* [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'. * fix NPE Co-authored-by: Björgvin <bjorgvino@gmail.com>
1 parent d4c8c97 commit 90e468b

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
6868
public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles";
6969
public static final String DYNAMIC_OPERATIONS = "dynamicOperations";
7070
public static final String SUPPORT_STREAMING = "supportStreaming";
71+
public static final String SUPPORT_URL_QUERY = "supportUrlQuery";
7172
public static final String GRADLE_PROPERTIES = "gradleProperties";
7273
public static final String ERROR_OBJECT_TYPE = "errorObjectType";
7374

@@ -428,10 +429,13 @@ public void processOpts() {
428429
}
429430

430431
// add URL query deepObject support to native, apache-httpclient by default
431-
if (!additionalProperties.containsKey("supportUrlQuery") && (isLibrary(NATIVE) || isLibrary(APACHE))) {
432-
additionalProperties.put("supportUrlQuery", true);
432+
if (!additionalProperties.containsKey(SUPPORT_URL_QUERY)) {
433+
if (isLibrary(NATIVE) || isLibrary(APACHE)) {
434+
// default to true for native and apache-httpclient
435+
additionalProperties.put(SUPPORT_URL_QUERY, true);
436+
}
433437
} else {
434-
additionalProperties.put("supportUrlQuery", Boolean.parseBoolean(additionalProperties.get(SUPPORT_STREAMING).toString()));
438+
additionalProperties.put(SUPPORT_URL_QUERY, Boolean.parseBoolean(additionalProperties.get(SUPPORT_URL_QUERY).toString()));
435439
}
436440

437441
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");

modules/openapi-generator/src/main/resources/Java/libraries/native/oneof_model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
294294
if (getActualInstance() != null) {
295295
int i = 0;
296296
for ({{items.dataType}} _item : ({{{dataType}}})getActualInstance()) {
297-
if ((({{{dataType}}})getActualInstance()).get(i) != null) {
297+
if (_item != null) {
298298
joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
299299
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix))));
300300
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
413413
if ({{getter}}() != null) {
414414
int i = 0;
415415
for ({{items.dataType}} _item : {{getter}}()) {
416-
if ({{getter}}().get(i) != null) {
416+
if (_item != null) {
417417
joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
418418
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix))));
419419
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
411411
if ({{getter}}() != null) {
412412
int i = 0;
413413
for ({{items.dataType}} _item : {{getter}}()) {
414-
if ({{getter}}().get(i) != null) {
414+
if (_item != null) {
415415
joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
416416
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix))));
417417
}

0 commit comments

Comments
 (0)