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
  • #10865
Closed
Open
Issue created Nov 16, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Kotlin] Default value should be generated in query param using Retrofit2

Created by: alitams

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

If the path has a query parameter which has default value, then the default value is not generated.

Generated output:

@POST("foo/bar")
fun inbox(@Query("size") size: kotlin.Int? = null): Completable

Expected output:

@POST("foo/bar")
fun inbox(@Query("size") size: kotlin.Int? = 10): Completable
openapi-generator version

5.3.0

OpenAPI declaration file content or url
  /foo/bar:
    post:
      tags:
        - "Foo"
      summary: "Retrieves something."
      description: "Provides something"
      operationId: "opid"
      parameters:
        - name: "size"
          in: "query"
          description: "Size"
          required: false
          schema:
            type: "integer"
            default: 10
    responses:
        "200":
          description: "Success."
         
Generation Details

Use the retrofit2 library.

Run this:

java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i xyz.yaml \
   -g kotlin-client \
   -o gen/generated \
   --additional-properties=library=jvm-retrofit2,useRxJava3=true,dateLibrary=threetenbp-localdatetime,enumPropertyNaming=UPPERCASE,serializationLibrary=jackson,enablePostProcessFile=true 
Steps to reproduce

Generate code with a path which has at least one parameter with a default value.

Related issues/PRs

In angular

Suggest a fix

In kotlin-client/libraries/jvm-retrofit2/queryParams.mustache Modify:

 {{^required}}? = null{{/required}} 

part to:

{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}
Assignee
Assign to
Time tracking