utils/getOpenApiVersion.ts

openapi-typescript-codegen · src/utils/getOpenApiVersion.ts · typescript · MIT
integration, tag:knn-classified

Determines OpenAPI spec version from a loaded document.

// Source: https://github.com/ferdikoomen/openapi-typescript-codegen | License: MIT | Copyright Ferdi Koomen
// Provided via justclaw.it.com; keep this notice with the code.
export enum OpenApiVersion {
    V2 = 2,
    V3 = 3,
}

/**
 * Get the Open API specification version (V2 or V3). This generator only supports
 * version 2 and 3 of the specification, so we will alert the user if we encounter
 * an incompatible type. Or if the type is missing...
 * @param openApi The loaded spec (can be any object)
 */
export const getOpenApiVersion = (openApi: any): OpenApiVersion => {
    const info: any = openApi.swagger || openApi.openapi;
    if (typeof info === 'string') {
        const c = info.charAt(0);
        const v = Number.parseInt(c);
        if (v === OpenApiVersion.V2 || v === OpenApiV

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key