OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Kotlin] Optional parameters

Open
#2,012 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Kotlin Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?
    Generated argument types are kotlin.String, but should be kotlin.String?
Description

Client code generated: It is impossible to not provide an optional param to an API.

openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url
swagger: "2.0"
info:
  version: "2.1.4"
  title: "Test"
  description: ""
host: "example.cm"
basePath: "/2_0"
schemes:
  - "https"
paths:
  /data/foo:
    get:
      operationId: "getFoo"
      produces:
        - "application/json"
      parameters:
        - name: "t0"
          in: "query"
          required: false
          type: "string"
          format: "date-time"
          description: "Filter by start time, e.g. '2018-03-01T00-00'"
      responses:
        200:
          description: "200 response"
          schema:
            type: "string"
Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i test.yaml -g kotlin -o tmp/kotlin/

Steps to reproduce
  1. Generate the code.
  2. Open vi tmp/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt
  3. See getFoo argument type.
Suggest a fix

Arguments for which spec says "required: false", should be optional (followed by ? in Kotlin).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied OpenAPI YAML and the documented generation command, then inspect tmp/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt at getFoo. Trace how the Kotlin generator derives that argument type; done means an optional parameter is generated with the nullable kotlin.String? type and the generated client allows it to be omitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.