forked from loafle/openapi-generator-original
[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>
This commit is contained in:
parent
d4c8c97e19
commit
90e468b9a3
@ -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,13 @@ 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)) {
|
||||
if (isLibrary(NATIVE) || isLibrary(APACHE)) {
|
||||
// default to true for native and apache-httpclient
|
||||
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(".", "/");
|
||||
|
@ -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))));
|
||||
}
|
||||
|
@ -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))));
|
||||
}
|
||||
|
@ -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))));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user