Bug Report Checklist
Description
When using enumUnknownDefaultCase=true with the Go generator and enumClassPrefix=false (the default), every generated enum type emits a bare UNKNOWN_DEFAULT_OPEN_API constant. Since all enum models live in the same Go package, this causes a compilation error:
UNKNOWN_DEFAULT_OPEN_API redeclared in this block
model_status_a.go:XX: other declaration of UNKNOWN_DEFAULT_OPEN_API
The sentinel constant is added as an enumVar and rendered through the same template path as regular constants:
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}}
When enumClassPrefix=false, no prefix is applied, so every enum gets an identical UNKNOWN_DEFAULT_OPEN_API constant.
Setting enumClassPrefix=true fixes the collision but renames all existing enum constants (e.g. ProvisionHalted becomes MODELPROVISIONSTAGEVALUE_ProvisionHalted), which is a breaking change for consumers.
openapi-generator version
7.22.0 (not a regression — this is the first release with Go support for enumUnknownDefaultCase, introduced by PR #23417)
OpenAPI declaration file content or url
openapi: 3.0.1
info:
version: 1.0.0
title: Test API
paths: {}
components:
schemas:
StatusA:
type: string
enum:
- active
- inactive
StatusB:
type: string
enum:
- pending
- completed
Generation Details
openapi-generator-cli generate \
-i spec.yaml \
-g go \
--additional-properties enumUnknownDefaultCase=true \
--package-name myapi
Steps to reproduce
- Generate a Go client with the above spec and
enumUnknownDefaultCase=true (without enumClassPrefix=true)
- Attempt to compile the generated code:
go build ./...
- Observe:
UNKNOWN_DEFAULT_OPEN_API redeclared in this block
Related issues/PRs
Suggest a fix
The sentinel constant should be unique per enum type when enumClassPrefix=false. The template could unconditionally prefix the sentinel with the classname, e.g.:
{{{classname}}}UnknownDefaultOpenApi {{{classname}}} = "unknown_default_open_api"
This would generate StatusAUnknownDefaultOpenApi, StatusBUnknownDefaultOpenApi, etc. — unique names without requiring enumClassPrefix=true and without renaming existing constants.
Bug Report Checklist
Description
When using
enumUnknownDefaultCase=truewith the Go generator andenumClassPrefix=false(the default), every generated enum type emits a bareUNKNOWN_DEFAULT_OPEN_APIconstant. Since all enum models live in the same Go package, this causes a compilation error:The sentinel constant is added as an
enumVarand rendered through the same template path as regular constants:When
enumClassPrefix=false, no prefix is applied, so every enum gets an identicalUNKNOWN_DEFAULT_OPEN_APIconstant.Setting
enumClassPrefix=truefixes the collision but renames all existing enum constants (e.g.ProvisionHaltedbecomesMODELPROVISIONSTAGEVALUE_ProvisionHalted), which is a breaking change for consumers.openapi-generator version
7.22.0 (not a regression — this is the first release with Go support for
enumUnknownDefaultCase, introduced by PR #23417)OpenAPI declaration file content or url
Generation Details
Steps to reproduce
enumUnknownDefaultCase=true(withoutenumClassPrefix=true)go build ./...UNKNOWN_DEFAULT_OPEN_API redeclared in this blockRelated issues/PRs
enumUnknownDefaultCasefor GoSuggest a fix
The sentinel constant should be unique per enum type when
enumClassPrefix=false. The template could unconditionally prefix the sentinel with the classname, e.g.:This would generate
StatusAUnknownDefaultOpenApi,StatusBUnknownDefaultOpenApi, etc. — unique names without requiringenumClassPrefix=trueand without renaming existing constants.