UNPKG

openapi-ts-mock-generator

Version:
65 lines (64 loc) 1.82 kB
var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/parsers/openapi-parser.ts import SwaggerParser from "@apidevtools/swagger-parser"; var getOpenAPIDocsDeref = (path) => __async(void 0, null, function* () { const doc = yield SwaggerParser.dereference(path); const isOpenApiV3 = "openapi" in doc && doc.openapi.startsWith("3"); if (isOpenApiV3) return doc; return void 0; }); var getOpenAPIDocsBundle = (path) => __async(void 0, null, function* () { const doc = yield SwaggerParser.bundle(path); const isOpenApiV3 = "openapi" in doc && doc.openapi.startsWith("3"); if (isOpenApiV3) return doc; return void 0; }); var validateOpenAPIDoc = (path) => __async(void 0, null, function* () { try { yield SwaggerParser.validate(path); return true; } catch (error) { console.error("OpenAPI validation failed:", error); return false; } }); var extractSchemas = (doc) => { var _a; return ((_a = doc.components) == null ? void 0 : _a.schemas) || {}; }; var extractPaths = (doc) => { return doc.paths || {}; }; var getOpenAPIVersion = (doc) => { return doc.openapi || doc.swagger || "unknown"; }; export { extractPaths, extractSchemas, getOpenAPIDocsBundle, getOpenAPIDocsDeref, getOpenAPIVersion, validateOpenAPIDoc }; //# sourceMappingURL=openapi-parser.mjs.map