[BUG][kotlin][jvm-retrofit2] unnecessary nullable type of OkHttpClient / small fix in docstring
Created by: warahiko
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
- unnecessary nullable type of OkHttpClient
In the function createService()
of generated infrastructure/ApiClient.kt
file, the variable usedClient
has nullable type.
But here it should be NonNullable.
Retrofit.Builder.client()
receives OkHttpClient
instance, and checks it is NonNull.
So in IDE such as AndroidStudio, an error occurs.
The actual output
fun <S> createService(serviceClass: Class<S>): S {
var usedClient: OkHttpClient? = null
this.okHttpClient?.let { usedClient = it } ?: run {usedClient = clientBuilder.build()}
return retrofitBuilder.client(usedClient).build().create(serviceClass)
}
The expected output
fun <S> createService(serviceClass: Class<S>): S {
val usedClient: OkHttpClient = this.okHttpClient ?: clientBuilder.build()
return retrofitBuilder.client(usedClient).build().create(serviceClass)
}
- small fix in docstrings
In the generated API files, the indent of the docstrings is irregular.
The actual output
interface PetApi {
/**
* Add a new pet to the store
*
* Responses:
* - 405: Invalid input
*
* @param body Pet object that needs to be added to the store
* @return [Call]<[Unit]>
*/
@POST("pet")
fun addPet(@Body body: Pet): Call<Unit>
...
}
The expected output
interface PetApi {
/**
* Add a new pet to the store
*
* Responses:
* - 405: Invalid input
*
* @param body Pet object that needs to be added to the store
* @return [Call]<[Unit]>
*/
@POST("pet")
fun addPet(@Body body: Pet): Call<Unit>
...
}
openapi-generator version
master (61b543f0)
OpenAPI declaration file content or url
(it is described in 2 - Getting Started)
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
-g kotlin --library jvm-retrofit2 -o kotlin-retrofit2-client -t modules/openapi-generator/src/main/resources/kotlin-client
Steps to reproduce
Run the above command-line
Related issues/PRs
Suggest a fix
I will submit a PR.