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
  • #5859
Closed
Open
Issue created Apr 08, 2020 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

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

Created by: Wrakor

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 (closed) #2012

Suggest a fix

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

Assignee
Assign to
Time tracking