-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
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
When generating Kotlin models (library: jvm-retrofit2, gson), an integer backed enum which includes x-enum-varnames and x-enum-descriptions produces enum entries where @SerializedName equals the numeric enum values (e.g., "12", "20").
Expected behavior is to have @SerializedName use the string names provided via x-enum-varnames, while keeping the underlying val value: Int as the wire value.
openapi-generator version
- 7.16.0
- 7.20.0-SNAPSHOT (commit : cc045ab)
OpenAPI declaration file content or url
Minimal reproducible spec:
openapi: 3.1.0
info:
title: Bar API
version: 1.0.0
components:
schemas:
GlassSize:
description: Size of the glass to order.
type: integer
enum:
- 20
- 12
- 16
- 40
x-enum-descriptions:
- 'Pint - Conical with bulge near top'
- 'Pilsner - Slender, hourglass shape'
- 'Stemmed - Short stem with wide, short bowl'
- 'Mug - Straight sides with handle; may feature dimples'
x-enum-varnames:
- Pint
- Pilsner
- Stemmed
- Mug
default: 12Generation Details
Config:
generatorName: 'kotlin'
library: 'jvm-retrofit2'
additionalProperties:
enumPropertyNaming: 'UPPERCASE' # 'original'
serializationLibrary: 'gson'CLI:
openapi-generator generate \
-g kotlin \
-i example-api.yml \
-o ./generated \
-c config.yamlSteps to reproduce
- Save the YAML spec above as
example-api.yml. - Save the config as
config.yaml. - Run the CLI command shown above.
- Inspect the generated
GlassSizeenum.
Actual output
enum class GlassSize(val value: kotlin.Int) {
@SerializedName(value = "20")
Pint(20),
@SerializedName(value = "12")
Pilsner(12),
@SerializedName(value = "16")
Stemmed(16),
@SerializedName(value = "40")
Mug(40);
// ...
}Notes:
Even with enumPropertyNaming: UPPERCASE, the enum identifiers aren’t uppercased in this case (secondary issue), and
@SerializedName is set to the numeric values as strings.
Expected output
enum class GlassSize(val value: kotlin.Int) {
@SerializedName(value = "Pint")
PINT(20),
@SerializedName(value = "Pilsner")
PILSNER(12),
@SerializedName(value = "Stemmed")
STEMMED(16),
@SerializedName(value = "Mug")
MUG(40);
// ...
}