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

Adding support for named integer enums #1214

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

barrybarrette
Copy link

Adding support for named enums via an optional extension, x-enum-varnames.

This extension is added to the schema inline with the enum definition:

 "Siva.e_Install_State": {
        "enum": [
          0,
          1,
          2,
          3,
          4,
          5,
          6,
          99
        ],
        "type": "integer",
        "format": "int32",
        "x-enum-varnames": [
          "Deinstalled",
          "Installed",
          "Upcoming_Site",
          "Lab_Site",
          "Pending_Deinstall",
          "Suspended",
          "Install_In_Progress",
          "Unknown"
        ]
      },

The result:
image

@barrybarrette barrybarrette changed the title Adding support for named enums Adding support for named integer enums Mar 6, 2025
@dbanty
Copy link
Collaborator

dbanty commented Mar 15, 2025

I've resisted adding custom OpenAPI attributes just for this generator... ideally, we could adopt conventions used by more popular projects, like OpenAPITools. Is x-enum-varnames used elsewhere already?

@barrybarrette
Copy link
Author

ideally, we could adopt conventions used by more popular projects, like OpenAPITools. Is x-enum-varnames used elsewhere already?

Yes, OpenAPITools adopted it in this PR -> OpenAPITools/openapi-generator#917

I did also search around for any other official or even adopted standard for this but came up empty.

@barrybarrette
Copy link
Author

Just fixed the possible null reference that failed tests. Also added a sanity check to ensure the lengths of the var_names matches the length of the actual values, inspired by the OpenAPITools implementation.

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

Successfully merging this pull request may close these issues.

2 participants