mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
23 lines
766 B
TypeScript
23 lines
766 B
TypeScript
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 function 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 === OpenApiVersion.V3) {
|
|
return v as OpenApiVersion;
|
|
}
|
|
}
|
|
throw new Error(`Unsupported Open API version: "${String(info)}"`);
|
|
}
|