@nestia/sdk
Version:
Nestia SDK and Swagger generator
80 lines • 4.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SdkHttpRouteProgrammer = void 0;
const FilePrinter_1 = require("./FilePrinter");
const SdkHttpFunctionProgrammer_1 = require("./SdkHttpFunctionProgrammer");
const SdkHttpNamespaceProgrammer_1 = require("./SdkHttpNamespaceProgrammer");
const SdkHttpParameterProgrammer_1 = require("./SdkHttpParameterProgrammer");
var SdkHttpRouteProgrammer;
(function (SdkHttpRouteProgrammer) {
SdkHttpRouteProgrammer.write = (project) => (importer) => (route) => [
FilePrinter_1.FilePrinter.description(SdkHttpFunctionProgrammer_1.SdkHttpFunctionProgrammer.write(project)(importer)(route), describe(project.config, route)),
SdkHttpNamespaceProgrammer_1.SdkHttpNamespaceProgrammer.write(project)(importer)(route),
];
const describe = (config, route) => {
var _a, _b, _c, _d, _e, _f, _g;
// MAIN DESCRIPTION
const descriptionComments = route.description
? route.description.split("\n")
: [];
const tagComments = [];
// PARAMETERS
for (const p of SdkHttpParameterProgrammer_1.SdkHttpParameterProgrammer.getSignificant(route, true)) {
const description = (_d = (_a = p.description) !== null && _a !== void 0 ? _a : (_c = (_b = p.jsDocTags.find((tag) => tag.name === "description")) === null || _b === void 0 ? void 0 : _b.text) === null || _c === void 0 ? void 0 : _c[0].text) !== null && _d !== void 0 ? _d : (_f = (_e = route.jsDocTags
.find((tag) => { var _a; return tag.name === "param" && ((_a = tag.text) === null || _a === void 0 ? void 0 : _a[0].text) === p.name; })) === null || _e === void 0 ? void 0 : _e.text) === null || _f === void 0 ? void 0 : _f.map((e) => e.text).join("").substring(p.name.length);
if (!(description === null || description === void 0 ? void 0 : description.length))
continue;
const name = config.keyword === true ? `props.${p.name}` : p.name;
tagComments.push(`@param ${name} ${description
.split("\n")
.map((str) => str.trim())
.map((str, i) => {
if (i === 0)
return str;
const rpad = p.name.length + 8;
return `${" ".repeat(rpad)}${str}`;
})
.join("\n")}`);
}
// COMMENT TAGS
const tags = route.jsDocTags.filter((tag) => tag.name !== "param");
if (tags.length !== 0) {
const content = tags.map((t) => {
var _a;
return ((_a = t.text) === null || _a === void 0 ? void 0 : _a.length)
? `@${t.name} ${t.text
.map((e) => e.text)
.join("")
.split("\n")
.map((str) => str.trim())
.map((str, i) => {
if (i === 0)
return str;
return `${" ".repeat(t.name.length + 1)} ${str}`;
})
.join("\n")}`
: `@${t.name}`;
});
tagComments.push(...new Set(content));
}
// EXCEPTIONS
for (const [key, value] of Object.entries(route.exceptions)) {
if (tagComments.some((str) => str.startsWith(`@throw ${key}`) || str.startsWith(`@throws ${key}`)))
continue;
tagComments.push(((_g = value.description) === null || _g === void 0 ? void 0 : _g.length)
? `@throws ${key} ${value.description.split("\n")[0]}`
: `@throws ${key}`);
}
// POSTFIX
return [
...descriptionComments,
...(descriptionComments.length && tagComments.length ? [""] : []),
...tagComments,
...(descriptionComments.length && tagComments.length ? [""] : []),
`@controller ${route.controller.class.name}.${route.name}`,
`@path ${route.method} ${route.path}`,
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
].join("\n");
};
})(SdkHttpRouteProgrammer || (exports.SdkHttpRouteProgrammer = SdkHttpRouteProgrammer = {}));
//# sourceMappingURL=SdkHttpRouteProgrammer.js.map