[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
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}}