[Kotlin][client] Add nullable query parameter support (#4197)

* add nullable query parameter support

* remove redundant bracket
This commit is contained in:
William Cheng 2019-10-22 15:14:14 +08:00 committed by GitHub
parent 5d7bb17cc6
commit 9fe2f4d3ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 14 deletions

View File

@ -1893,7 +1893,7 @@ public class DefaultCodegen implements CodegenConfig {
} }
} }
if(composed.getRequired() != null) { if (composed.getRequired() != null) {
required.addAll(composed.getRequired()); required.addAll(composed.getRequired());
} }
addVars(m, unaliasPropertySchema(properties), required, unaliasPropertySchema(allProperties), allRequired); addVars(m, unaliasPropertySchema(properties), required, unaliasPropertySchema(allProperties), allRequired);
@ -2002,7 +2002,7 @@ public class DefaultCodegen implements CodegenConfig {
addProperties(properties, required, component); addProperties(properties, required, component);
} }
if(schema.getRequired() != null) { if (schema.getRequired() != null) {
required.addAll(schema.getRequired()); required.addAll(schema.getRequired());
} }
@ -5022,7 +5022,6 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.pattern = codegenProperty.pattern; codegenParameter.pattern = codegenProperty.pattern;
if (codegenProperty.complexType != null) { if (codegenProperty.complexType != null) {
imports.add(codegenProperty.complexType); imports.add(codegenProperty.complexType);
} }

View File

@ -33,9 +33,21 @@ import {{packageName}}.infrastructure.toMultiValue
{{/hasQueryParams}}{{#hasQueryParams}}mutableMapOf<kotlin.String, List<kotlin.String>>() {{/hasQueryParams}}{{#hasQueryParams}}mutableMapOf<kotlin.String, List<kotlin.String>>()
.apply { .apply {
{{#queryParams}} {{#queryParams}}
{{^required}}if ({{paramName}} != null) { {{^required}}
if ({{paramName}} != null) {
put("{{paramName}}", {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{paramName}}.toString()){{/isContainer}}) put("{{paramName}}", {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{paramName}}.toString()){{/isContainer}})
}{{/required}}{{#required}}put("{{paramName}}", {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{paramName}}.toString()){{/isContainer}}){{/required}} }
{{/required}}
{{#required}}
{{#isNullable}}
if ({{paramName}} != null) {
put("{{paramName}}", {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{paramName}}.toString()){{/isContainer}})
}
{{/isNullable}}
{{^isNullable}}
put("{{paramName}}", {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf({{paramName}}.toString()){{/isContainer}})
{{/isNullable}}
{{/required}}
{{/queryParams}} {{/queryParams}}
} }
{{/hasQueryParams}} {{/hasQueryParams}}