c2-http 1.0.26 → 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/index.d.ts CHANGED
@@ -4,6 +4,6 @@ import { CrudController } from "./model/CrudController";
4
4
  import { HttpError } from "./model/HttpError";
5
5
  import { IControllerOptions } from "./model/IControllerOptions";
6
6
  import { ICrudControllerOptions } from "./model/ICrudControllerOptions";
7
- import { Server, IServerConfig } from "./model/Server";
7
+ import { IServerConfig, Server } from "./model/Server";
8
8
  export declare const convertErrorToHttpError: (error: any) => HttpError;
9
- export { Controller, CrudController, IControllerOptions, ICrudControllerOptions, Server, IServerConfig, HttpDispatchDownload, HttpDispatchHandling, getMessage, initializei18n };
9
+ export { Controller, CrudController, HttpDispatchDownload, HttpDispatchHandling, IControllerOptions, ICrudControllerOptions, IServerConfig, Server, getMessage, initializei18n };
package/dist/index.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initializei18n = exports.getMessage = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.Server = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
6
+ exports.initializei18n = exports.getMessage = exports.Server = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
7
8
  const express_http_context_1 = __importDefault(require("express-http-context"));
8
9
  const http_status_1 = require("http-status");
9
10
  const mongodb_1 = require("mongodb");
@@ -20,7 +21,6 @@ Object.defineProperty(exports, "CrudController", { enumerable: true, get: functi
20
21
  const HttpError_1 = require("./model/HttpError");
21
22
  const Server_1 = require("./model/Server");
22
23
  Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });
23
- const axios_1 = __importDefault(require("axios"));
24
24
  const convertErrorToHttpError = (error) => {
25
25
  if (error instanceof mongodb_1.MongoServerError) {
26
26
  if (error.code === 11000) {
@@ -2,8 +2,10 @@ import { Router } from "express";
2
2
  import { IControllerOptions } from "./IControllerOptions";
3
3
  export declare abstract class Controller {
4
4
  routers: Router;
5
+ documentation: any;
5
6
  protected options: IControllerOptions;
6
7
  constructor(_options: Partial<IControllerOptions>);
7
8
  }
8
9
  export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
9
10
  export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
11
+ export declare function OpenApi(target: any): typeof target;
@@ -1,11 +1,13 @@
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
+ /* eslint-disable @typescript-eslint/ban-types */
4
5
  const c2_util_1 = require("c2-util");
5
6
  const express_1 = require("express");
6
7
  const http_status_1 = require("http-status");
7
8
  class Controller {
8
9
  routers = (0, express_1.Router)();
10
+ documentation;
9
11
  options;
10
12
  constructor(_options) {
11
13
  this.options = _options;
@@ -69,3 +71,37 @@ function HttpDispatchDownload(target, methodName, descriptor) {
69
71
  return descriptor;
70
72
  }
71
73
  exports.HttpDispatchDownload = HttpDispatchDownload;
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.26",
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>",