OpenAPITools / OpenAPITools/openapi-generator
[BUG][ALL GENERATORS] enums with x-enum-varnames do not respect 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? YES
- Have you validated the input using an OpenAPI validator (example)? YES
- What's the version of OpenAPI Generator used? 4.1.2
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
Description
If an API is relying on x-enum-varnames to provide enums' names, enumPropertyNaming is not applied.
This is because the DefaultGenerator does not use toEnumVarName to process x-enum-varnames extensions.
openapi-generator version
4.1.2 (still present in master)
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: 'ping test'
version: '1.0'
servers:
- url: 'http://localhost:9999/'
paths:
/ping:
get:
operationId: pingGet
responses: {'201': {description: OK}}
components:
schemas:
WeatherType: null
type: integer
format: int32
enum:
- 42
- 18
- 56
x-enum-varnames:
- Sunny
- Cloudy
- Rainy
Command line used for generation
generate -i api.yaml -g kotlin -o output -p enumPropertyNaming=UPPERCASE
Steps to reproduce
Generate, open WeatherType.kt
Expected output:
enum class WeatherType(val rawValue: kotlin.Int) {
SUNNY(42),
CLOUDY(18),
RAINY(56);
}
Actual output:
enum class WeatherType(val rawValue: kotlin.Int) {
Sunny(42),
Cloudy(18),
Rainy(56);
}
Related issues/PRs
None
Suggest a fix
When processing x-enum-varnames in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L4346-L4361 We should make sure to call toEnumVarName to correctly generate the name.
Another solution could be to delay to call to toEnumVarName until after x-enum-varnames has been processed in postProcessModelsEnum (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L372-L378)
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 by reproducing the issue with the Kotlin generator and enumPropertyNaming=UPPERCASE, then inspect DefaultCodegen.java around lines 4346-4361 and postProcessModelsEnum around lines 372-378. Compare the generated WeatherType.kt names with the expected uppercase output; done means x-enum-varnames respects enumPropertyNaming.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100