tspace-spear
Version:
tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.
52 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Swagger = void 0;
/**
* Attaches Swagger/OpenAPI specification metadata to a controller method.
*
* This decorator stores route documentation using `Reflect.defineMetadata`
* so the framework can later collect it and generate **Swagger / OpenAPI**
* documentation automatically.
*
* The metadata is stored on the controller constructor under the key `"swaggers"`.
* Each decorated method contributes a Swagger specification object.
*
* @example
* ```ts
* class UserController {
*
* \@Swagger({
* summary: "Get user profile",
* description: "Returns the authenticated user's profile",
* tags: ["Users"],
* responses: {
* 200: {
* description: "Successful response"
* }
* }
* })
* async profile(ctx: T.Context) {
* return { id: 1, name: "John" };
* }
*
* }
* ```
*
* @param {T.Swagger.Spec} data - Swagger/OpenAPI specification for the route.
* @returns {MethodDecorator}
*/
const Swagger = (data = {}) => {
return (target, propertyKey) => {
const controller = target.constructor;
const swaggers = Reflect.hasMetadata("swaggers", controller)
? Reflect.getMetadata("swaggers", controller)
: [];
swaggers.push({
handler: propertyKey,
...data,
});
Reflect.defineMetadata("swaggers", swaggers, controller);
};
};
exports.Swagger = Swagger;
//# sourceMappingURL=swagger.js.map