UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

35 lines (34 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.groupTypeGenerator = groupTypeGenerator; const type_1 = require("../../../../type"); const utils_1 = require("./utils"); function groupTypeGenerator(ast, ctx) { const result = { name: ast.keyName ?? '', comment: (0, utils_1.setComment)(ast, ctx.options), type: 'type', code: '', }; const groups = []; ast.params.forEach((item) => { ctx.pathKey = `${item.keyName}`; const nextValue = ctx.next(item, ctx.options); groups.push(`(${(0, utils_1.getValue)(nextValue, ctx.options)})`); }); switch (ast.type) { case type_1.ASTType.INTERSECTION: result.code = groups.join(' & '); break; case type_1.ASTType.UNION: result.code = groups.join(' | '); break; default: break; } return result; } exports.default = { type: [type_1.ASTType.INTERSECTION, type_1.ASTType.UNION], generate: groupTypeGenerator, };