UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

41 lines (40 loc) 1.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.referenceTypeParser = referenceTypeParser; const standardLoader_1 = require("../../../../core/loader/standardLoader"); const helper_1 = require("../../../../helper"); const type_1 = require("../../../../type"); const utils_1 = require("../../../../utils"); const normalize_1 = __importDefault(require("../normalize")); const utils_2 = require("./utils"); function referenceTypeParser(schema, ctx) { const refName = standardLoader_1.standardLoader.transformRefName(schema.$ref); const refernceAST = { ...(0, utils_2.initAST)(schema, ctx), type: type_1.ASTType.REFERENCE, params: refName, }; if (ctx.visited.has(schema.$ref)) { refernceAST.deepComment = helper_1.CommentHelper.load({ type: ctx.options.commentType, }) .add('[cycle]', ctx.pathMap.get(schema.$ref)) .end(); return refernceAST; } const nextSchema = normalize_1.default.normalize((0, utils_1.dereference)(schema, ctx.options.document)); ctx.visited.add(schema.$ref); ctx.pathMap.set(schema.$ref, ctx.path.join('.')); ctx.keyName = refName; const result = ctx.next(nextSchema, ctx.options); ctx.options.onReference?.(result); ctx.visited.delete(schema.$ref); return result; } exports.default = { type: 'reference', parse: referenceTypeParser, };