UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

67 lines (66 loc) 2.51 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.astParse = astParse; const type_1 = require("../../../../type"); const array_1 = __importDefault(require("./array")); const enum_1 = __importDefault(require("./enum")); const group_1 = __importDefault(require("./group")); const object_1 = __importDefault(require("./object")); const reference_1 = __importDefault(require("./reference")); const simple_1 = __importDefault(require("./simple")); const tuple_1 = __importDefault(require("./tuple")); const utils_1 = require("./utils"); __exportStar(require("./type"), exports); function astParse(schema, options) { const doParse = (schema, ctx) => { const value = (0, utils_1.parse)(schema, { type: (0, utils_1.getParserSchemaType)(schema), ctx, parsers: [array_1.default, object_1.default, enum_1.default, simple_1.default, reference_1.default, tuple_1.default, group_1.default], }); if (!value) { return { type: type_1.ASTType.UNKNOWN, }; } return value; }; const ctx = { options, next(schema, options) { const hasPathKey = !!ctx.pathKey; if (hasPathKey) { ctx.path.push(ctx.pathKey); ctx.pathKey = ''; } ctx.options = options; const nextAST = doParse(schema, ctx); if (hasPathKey) { ctx.path.pop(); } return nextAST; }, keyName: '', visited: new Set(), pathMap: new Map(), path: ['$'], }; return doParse(schema, ctx); }