[BUG] [kotlin-spring] generator double-quotes stringy default query parameters
Created by: pilzm
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 (closed) 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