Skip to content

Reduce redundancy in generated OpenAPI definition names #125

Description

@mzpx

Reduce redundancy in generated OpenAPI definition names

Problem

Generated OpenAPI definitions repeat the same hierarchy in every type name.

This is not limited to schemas. The same pattern appears across:

  • Operations
  • Path items
  • Parameters
  • Request bodies
  • Responses
  • Schemas
  • Tags

For example:

WebMenuCreateOperation
WebMenuUpdateOperation
WebMenuIdPathItems
WebMenuCreateRequestBody
WebMenuDetailResponse
WebMenuCreateSchema
WebMenuTag

Repeating the resource hierarchy in every generated type makes the code unnecessarily verbose and increases the risk of inconsistent naming or typos.

Proposal

Generate nested namespaces that mirror the OpenAPI resource hierarchy.

For example:

enum Web {
    enum Menu {
        struct CreateOperation: OperationRepresentable { ... }
        struct UpdateOperation: OperationRepresentable { ... }

        struct IdPathItems: PathItemRepresentable { ... }

        struct CreateRequestBody: RequestBodyRepresentable { ... }

        struct DetailResponse: JSONResponseRepresentable { ... }

        struct CreateSchema: ObjectSchemaRepresentable { ... }

        struct Tag: TagRepresentable { ... }
    }
}

References would then become:

Web.Menu.CreateOperation()
Web.Menu.IdPathItems()
Web.Menu.DetailResponse()
Web.Menu.CreateSchema()

Benefits

  • Less redundant generated code.
  • Names mirror the OpenAPI resource hierarchy.
  • Shorter and more readable type names.
  • Reduced risk of naming inconsistencies and typos.
  • Easier navigation and refactoring.

Screenshots

Image Image Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions