Skip to content
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

[BUG] [Kotlin] Kotlin-client with retrofit2 doesn't generate nullable parameters #5859

Open
5 tasks done
Wrakor opened this issue Apr 8, 2020 · 0 comments
Open
5 tasks done

Comments

@Wrakor
Copy link

Wrakor commented Apr 8, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

The kotlin-client generator when using Retrofit2 library generates a DefaultApi.kt file that doesn't mark optional parameters as nullable.

openapi-generator version

openapi-generator-cli/4.3.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 0.0.1
  title: Optional Parameter Demo
paths:
  /foo:
    get:
      parameters:
        - in: query
          name: optional
          required: false
          schema:
            type: integer
        - in: query
          name: mandatory
          required: true
          schema:
            type: integer
      responses:
        200:
          description: ''
          content:
            text/plain:
              schema:
                type: integer
Command line used for generation

java -jar .\openapi-generator-cli-4.3.0.jar generate -i ".\foo.yaml" --artifact-id kotlin-client -g kotlin -o generated --library jvm-retrofit2

Steps to reproduce
  1. Run the above command on the declaration file provided

Result will be:

package org.openapitools.client.apis

import org.openapitools.client.infrastructure.CollectionFormats.*
import retrofit2.http.*
import retrofit2.Call
import okhttp3.RequestBody
import okhttp3.ResponseBody
import okhttp3.MultipartBody


interface DefaultApi {
    @GET("/foo")
    fun fooGet(@Query("mandatory") mandatory: kotlin.Int, @Query("optional") optional: kotlin.Int): Call<kotlin.Int>

}
Related issues/PRs

#5198
#2012

Suggest a fix

Optional parameter should be @Query("optional") optional: kotlin.Int?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant