c2-http 1.0.28 → 1.0.30
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 +2 -2
- package/dist/index.js +2 -1
- package/dist/model/Controller.d.ts +1 -0
- package/dist/model/Controller.js +53 -0
- package/dist/model/Server.js +2 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getMessage, initializei18n } from "./i18n";
|
|
2
|
-
import { Controller, HttpDispatchDownload, HttpDispatchHandling } from "./model/Controller";
|
|
2
|
+
import { Controller, HttpDispatchDownload, HttpDispatchHandling, OpenApi } from "./model/Controller";
|
|
3
3
|
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
7
|
import { IServerConfig, Server } from "./model/Server";
|
|
8
8
|
export declare const convertErrorToHttpError: (error: any) => HttpError;
|
|
9
|
-
export { Controller, CrudController, HttpDispatchDownload, HttpDispatchHandling, IControllerOptions, ICrudControllerOptions, IServerConfig, Server, getMessage, initializei18n };
|
|
9
|
+
export { Controller, CrudController, HttpDispatchDownload, HttpDispatchHandling, IControllerOptions, ICrudControllerOptions, IServerConfig, OpenApi, Server, getMessage, initializei18n };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.Server = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
|
|
6
|
+
exports.initializei18n = exports.getMessage = exports.Server = exports.OpenApi = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const express_http_context_1 = __importDefault(require("express-http-context"));
|
|
9
9
|
const http_status_1 = require("http-status");
|
|
@@ -16,6 +16,7 @@ const Controller_1 = require("./model/Controller");
|
|
|
16
16
|
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return Controller_1.Controller; } });
|
|
17
17
|
Object.defineProperty(exports, "HttpDispatchDownload", { enumerable: true, get: function () { return Controller_1.HttpDispatchDownload; } });
|
|
18
18
|
Object.defineProperty(exports, "HttpDispatchHandling", { enumerable: true, get: function () { return Controller_1.HttpDispatchHandling; } });
|
|
19
|
+
Object.defineProperty(exports, "OpenApi", { enumerable: true, get: function () { return Controller_1.OpenApi; } });
|
|
19
20
|
const CrudController_1 = require("./model/CrudController");
|
|
20
21
|
Object.defineProperty(exports, "CrudController", { enumerable: true, get: function () { return CrudController_1.CrudController; } });
|
|
21
22
|
const HttpError_1 = require("./model/HttpError");
|
|
@@ -4,6 +4,7 @@ export declare abstract class Controller {
|
|
|
4
4
|
routers: Router;
|
|
5
5
|
documentation: any;
|
|
6
6
|
protected options: IControllerOptions;
|
|
7
|
+
static openApi: any;
|
|
7
8
|
constructor(_options: Partial<IControllerOptions>);
|
|
8
9
|
}
|
|
9
10
|
export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
package/dist/model/Controller.js
CHANGED
|
@@ -9,6 +9,8 @@ class Controller {
|
|
|
9
9
|
routers = (0, express_1.Router)();
|
|
10
10
|
documentation;
|
|
11
11
|
options;
|
|
12
|
+
// Propriedade estática compartilhada por todas as instâncias
|
|
13
|
+
static openApi = {};
|
|
12
14
|
constructor(_options) {
|
|
13
15
|
this.options = _options;
|
|
14
16
|
if (!this?.options?.relativePath?.startsWith("/")) {
|
|
@@ -28,6 +30,57 @@ class Controller {
|
|
|
28
30
|
this.options.prefixRole = defaultPrefixRole.replaceAll("/", "-");
|
|
29
31
|
}
|
|
30
32
|
this.options.uri = `${this.options.basePath}${this.options.relativePath}`;
|
|
33
|
+
Controller.openApi = {
|
|
34
|
+
"openapi": "3.1.0",
|
|
35
|
+
"info": {
|
|
36
|
+
"version": "1.0.0",
|
|
37
|
+
"title": "REST API",
|
|
38
|
+
"description": ""
|
|
39
|
+
},
|
|
40
|
+
"servers": [
|
|
41
|
+
{
|
|
42
|
+
"url": "http://localhost:3000/"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"components": {
|
|
46
|
+
"schemas": {
|
|
47
|
+
"info": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": {
|
|
50
|
+
"title": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"example": "Sua API"
|
|
53
|
+
},
|
|
54
|
+
"version": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"example": "1.0.0"
|
|
57
|
+
},
|
|
58
|
+
"description": {
|
|
59
|
+
"type": "string",
|
|
60
|
+
"example": "Descrição da sua API"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"servers": {
|
|
65
|
+
"type": "array",
|
|
66
|
+
"items": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"properties": {
|
|
69
|
+
"url": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"example": "http://localhost:3000"
|
|
72
|
+
},
|
|
73
|
+
"description": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"example": "Servidor local"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
paths: {}
|
|
83
|
+
};
|
|
31
84
|
}
|
|
32
85
|
}
|
|
33
86
|
exports.Controller = Controller;
|
package/dist/model/Server.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.Server = void 0;
|
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
const i18n_1 = require("../i18n");
|
|
9
9
|
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
10
|
+
const Controller_1 = require("./Controller");
|
|
10
11
|
class Server {
|
|
11
12
|
app;
|
|
12
13
|
config;
|
|
@@ -17,9 +18,6 @@ class Server {
|
|
|
17
18
|
async initialize(callback) {
|
|
18
19
|
(0, i18n_1.initializei18n)(this.config.i18n);
|
|
19
20
|
console.log(`Initializing server on ${this.config.port}...`);
|
|
20
|
-
if (this.config.openApiFileOutput) {
|
|
21
|
-
this.app.use("/docs", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(this.config.openApiFileOutput));
|
|
22
|
-
}
|
|
23
21
|
this.config.globalMiddleware(this.app);
|
|
24
22
|
for (const router of this.config.routes) {
|
|
25
23
|
this.app.use(router);
|
|
@@ -28,6 +26,7 @@ class Server {
|
|
|
28
26
|
for (const router of this.config.routesWithToken) {
|
|
29
27
|
this.app.use(router);
|
|
30
28
|
}
|
|
29
|
+
this.app.use("/docs", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(Controller_1.Controller.openApi));
|
|
31
30
|
this.app.listen(this.config.port, async () => {
|
|
32
31
|
console.info(`Server running on port ${this.config.port}`);
|
|
33
32
|
if (callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
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>",
|