Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][GO-SERVER] Enum fromValue functions always returns string in case of invalid values #20084

Open
4 of 6 tasks
simodima opened this issue Nov 12, 2024 · 0 comments · May be fixed by #20085
Open
4 of 6 tasks

[BUG][GO-SERVER] Enum fromValue functions always returns string in case of invalid values #20084

simodima opened this issue Nov 12, 2024 · 0 comments · May be fixed by #20085

Comments

@simodima
Copy link

simodima commented Nov 12, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

The current golang server enum template modules/openapi-generator/src/main/resources/go-server/model.mustache produces a bugged code for enum values.
The New{{{classname}}}FromValue function always returns an empty string when the ev is not valid, so for integer enums the code does not compile.

The bugged code is the following

func NewErrorCodesFromValue(v int32) (ErrorCodes, error) {
	ev := ErrorCodes(v)
	if ev.IsValid() {
		return ev, nil
	}

	return "", fmt.Errorf("invalid value '%v' for ErrorCodes: valid values are %v", v, AllowedErrorCodesEnumValues)
}

Expected output

func NewErrorCodesFromValue(v int32) (ErrorCodes, error) {
	ev := ErrorCodes(v)
	if ev.IsValid() {
		return ev, nil
	}
	noValue := new(ErrorCodes)
	return *noValue, fmt.Errorf("invalid value '%v' for ErrorCodes: valid values are %v", v, AllowedErrorCodesEnumValues)
}
openapi-generator version

The latest version is affected

OpenAPI declaration file content or url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant