UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

41 lines (40 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.openApiHelper = exports.OpenApiHelper = exports.supportedApiMethods = void 0; const type_1 = require("../../type"); exports.supportedApiMethods = [type_1.HttpMethod.GET, type_1.HttpMethod.PUT, type_1.HttpMethod.POST, type_1.HttpMethod.DELETE]; class OpenApiHelper { load(document) { this.document = document; return this; } static load(document) { const ins = new OpenApiHelper(); return ins.load(document); } getApiMethods() { const paths = this.document.paths || []; const apiMethods = []; for (const [url, pathInfo] of Object.entries(paths)) { if (!pathInfo) { continue; } for (const [method, operationObject] of Object.entries(pathInfo)) { if (!exports.supportedApiMethods.includes(method)) { continue; } if (typeof operationObject === 'string' || Array.isArray(operationObject)) { continue; } apiMethods.push({ url, method, operationObject, }); } } return apiMethods; } } exports.OpenApiHelper = OpenApiHelper; exports.openApiHelper = new OpenApiHelper();