Skip to content

Improved Enum Naming Options to Avoid Collision #191

Closed
@bowenwr

Description

@bowenwr

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

When two components have an enum field with the same name, the second Enum class generated is just incremented with a number. For instance, given a field status, the two generated classes will be Status and Status1. It makes for a rather unhelpful name.

Given spec snippet:

    CheckoutRecord:
      type: object
      properties:
        status:
          type: string
          enum: ['AVAILABLE', 'RESERVED', 'CHECKED_OUT']

    Task:
      type: object
      properties:
        status:
          type: string
          enum: ['RUNNING', 'SUCCEEDED', 'FAILED']

Generates Enum classes:

class Status(str, Enum):
    AVAILABLE = "AVAILABLE"
    RESERVED = "RESERVED"
    CHECKED_OUT = "CHECKED_OUT"
class Status1(str, Enum):
    RUNNING = "RUNNING"
    SUCCEEDED = "SUCCEEDED"
    FAILED = "FAILED"

Describe the solution you'd like

I think the best thing to have for compatibility here might be to add an option to the generator which will prepend the component name to the generated Enum class.

For example, given the example above the two generated Enums would be CheckoutRecordStatus and TaskStatus. Naming collision is very unlikely in this case and the names are much more helpful.

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