Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7591
Closed
Open
Issue created Oct 04, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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
  1. 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. スクリーンショット 2020-10-04 19 39 55

So in IDE such as AndroidStudio, an error occurs. スクリーンショット 2020-10-04 16 46 36

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)
}
  1. 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

https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml

(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.

Assignee
Assign to
Time tracking