apeframework 0.0.0-dev.8 → 0.0.0-dev.9
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/README.md +1 -1
- package/api/Api.d.ts +4 -4
- package/api/Api.js +18 -14
- package/api/Api.ts +22 -18
- package/package.json +1 -1
package/README.md
CHANGED
package/api/Api.d.ts
CHANGED
|
@@ -10,10 +10,6 @@ declare class Api {
|
|
|
10
10
|
host: string;
|
|
11
11
|
port?: number;
|
|
12
12
|
endpoints: Endpoint[];
|
|
13
|
-
onRequest?: Handler;
|
|
14
|
-
onResponse?: Handler;
|
|
15
|
-
onNotFound?: Handler;
|
|
16
|
-
onError?: ErrorHandler;
|
|
17
13
|
openapi?: {
|
|
18
14
|
name?: string;
|
|
19
15
|
version?: string;
|
|
@@ -23,6 +19,10 @@ declare class Api {
|
|
|
23
19
|
origin?: string[];
|
|
24
20
|
};
|
|
25
21
|
responseValidation?: boolean;
|
|
22
|
+
onRequest?: Handler;
|
|
23
|
+
onResponse?: Handler;
|
|
24
|
+
onNotFound?: Handler;
|
|
25
|
+
onError?: ErrorHandler;
|
|
26
26
|
});
|
|
27
27
|
start(): Promise<string>;
|
|
28
28
|
openapi(): OpenAPIV3.Document;
|
package/api/Api.js
CHANGED
|
@@ -30,6 +30,7 @@ class Api {
|
|
|
30
30
|
}
|
|
31
31
|
this.server.register(swagger_1.default, {
|
|
32
32
|
openapi: {
|
|
33
|
+
openapi: '3.1.0',
|
|
33
34
|
info: {
|
|
34
35
|
title: params.openapi?.name ?? '',
|
|
35
36
|
version: params.openapi?.version ?? '',
|
|
@@ -44,21 +45,24 @@ class Api {
|
|
|
44
45
|
if (params.responseValidation) {
|
|
45
46
|
this.server.register(response_validation_1.default);
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
this.server.register((server, options, done) => {
|
|
49
|
+
params.endpoints.forEach((e) => {
|
|
50
|
+
server.route({
|
|
51
|
+
url: e.path,
|
|
52
|
+
method: e.method,
|
|
53
|
+
schema: {
|
|
54
|
+
summary: e.name ?? e.path,
|
|
55
|
+
description: e.description,
|
|
56
|
+
...e.schema.params ? { params: e.schema.params } : {},
|
|
57
|
+
...e.schema.query ? { query: e.schema.query } : {},
|
|
58
|
+
...e.schema.headers ? { headers: e.schema.headers } : {},
|
|
59
|
+
...e.schema.body ? { body: e.schema.body } : {},
|
|
60
|
+
...e.schema.response ? { response: e.schema.response } : {},
|
|
61
|
+
},
|
|
62
|
+
handler: e.handler,
|
|
63
|
+
});
|
|
61
64
|
});
|
|
65
|
+
done();
|
|
62
66
|
});
|
|
63
67
|
}
|
|
64
68
|
async start() {
|
package/api/Api.ts
CHANGED
|
@@ -19,10 +19,6 @@ class Api {
|
|
|
19
19
|
host: string,
|
|
20
20
|
port?: number,
|
|
21
21
|
endpoints: Endpoint[],
|
|
22
|
-
onRequest?: Handler,
|
|
23
|
-
onResponse?: Handler,
|
|
24
|
-
onNotFound?: Handler,
|
|
25
|
-
onError?: ErrorHandler,
|
|
26
22
|
openapi?: {
|
|
27
23
|
name?: string,
|
|
28
24
|
version?: string,
|
|
@@ -32,6 +28,10 @@ class Api {
|
|
|
32
28
|
origin?: string[],
|
|
33
29
|
},
|
|
34
30
|
responseValidation?: boolean,
|
|
31
|
+
onRequest?: Handler,
|
|
32
|
+
onResponse?: Handler,
|
|
33
|
+
onNotFound?: Handler,
|
|
34
|
+
onError?: ErrorHandler,
|
|
35
35
|
}) {
|
|
36
36
|
this.host = params.host
|
|
37
37
|
this.port = params.port
|
|
@@ -56,6 +56,7 @@ class Api {
|
|
|
56
56
|
|
|
57
57
|
this.server.register(swagger, {
|
|
58
58
|
openapi: {
|
|
59
|
+
openapi: '3.1.0',
|
|
59
60
|
info: {
|
|
60
61
|
title: params.openapi?.name ?? '',
|
|
61
62
|
version: params.openapi?.version ?? '',
|
|
@@ -73,21 +74,24 @@ class Api {
|
|
|
73
74
|
this.server.register(responseValidation)
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
this.server.register((server, options, done) => {
|
|
78
|
+
params.endpoints.forEach((e) => {
|
|
79
|
+
server.route({
|
|
80
|
+
url: e.path,
|
|
81
|
+
method: e.method,
|
|
82
|
+
schema: {
|
|
83
|
+
summary: e.name ?? e.path,
|
|
84
|
+
description: e.description,
|
|
85
|
+
...e.schema.params ? { params: e.schema.params } : {},
|
|
86
|
+
...e.schema.query ? { query: e.schema.query } : {},
|
|
87
|
+
...e.schema.headers ? { headers: e.schema.headers } : {},
|
|
88
|
+
...e.schema.body ? { body: e.schema.body } : {},
|
|
89
|
+
...e.schema.response ? { response: e.schema.response } : {},
|
|
90
|
+
},
|
|
91
|
+
handler: e.handler,
|
|
92
|
+
})
|
|
90
93
|
})
|
|
94
|
+
done()
|
|
91
95
|
})
|
|
92
96
|
}
|
|
93
97
|
|