UNPKG

reest

Version:

A library inspired by NestJS's elegance, specifically designed for efficient serverless API development on AWS Lambda. It streamlines the creation of microservices with automated Swagger documentation and enhanced decorator-based middleware support, makin

40 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateRequestMethodDecorathor = void 0; const generateRequestMethodDecorathor = (type, path, options) => { return (target, key, descriptor) => { if (!Reflect.hasMetadata("routes", target.constructor)) { Reflect.defineMetadata("routes", [], target.constructor); } const routes = Reflect.getMetadata("routes", target.constructor); const route = routes.find((route) => route.methodName === key) || { methodName: key, middlewares: [], }; route.requestMethod = type; route.path = path; route.openApi = { operationId: target.constructor.name + "__" + key.toString() + "__" + type, description: options?.description, tags: [target.constructor.name], requestBody: ["post", "put", "patch"].includes(type) && { description: options?.bodyDescription || "Request body", required: options?.bodyRequired || false, content: { "application/json": { schema: { type: "object" }, }, }, }, produces: ["application/json", "application/xml"], responses: { 200: { description: "OK", }, }, }; Reflect.defineMetadata("routes", [...routes, route], target.constructor); }; }; exports.generateRequestMethodDecorathor = generateRequestMethodDecorathor; //# sourceMappingURL=generateMethodDecorator.js.map