UNPKG

@nestia/sdk

Version:

Nestia SDK and Swagger generator

87 lines 4.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwaggerOperationComposer = void 0; const SecurityAnalyzer_1 = require("../../analyses/SecurityAnalyzer"); const SwaggerDescriptionComposer_1 = require("./SwaggerDescriptionComposer"); const SwaggerOperationParameterComposer_1 = require("./SwaggerOperationParameterComposer"); const SwaggerOperationResponseComposer_1 = require("./SwaggerOperationResponseComposer"); var SwaggerOperationComposer; (function (SwaggerOperationComposer) { SwaggerOperationComposer.compose = (props) => { var _a, _b, _c, _d, _e, _f; var _g, _h; // FIND REQUEST BODY const body = props.route.parameters.find((param) => param.category === "body"); // COMPOSE TAGS const tags = new Set([ ...props.route.controller.tags, ...props.route.tags, ...SwaggerDescriptionComposer_1.SwaggerDescriptionComposer.getJsDocTexts({ jsDocTags: props.route.jsDocTags, name: "tag", }).map((t) => t.split(" ")[0]), ]); if (tags.size) { (_a = (_g = props.document).tags) !== null && _a !== void 0 ? _a : (_g.tags = []); for (const t of tags) if (props.document.tags.find((elem) => elem.name === t) === undefined) props.document.tags.push({ name: t }); for (const texts of SwaggerDescriptionComposer_1.SwaggerDescriptionComposer.getJsDocTexts({ jsDocTags: props.route.jsDocTags, name: "tag", })) { const [name, ...description] = texts.split(" "); if (description.length) (_b = (_h = props.document.tags.find((elem) => elem.name === name)).description) !== null && _b !== void 0 ? _b : (_h.description = description.join(" ")); } } // SECURITY const security = SecurityAnalyzer_1.SecurityAnalyzer.merge(...props.route.controller.security, ...props.route.security, ...props.route.jsDocTags .filter((tag) => tag.name === "security") .map((tag) => tag.text === undefined ? [{}] : tag.text.map((text) => { const line = text.text .split(" ") .filter((s) => s.trim()) .filter((s) => !!s.length); if (line.length === 0) return {}; return { [line[0]]: line.slice(1), }; })) .flat()); // FINALIZE return Object.assign(Object.assign(Object.assign(Object.assign({}, SwaggerDescriptionComposer_1.SwaggerDescriptionComposer.compose({ description: props.route.description, jsDocTags: props.route.jsDocTags, kind: "summary", })), { deprecated: props.route.jsDocTags.some((tag) => tag.name === "deprecated") ? true : undefined, tags: Array.from(tags), operationId: (_c = props.route.operationId) !== null && _c !== void 0 ? _c : (_e = (_d = props.config).operationId) === null || _e === void 0 ? void 0 : _e.call(_d, { class: props.route.controller.class.name, function: props.route.name, method: props.route.method, path: props.route.path, }), parameters: props.route.parameters .map((p) => SwaggerOperationParameterComposer_1.SwaggerOperationParameterComposer.compose({ config: props.config, document: props.document, schema: props.schema(p.metadata), parameter: p, jsDocTags: props.route.jsDocTags, })) .flat(), requestBody: body ? SwaggerOperationParameterComposer_1.SwaggerOperationParameterComposer.body({ schema: props.schema(body.metadata), jsDocTags: props.route.jsDocTags, parameter: body, }) : undefined, responses: SwaggerOperationResponseComposer_1.SwaggerOperationResponseComposer.compose({ schema: props.schema, route: props.route, }), security: security.length ? security : undefined }), ((_f = props.route.extensions) !== null && _f !== void 0 ? _f : {})), { "x-samchon-accessor": props.route.accessor, "x-samchon-controller": props.route.controller.class.name }); }; })(SwaggerOperationComposer || (exports.SwaggerOperationComposer = SwaggerOperationComposer = {})); //# sourceMappingURL=SwaggerOperationComposer.js.map