OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-spring] generator double-quotes stringy default query parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When specifying a stringy default value for a query parameter, the RequestParam annotation is generated with a duplicate set of quotes. This causes an error at compile time.
parameters:
- in: query
name: sortBy
schema:
type: string
default: id
@RequestParam(value = "sortBy", required = false, defaultValue=""id"")
openapi-generator version
This is a regression - the output in 5.0.0 was as expected,
@RequestParam(value = "sortBy", required = false, defaultValue="id")
while 5.1.1 (and 5.2.0-SNAPSHOT) generate the following
@RequestParam(value = "sortBy", required = false, defaultValue=""id"")
OpenAPI declaration file content or url
OpenAPI file:
openapi: 3.0.3
info:
title: Reproducer
version: "1.0"
servers:
- url: http://example.org
paths:
"/":
get:
parameters:
- in: query
name: sortBy
schema:
type: string
default: id
responses:
200:
description: "A response"
Generation Details
Command to generate faulty code:
openapi-generator-cli version-manager set 5.1.1
openapi-generator-cli generate -i default-params.yaml -o default-params_5.1.1/ -g kotlin-spring
Command to generate working code:
openapi-generator-cli version-manager set 5.0.0
openapi-generator-cli generate -i default-params.yaml -o default-params_5.0.0/ -g kotlin-spring
Steps to reproduce
- Save attached file as
default-params.yaml: default-params.txt - Execute generation script below
- Compare output
openapi-generator-cli version-manager set 5.1.1
openapi-generator-cli generate -i default-params.yaml -o default-params_5.1.1/ -g kotlin-spring
openapi-generator-cli version-manager set 5.0.0
openapi-generator-cli generate -i default-params.yaml -o default-params_5.0.0/ -g kotlin-spring
diff default-params_5.0.0/src/main/kotlin/org/openapitools/api/DefaultApi.kt default-params_5.1.1/src/main/kotlin/org/openapitools/api/DefaultApi.kt
< fun rootGet( @RequestParam(value = "sortBy", required = false, defaultValue="id") sortBy: kotlin.String
---
> fun rootGet( @RequestParam(value = "sortBy", required = false, defaultValue=""id"") sortBy: kotlin.String
Related issues/PRs
Same issue as back in #540
Maybe caused by #8577, but that PR targeted Java.
Suggest a fix
The fix might be in the same place as #5776, but I'm not sure how many kotlin generators are really affected by this
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided default-params.yaml and run the kotlin-spring generation commands for versions 5.1.1 and 5.0.0. Compare the generated src/main/kotlin/org/openapitools/api/DefaultApi.kt and review the related guidance in #5776; done means the defaultValue for sortBy has one quoted id and the generated Kotlin compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100