c2-http 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/Controller.d.ts +1 -2
- package/dist/model/Controller.js +35 -78
- package/package.json +1 -1
|
@@ -5,8 +5,7 @@ export declare abstract class Controller {
|
|
|
5
5
|
documentation: any;
|
|
6
6
|
protected options: IControllerOptions;
|
|
7
7
|
constructor(_options: Partial<IControllerOptions>);
|
|
8
|
-
BuildDocumentation(): any;
|
|
9
|
-
private getMethodsUsed;
|
|
10
8
|
}
|
|
11
9
|
export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
12
10
|
export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
11
|
+
export declare function OpenApi(target: any): typeof target;
|
package/dist/model/Controller.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
|
|
3
|
+
exports.OpenApi = exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
5
5
|
const c2_util_1 = require("c2-util");
|
|
6
6
|
const express_1 = require("express");
|
|
@@ -29,34 +29,6 @@ class Controller {
|
|
|
29
29
|
}
|
|
30
30
|
this.options.uri = `${this.options.basePath}${this.options.relativePath}`;
|
|
31
31
|
}
|
|
32
|
-
// Método para extrair as definições de rota para o OpenApi
|
|
33
|
-
BuildDocumentation() {
|
|
34
|
-
const paths = {};
|
|
35
|
-
this.routers.stack.forEach((route) => {
|
|
36
|
-
if (route.route && route.route.path) {
|
|
37
|
-
const methodsUsed = this.getMethodsUsed(route.route.methods);
|
|
38
|
-
const methods = {};
|
|
39
|
-
methodsUsed.forEach((method) => {
|
|
40
|
-
methods[method] = {};
|
|
41
|
-
});
|
|
42
|
-
paths[route.route.path] = {
|
|
43
|
-
...paths[route.route.path],
|
|
44
|
-
...methods
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return paths;
|
|
49
|
-
}
|
|
50
|
-
;
|
|
51
|
-
getMethodsUsed(obj) {
|
|
52
|
-
const trueProperties = [];
|
|
53
|
-
for (const key in obj) {
|
|
54
|
-
if (obj[key] === true) {
|
|
55
|
-
trueProperties.push(key);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return trueProperties;
|
|
59
|
-
}
|
|
60
32
|
}
|
|
61
33
|
exports.Controller = Controller;
|
|
62
34
|
function HttpDispatchHandling(target, methodName, descriptor) {
|
|
@@ -99,52 +71,37 @@ function HttpDispatchDownload(target, methodName, descriptor) {
|
|
|
99
71
|
return descriptor;
|
|
100
72
|
}
|
|
101
73
|
exports.HttpDispatchDownload = HttpDispatchDownload;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// const methodsUsed = getMethodsUsed(route.route.methods)
|
|
137
|
-
// const methods: { [key: string]: any } = {}
|
|
138
|
-
// methodsUsed.forEach((method: string) => {
|
|
139
|
-
// methods[method] = {}
|
|
140
|
-
// });
|
|
141
|
-
// paths[route.route.path] = {
|
|
142
|
-
// ...paths[route.route.path],
|
|
143
|
-
// ...methods
|
|
144
|
-
// }
|
|
145
|
-
// }
|
|
146
|
-
// });
|
|
147
|
-
// return paths;
|
|
148
|
-
// };
|
|
149
|
-
// return descriptor;
|
|
150
|
-
// };
|
|
74
|
+
function OpenApi(target) {
|
|
75
|
+
return class extends target {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(); // Chama o construtor da classe original
|
|
78
|
+
// const controller = target as unknown as Controller;
|
|
79
|
+
const paths = {};
|
|
80
|
+
// console.log(target)
|
|
81
|
+
this.routers.stack.forEach((route) => {
|
|
82
|
+
if (route.route && route.route.path) {
|
|
83
|
+
const methodsUsed = this.getMethodsUsed2(route.route.methods);
|
|
84
|
+
const methods = {};
|
|
85
|
+
methodsUsed.forEach((method) => {
|
|
86
|
+
methods[method] = {};
|
|
87
|
+
});
|
|
88
|
+
paths[route.route.path] = {
|
|
89
|
+
...paths[route.route.path],
|
|
90
|
+
...methods
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.documentation = paths;
|
|
95
|
+
}
|
|
96
|
+
getMethodsUsed2(obj) {
|
|
97
|
+
const trueProperties = [];
|
|
98
|
+
for (const key in obj) {
|
|
99
|
+
if (obj[key] === true) {
|
|
100
|
+
trueProperties.push(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return trueProperties;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
exports.OpenApi = OpenApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "Biblioteca Typescript para API NodeJS",
|
|
5
5
|
"repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
|
|
6
6
|
"author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",
|