-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Bug][Kotlin-client] Can now handle path param of type list #12244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9b8460e
b444a32
80c48eb
dae5b33
a84308f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-array-simple-string | ||
| outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3 | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-array-simple-string | ||
| artifactId: kotlin-array-simple-string-jvm-okhttp3 | ||
| library: jvm-okhttp3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4 | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-array-simple-string-jvm-okhttp4 | ||
| library: jvm-okhttp4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-volley | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-array-simple-string-jvm-volley | ||
| library: jvm-volley | ||
| serializationLibrary: gson | ||
| generateRoomModels: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-array-simple-string-multiplatform | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-array-simple-string-multiplatform | ||
| library: multiplatform |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import com.android.volley.RequestQueue | |
| import com.android.volley.Response | ||
| import com.android.volley.toolbox.BaseHttpStack | ||
| import com.android.volley.toolbox.Volley | ||
| import java.util.*; | ||
| import java.util.* | ||
| import kotlin.coroutines.resume | ||
| import kotlin.coroutines.resumeWithException | ||
| import kotlin.coroutines.suspendCoroutine | ||
|
|
@@ -52,47 +52,34 @@ class {{classname}} ( | |
| {{^bodyParam}} | ||
| val body: Any? = null | ||
| {{/bodyParam}} | ||
| {{#allParams}} | ||
| {{#required}} | ||
| // verify the required parameter '{{paramName}}' is set | ||
| // This is probably taken care of by non-null types anyway | ||
| requireNotNull({{paramName}}) | ||
| {{/required}} | ||
| {{/allParams}} | ||
|
Comment on lines
55
to
61
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Kotlin type systems makes sure that the parameters cannot be null. Completely redundant check. |
||
|
|
||
| val contentTypes : Array<String> = arrayOf({{#consumes}}"{{{mediaType}}}"{{^-last}},{{/-last}}{{/consumes}}) | ||
| val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } | ||
|
|
||
| // Do some work or avoid some work based on what we know about the model, | ||
| // Do some work or avoid some work based on what we know about the model, | ||
| // before we delegate to a pluggable request factory template | ||
| // The request factory template contains only pure code and no templates | ||
| // to make it easy to override with your own. | ||
|
|
||
| // create path and map variables | ||
| val path = "{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", IRequestFactory.escapeString({{{paramName}}}.toString())){{/pathParams}}; | ||
| val path = "{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}IRequestFactory.escapeString({{{paramName}}}.toString()){{/isContainer}}){{/pathParams}} | ||
|
Comment on lines
72
to
65
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bugfix (#7199) to handle that you can't use |
||
|
|
||
| // form params | ||
| val formParams = mapOf<String, String>( | ||
| {{#formParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), | ||
| {{/formParams}} | ||
| ) | ||
| val formParams = mapOf<String, String>({{^formParams}}){{/formParams}}{{#formParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} | ||
| ){{/-last}}{{/formParams}} | ||
|
|
||
|
|
||
| // TODO: Cater for allowing empty values | ||
| // TODO, if its apikey auth, then add the header names here and the hardcoded auth key | ||
| // Only support hard coded apikey in query param auth for when we do this first path | ||
| val queryParams = mapOf<String, String>( | ||
| {{#queryParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), | ||
| {{/queryParams}} | ||
| ).filter { it.value.isNotEmpty() } | ||
|
|
||
| val headerParams: Map<String, String> = mapOf( | ||
| {{#headerParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), | ||
| {{/headerParams}} | ||
| ) | ||
| val queryParams = mapOf<String, String>({{^queryParams}}){{/queryParams}}{{#queryParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} | ||
| ){{/-last}}{{/queryParams}} | ||
| .filter { it.value.isNotEmpty() } | ||
|
|
||
| val headerParams: Map<String, String> = mapOf({{^headerParams}}){{/headerParams}}{{#headerParams}} | ||
| "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} | ||
| ){{/-last}}{{/headerParams}} | ||
|
|
||
| return suspendCoroutine { continuation -> | ||
| val responseListener = Response.Listener<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}> { response -> | ||
|
|
@@ -119,7 +106,7 @@ class {{classname}} ( | |
| responseListener, | ||
| errorListener) | ||
|
|
||
| postProcessors.forEach{ it.invoke(request)} | ||
| postProcessors.forEach { it.invoke(request) } | ||
|
|
||
| requestQueue.value.add(request) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| {{#generateRoomModels}} | ||
| android.useAndroidX=true | ||
| {{#generateRoomModels}} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jvm-volley refuses to build without |
||
| android.enableJetifier=true | ||
| {{/generateRoomModels}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,19 +60,14 @@ import kotlinx.serialization.encoding.* | |
| {{/hasFormParams}} | ||
| {{/hasBodyParam}} | ||
|
|
||
| val localVariableQuery = mutableMapOf<String, List<String>>() | ||
| {{#queryParams}} | ||
| {{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{{paramName}}}"){{/isContainer}} } | ||
| {{/queryParams}} | ||
|
|
||
| val localVariableHeaders = mutableMapOf<String, String>() | ||
| {{#headerParams}} | ||
| {{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} } | ||
| {{/headerParams}} | ||
| val localVariableQuery = mutableMapOf<String, List<String>>(){{#queryParams}} | ||
| {{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{{paramName}}}"){{/isContainer}} }{{/queryParams}} | ||
| val localVariableHeaders = mutableMapOf<String, String>(){{#headerParams}} | ||
| {{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} }{{/headerParams}} | ||
|
|
||
| val localVariableConfig = RequestConfig<kotlin.Any?>( | ||
| RequestMethod.{{httpMethod}}, | ||
| "{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", "${{{paramName}}}"){{/pathParams}}, | ||
| "{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}"${{{paramName}}}"{{/isContainer}}){{/pathParams}}, | ||
|
Comment on lines
75
to
70
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bugfix (#7199) to handle that you can't use |
||
| query = localVariableQuery, | ||
| headers = localVariableHeaders | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| rootProject.name = 'kotlin-array-simple-string-jvm-okhttp3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying code