Skip to content

Parse Enums with spaces #198

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

Closed
bowenwr opened this issue Sep 23, 2020 · 2 comments
Closed

Parse Enums with spaces #198

bowenwr opened this issue Sep 23, 2020 · 2 comments
Labels
✨ enhancement New feature or improvement

Comments

@bowenwr
Copy link
Contributor

bowenwr commented Sep 23, 2020

Is your feature request related to a problem? Please describe.

Attempting to parse an Enum with spaces in it causes an error.

Example component:

    SampleComponent:
      type: object
      properties:
        reason:
          type: string
          description: Component that won't parse
          enum:
            - Made in error
            - Other

Produces an Enum entry with a name MADE IN ERROR which is invalid and results in models/reason.py: Cannot parse: 5:9: MADE IN ERROR = "Made in error"

Describe the solution you'd like
Replace spaces (and probably other similar characters) with underscore to produce:

class Reason(str, Enum):
    MADE_IN_ERROR = "Made in error"
    OTHER = "Other"

This could introduce some naming collision if say we had both "Made in error" and "Made:in:error" but that seems like this would solve almost all reasonable cases.

Describe alternatives you've considered
Currently we are not able to use an Enum for this.

@bowenwr bowenwr added the ✨ enhancement New feature or improvement label Sep 23, 2020
@bowenwr
Copy link
Contributor Author

bowenwr commented Sep 23, 2020

For clarification, this only seems to happen when it's defined under components. If it's just left as part of the request body definition, however, the file creates the class as expected but does not appear to import Enum.

@dbanty dbanty closed this as completed in ec9e485 Sep 26, 2020
@dbanty
Copy link
Collaborator

dbanty commented Sep 26, 2020

Will be fixed in 0.6.1 coming later today. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants