UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

51 lines (50 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.groupTypeParser = groupTypeParser; const helper_1 = require("../../../../helper"); const type_1 = require("../../../../type"); const utils_1 = require("./utils"); function groupTypeParser(schema, ctx) { const result = { ...(0, utils_1.initAST)(schema, ctx), }; const items = schema.anyOf || schema.oneOf || schema.allOf || []; const params = items.map(value => ctx.next(value, ctx.options)); const deepCommenter = helper_1.CommentHelper.load({ type: ctx.options.commentType, }); params.forEach((itemsAst, idx) => { const comment = helper_1.CommentHelper.parseStr(itemsAst.comment ?? ''); const deepComment = helper_1.CommentHelper.parseStr(itemsAst.deepComment ?? ''); if (comment || deepComment) { deepCommenter .add(`[params${idx + 1}] start`) .add(comment) .add(deepComment) .add(`[params${idx + 1}] end`); } }); result.deepComment = deepCommenter.end(); if (schema.anyOf || schema.oneOf) { return { ...result, type: type_1.ASTType.UNION, params, }; } if (schema.allOf) { // 显式检查 allOf return { ...result, type: type_1.ASTType.INTERSECTION, params, }; } throw helper_1.logger.throwError('schema must contain anyOf, oneOf or allOf', { schema, }); } exports.default = { type: 'group', parse: groupTypeParser, };