Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Investigate improving generation of enums #124

Closed
ctreatma opened this issue Aug 2, 2023 · 2 comments · Fixed by #145
Closed

Investigate improving generation of enums #124

ctreatma opened this issue Aug 2, 2023 · 2 comments · Fixed by #145

Comments

@ctreatma
Copy link
Contributor

ctreatma commented Aug 2, 2023

The Metal API spec has a number of inline enum definitions. There's a bug in the Go generator that treats these inline enums as strings instead of creating a Go enum for them: OpenAPITools/openapi-generator#2360.

Should we update the official spec to move all enums to dedicated files under components/schemas/?

Something to keep in mind here is that enum can cause problems on response models. For example, if a new value is introduced by the API, all existing SDKs will throw a validation error when they encounter that new value, effectively breaking any integrations based on generated SDKs

@ctreatma
Copy link
Contributor Author

The validation problem mentioned in this issue is being discussed more specifically and in more detail on equinix-labs/metal-java#113

@ctreatma ctreatma mentioned this issue Aug 30, 2023
2 tasks
ctreatma added a commit that referenced this issue Sep 15, 2023
This enables the [`RESOLVE_INLINE_ENUMS` option for
`openapi-generator@v7.0.0`](https://openapi-generator.tech/docs/customization#inline-schema-naming)
to tell the generator to create dedicated models for inline enums
instead of treating the inline enums as plain strings. Among other
things, generating inline enums helps the SDK properly validate API
responses against `oneOf` schemas in which each component schema has
different enum values for the same property name.

In addition to the `RESOLVE_INLINE_ENUMS` option, this also enables the
`enumClassPrefix` setting. Since the constants used in each enum are
defined in the same scope, we have to turn this setting on in order to
avoid conflicts between different enums that include identical values.

Fixes #124
@github-actions
Copy link
Contributor

This issue has been resolved in version 0.22.0 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant