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.
@@ -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;
@@ -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
- // export function CustomDecorator<Controller extends { new (...args: any[]): {} }>(target: Controller) {
103
- // return class extends target {
104
- // constructor(...args: any[]) {
105
- // super(...args); // Chama o construtor da classe original
106
- // // this.initProperty(); // Executa o método que inicializa a propriedade
107
- // this.anotherProperty = "valor da outra propriedade"; // Define outra propriedade
108
- // }
109
- // // initProperty() {
110
- // // if (typeof this.exampleProperty === 'undefined') {
111
- // // this.exampleProperty = "valor inicial da propriedade"; // Inicializa a propriedade
112
- // // }
113
- // // }
114
- // };
115
- // }
116
- // // Método para extrair as definições de rota para o OpenApi
117
- // export function OpenApi(
118
- // target: any,
119
- // methodName: string,
120
- // descriptor: PropertyDescriptor): any {
121
- // const originalMethod = descriptor.value;
122
- // const getMethodsUsed = (obj: { [key: string]: boolean }): string[] => {
123
- // const trueProperties: string[] = [];
124
- // for (const key in obj) {
125
- // if (obj[key] === true) {
126
- // trueProperties.push(key);
127
- // }
128
- // }
129
- // return trueProperties;
130
- // }
131
- // descriptor.value = async function (...args: any) {
132
- // const controller = args as Controller;
133
- // const paths: { [key: string]: any } = {}
134
- // controller.routers.stack.forEach((route: any) => {
135
- // if (route.route && route.route.path) {
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.27",
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>",