OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the additional parameter enumUnknownDefaultCase for other languages like Java, if the provided enum value is not found, the default case is returned. For Go that is not the case. Always the same error is provided, no matter the value of additional parameter.
openapi-generator version
7.6.0, no regression AFAIK
OpenAPI declaration file content or url
openapi: 3.0.1
info:
version: 1.0.0
title: Test API
paths: {}
components:
schemas:
TestEnum:
type: string
enum:
- SOME_VALUE
- SOME_OTHER_VALUE
Output code:
// List of TestEnum
const (
TESTENUM_VALUE TestEnum = "SOME_VALUE"
TESTENUM_OTHER_VALUE TestEnum = "SOME_OTHER_VALUE"
TESTENUM_UNKNOWN_DEFAULT_OPEN_API TestEnum = "11184809"
)
...
func (v *TestEnum) UnmarshalJSON(src []byte) error {
var value string
err := json.Unmarshal(src, &value)
if err != nil {
return err
}
enumTypeValue := TestEnum(value)
for _, existing := range AllowedTestEnumEnumValues {
if existing == enumTypeValue {
*v = enumTypeValue
return nil
}
}
return fmt.Errorf("%+v is not a valid TestEnum", value) <-- this line is the problem
}
...
Bug Report Checklist
Description
When using the additional parameter
enumUnknownDefaultCase
for other languages like Java, if the provided enum value is not found, the default case is returned. For Go that is not the case. Always the same error is provided, no matter the value ofadditional parameter
.openapi-generator version
7.6.0, no regression AFAIK
OpenAPI declaration file content or url
Output code:
Steps to reproduce
Simply run:
Related issues/PRs
Link to the related PR: https://github.com/OpenAPITools/openapi-generator/pull/18748
Suggest a fix