FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adding support for named integer enums by barrybarrette · Pull Request #1214 · openapi-generators/openapi-python-client · GitHub

Repository navigation

Adding support for named integer enums - #1214

Merged
dbanty merged 9 commits into
openapi-generators:mainfrom
barrybarrette:main
Mar 27, 2025
Merged

dbanty merged 9 commits into
openapi-generators:mainfrom
barrybarrette:main

Conversation

Copy link
Copy Markdown
Contributor

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:

barrybarrette changed the title Adding support for named enums Adding support for named integer enums Mar 6, 2025

dbanty commented Mar 15, 2025

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor 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.

Copy link
Copy Markdown
Contributor 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.

dbanty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looking good! In addition to the one thought below, could you add something to the README about this feature? It's kinda the only docs we have right now 😓

dbanty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this is good to go. We should come up with a way to emit warnings effectively that don't stop code from being generated, but that needs some broader thinking outside this change.

dbanty added this pull request to the merge queue Mar 27, 2025
Merged via the queue into openapi-generators:main with commit dd9ad5a Mar 27, 2025
knope-bot Bot mentioned this pull request Mar 27, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Mar 31, 2025
> [!IMPORTANT]
> Merging this pull request will create this release

## Features

### Adding support for named integer enums

#1214 by @barrybarrette

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

This extension is added to the schema inline with the `enum` definition:
```
"MyEnum": {
    "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](https://github.com/user-attachments/assets/780880b3-2f1f-49be-823b-f9abb713a3e1)

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
micha91 pushed a commit to micha91/openapi-python-client that referenced this pull request May 13, 2025
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](https://github.com/user-attachments/assets/780880b3-2f1f-49be-823b-f9abb713a3e1)

---------

Co-authored-by: Barry Barrette <bbarrette@sonifi.com>
micha91 pushed a commit to micha91/openapi-python-client that referenced this pull request May 13, 2025
> [!IMPORTANT]
> Merging this pull request will create this release

## Features

### Adding support for named integer enums

openapi-generators#1214 by @barrybarrette

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

This extension is added to the schema inline with the `enum` definition:
```
"MyEnum": {
    "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](https://github.com/user-attachments/assets/780880b3-2f1f-49be-823b-f9abb713a3e1)

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
github-merge-queue Bot pushed a commit that referenced this pull request Mar 10, 2026
Building on
#1214,
this allows customization of string enumerations in exactly the same way
as integer enumerations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL