OpenAPITools / OpenAPITools/openapi-generator
[BUG][kotlin][jvm-spring-webclient] Query Parameter is created wrong, when using enum with non-default enumPropertyNaming
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
We want to call an API, which has an endpoint with a query parameter, with an enum set of values, e.g. a timeRange of OneWeek, OneMonth or OneYear.
We create the calling API classes via OpenAPIGenerator with generator kotlin and library jvm-spring-webclient and enumPropertyNaming=UPPERCASE.
The enum is created with all values in UPPERCASE and the original value is set in a variable called value.
enum class TimeRangeGetExample(val value: kotlin.String) {
@JsonProperty(value = "OneWeek") ONE_WEEK("OneWeek"),
@JsonProperty(value = "OneMonth") ONE_MONTH("OneMonth"),
@JsonProperty(value = "OneYear") ONE_YEAR("OneYear")
}
But when calling via the created API, the UPPERCASE name of the enum value is used instead of the original value written in the spec.
Expected:
example.com/example?timeRange=OneWeek
Actual:
example.com/example?timeRange=ONE_WEEK
The created API class contains following code:
fun getExampleRequestConfig(timeRange: TimeRangeGetExample) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
.apply {
put("timeRange", listOf(timeRange.toString()))
}
Instead of calling toString, the variable value has to be used
fun getExampleRequestConfig(timeRange: TimeRangeGetExample) : RequestConfig<Unit> {
val localVariableBody = null
val localVariableQuery = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
.apply {
put("timeRange", listOf(timeRange.value))
}
or the toString method has to be overwritten with:
override fun toString() = value
openapi-generator version
7.14.0
OpenAPI declaration file content or url
swagger: '2.0'
info:
version: v1
title: Test.Api
host: example.com
schemes:
- https
paths:
/example:
get:
operationId: getExample
consumes: [ ]
produces:
- application/json
- text/json
parameters:
- name: timeRange
in: query
required: true
type: string
enum:
- OneWeek
- OneMonth
- OneYear
responses:
'200':
description: OK
Generation Details
Maven Plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.14.0</version>
<configuration>
<generatorName>kotlin</generatorName>
<library>jvm-spring-webclient</library>
<configOptions>
<sourceFolder>src/main/kotlin</sourceFolder>
<serializationLibrary>jackson</serializationLibrary>
<enumPropertyNaming>UPPERCASE</enumPropertyNaming>
<useSpringBoot3>true</useSpringBoot3>
<omitGradlePluginVersions>true</omitGradlePluginVersions>
<omitGradleWrapper>true</omitGradleWrapper>
</configOptions>
</configuration>
<executions>
<execution>
<id>example</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<output>${project.build.directory}/generated-sources/example</output>
<inputSpec>${project.basedir}/src/main/resources/example/swagger.yml</inputSpec>
<apiPackage>${project.groupId}.example.client.api</apiPackage>
<modelPackage>${project.groupId}.example.client.dto</modelPackage>
<packageName>${project.groupId}.example.client.handler</packageName>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Use the generated API class to call the API endpoint. This will fail, because the query parameter will be created wrong.
Related issues/PRs
https://github.com/openapitools/openapi-generator/issues/21564 seems very similar, but is a different generator and library
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 Kotlin generator's jvm-spring-webclient output for getExampleRequestConfig and reproduce the issue using the supplied Swagger definition and Maven configuration. Check how the generated query parameter serializes the TimeRangeGetExample enum when enumPropertyNaming=UPPERCASE. Done means the generated request uses the original enum value, producing timeRange=OneWeek rather than timeRange=ONE_WEEK.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100