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)