UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

57 lines (56 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommentBySchema = getCommentBySchema; exports.initAST = initAST; exports.parse = parse; exports.getParserSchemaType = getParserSchemaType; const helper_1 = require("../../../../helper"); const type_1 = require("../../../../type"); const utils_1 = require("../../../../utils"); const forward_1 = require("./forward"); function getCommentBySchema(schema, options) { const commenter = helper_1.CommentHelper.load(options); if (!(0, utils_1.isReferenceObject)(schema) && schema.title) { commenter.add('[title]', schema.title); } if ((0, utils_1.isReferenceObject)(schema) && schema.summary) { commenter.add('[summary]', schema.summary); } if (schema.description) { commenter.add(schema.description); } return commenter.end(); } function initAST(schema, ctx) { const result = { type: type_1.ASTType.UNKNOWN, comment: getCommentBySchema(schema, { type: ctx.options.commentType, }), keyName: ctx.keyName, deprecated: (0, utils_1.isReferenceObject)(schema) ? false : schema.deprecated, }; ctx.keyName = ''; return result; } function parse(schema, options) { const { type, ctx, parsers } = options; const parser = parsers.find(parser => [parser.type].flat().includes(type)); if (parser) { return parser.parse(schema, ctx); } return null; } function getParserSchemaType(schema) { if ((0, utils_1.isReferenceObject)(schema)) { return 'reference'; } const forwardType = (0, forward_1.forward)(schema); if (forwardType) { return forwardType; } if (schema.type && typeof schema.type === 'string') { return schema.type; } return 'null'; }