Skip to content

Parse Enums with spaces #198

Closed
Closed
@bowenwr

Description

@bowenwr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions