Skip to content

Add an option to generate type aliases for schemas #1543

Closed
@tgross35

Description

@tgross35

Description

Schemas are probably the closest representation of TS types and are reused in similar ways. It is somewhat awkward to refer to them using their string paths all the time.

Proposal

Add a flag like --generate-schema-type-aliases that will generate type aliases for schema types. For example, with the below:

export interface components {
    schemas: {
        /** About */
        About: {
            name: string;
            version: string;
            /** Format: date */
            build_date: string;
        };
    responses: never;
    parameters: never;
    requestBodies: never;
    headers: never;
    pathItems: never;
}

With the flag, there would be a new alias that could be directly imported:

type About = components["schemas"]["About"];

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs welcomePRs are welcome to solve this issue!enhancementNew feature or requestopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions