express-swagger-autogen
Version:
A library that auto generates swagger docs to your endpoints from express.
39 lines (38 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Documentation = Documentation;
var utils_1 = require("./utils");
/**
* Decorator to document a controller method.
*
* @param {HandlerDocumentation} documentation - The documentation object for the method.
* @returns {Function} - The decorator function.
*/
function Documentation(documentation) {
return function (target, propertyKey) {
// If the method is static arrow or normal method
var original = target[propertyKey];
if (typeof original === "function") {
Reflect.defineMetadata(utils_1.ExpressSwaggerAutogenUtils.METADATA_KEY, documentation, original);
return;
}
// If it's an instance arrow function (non-static)
var symbol = Symbol();
Object.defineProperty(target, propertyKey, {
set: function (fn) {
if (typeof fn === "function") {
Reflect.defineMetadata(utils_1.ExpressSwaggerAutogenUtils.METADATA_KEY, documentation, fn);
}
Object.defineProperty(this, symbol, {
value: fn,
writable: true,
configurable: true,
});
},
get: function () {
return this[symbol];
},
configurable: true,
});
};
}