question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] [Kotlin] Optional parameters

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
karismanncommented, May 21, 2019

@wing328 this issue can be closed as it has been fixed by the related PR with 4.0.0

0reactions
isycatcommented, Sep 3, 2020

I have submitted a small PR re. the above: https://github.com/OpenAPITools/openapi-generator/pull/7341

Who should I @? Someone/everyone from the kotlin technical committee? Or is posting here enough?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't omit default params when call Kotlin's function from Java ...
I need to write function (createSend) that has 3 params. But only last ( callback ) must be required. So to do this...
Read more >
Functions | Kotlin
Function parameters can have default values, which are used when you skip the corresponding argument. This reduces the number of overloads:.
Read more >
Quick Guide to Kotlin Default and Named Arguments - Baeldung
Kotlin requires that default values can only be specified in the base class functions.
Read more >
Using kotlin function with default parameters in java context
If you are using the annotation @JvmOverloads on kotlin function. It will automatically overload the provided function for you, creating “n” functions until ......
Read more >
Constructor default values - Kotlin Quick Reference
Default values for constructor parameters · When all parameters have default values, you don't have to provide any values when creating a new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found