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

Spaces in enum values are not honored #55

Open
AaronKluck opened this issue Nov 14, 2023 · 0 comments
Open

Spaces in enum values are not honored #55

AaronKluck opened this issue Nov 14, 2023 · 0 comments

Comments

@AaronKluck
Copy link

Describe the bug
With other generators, spaces in enum values work perfectly fine. But with openapi-python-generator, spaces are replaced by underscores. This causes the generated client to be incompatible with the actual service!

I traced this behavior to where this regex determining value_dict["enum"] values to feed the ENUM_TEMPLATE Jinja template. I'm not experienced with Jinja, but I expect a separate key-value pair could be used with it somehow instead.

To Reproduce
Define an enum with spaces in one or more values, e.g.

    "components": {
        "schemas": {
            "ThingType": {
                "title": "ThingType",
                "enum": [
                    "big thing",
                    "small thing"
                ],
                "type": "string"
            },

The resulting model looks like this:

class ThingType(str, Enum):

    BIG_THING = "big_thing"
    SMALL_THING = "small_thing"

Expected behavior
Enum names should have invalid characters converted to underscores, but the values should be preserved. In the above example, I would expect:

class ThingType(str, Enum):

    BIG_THING = "big thing"
    SMALL_THING = "small thing"

Additional context
I attached a sample OpenAPI spec that trivially causes this to happen.

enum_with_spaces.json

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

No branches or pull requests

1 participant