@ply-ct/ply
Version:
REST API Automated Testing
56 lines • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestJsPlugin = void 0;
class NestJsPlugin {
constructor(ts) {
this.ts = ts;
}
getEndpointMethods() {
const endpointMethods = [];
for (const classDec of this.ts.scanClassDecorators(['Controller'])) {
for (const methodDec of this.ts.findMethodDecorators(classDec, [
'Get',
'Post',
'Put',
'Patch',
'Delete'
])) {
let path = '' + classDec.arg;
if (!path.startsWith('/'))
path = `/${path}`;
let lastSegmentOptional = false;
if (methodDec.arg) {
let subpath = methodDec.arg;
if (subpath.endsWith('?')) {
subpath = subpath.substring(0, subpath.length - 1);
endpointMethods.push({
file: methodDec.file,
class: methodDec.class,
method: methodDec.decorator.toLowerCase(),
name: methodDec.method,
path
});
lastSegmentOptional = true;
}
if (!subpath.startsWith('/'))
subpath = `/${subpath}`;
if (subpath.startsWith('/:')) {
subpath = `/{${subpath.substring(2)}}`;
}
path += subpath;
}
endpointMethods.push({
file: methodDec.file,
class: methodDec.class,
method: methodDec.decorator.toLowerCase(),
name: methodDec.method,
path,
...(lastSegmentOptional && { lastSegmentOptional })
});
}
}
return endpointMethods;
}
}
exports.NestJsPlugin = NestJsPlugin;
//# sourceMappingURL=nestjs.js.map