alapa
Version:
A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.
45 lines (44 loc) • 2.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenApiPath = OpenApiPath;
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
require("reflect-metadata");
const entry_1 = require("../builder/entry");
function OpenApiPath(route, properties) {
return function (target, propertyKey) {
// Ensure temporalCollections exists
if (!entry_1.temporalCollections["routes"]) {
entry_1.temporalCollections["routes"] = {};
}
if (!entry_1.temporalCollections["routes"][route]) {
entry_1.temporalCollections["routes"][route] = {};
}
// Merge the provided properties into the temporal collection for the route
Object.keys(properties).forEach((key) => {
if (!entry_1.temporalCollections["routes"][route][key]) {
entry_1.temporalCollections["routes"][route][key] = {}; // Initialize if not already present
}
entry_1.temporalCollections["routes"][route][key] = {
...entry_1.temporalCollections["routes"][route][key], // Preserve previous properties
...properties[key],
};
// Log to inspect the target and ensure we're dealing with the prototype
const classConstructor = target.constructor;
// Ensure tags exist and set them based on the class name
if (!entry_1.temporalCollections["routes"][route][key]["tags"]) {
entry_1.temporalCollections["routes"][route][key]["tags"] = [];
}
// Avoid overwriting existing tags; instead, add the tag if it's not already there
const existingTags = entry_1.temporalCollections["routes"][route][key]["tags"];
if (existingTags.length == 0) {
if (classConstructor.name !== "Function") {
existingTags.push(classConstructor.name); // Add class name as a tag
}
else {
existingTags.push(target.name); // Use target name if the class is a function
}
}
});
};
}
;