apeframework 0.0.0-dev.7 → 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 CHANGED
@@ -9,5 +9,5 @@ GitHub repository: [ApeFramework/apeframework](https://github.com/ApeFramework/a
9
9
  ## Installation
10
10
 
11
11
  ```
12
- npm install apeframework
12
+ yarn add apeframework
13
13
  ```
package/api/Api.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Endpoint } from './Endpoint';
2
2
  import type { ErrorHandler } from './ErrorHandler';
3
3
  import type { Handler } from './Handler';
4
+ import type { OpenAPIV3 } from 'openapi-types';
4
5
  declare class Api {
5
6
  private readonly host;
6
7
  private readonly port;
@@ -9,12 +10,8 @@ declare class Api {
9
10
  host: string;
10
11
  port?: number;
11
12
  endpoints: Endpoint[];
12
- onRequest?: Handler;
13
- onResponse?: Handler;
14
- onNotFound?: Handler;
15
- onError?: ErrorHandler;
16
13
  openapi?: {
17
- title?: string;
14
+ name?: string;
18
15
  version?: string;
19
16
  };
20
17
  cors?: {
@@ -22,7 +19,12 @@ declare class Api {
22
19
  origin?: string[];
23
20
  };
24
21
  responseValidation?: boolean;
22
+ onRequest?: Handler;
23
+ onResponse?: Handler;
24
+ onNotFound?: Handler;
25
+ onError?: ErrorHandler;
25
26
  });
26
27
  start(): Promise<string>;
28
+ openapi(): OpenAPIV3.Document;
27
29
  }
28
30
  export { Api, };
package/api/Api.js CHANGED
@@ -32,7 +32,7 @@ class Api {
32
32
  openapi: {
33
33
  openapi: '3.1.0',
34
34
  info: {
35
- title: params.openapi?.title ?? '',
35
+ title: params.openapi?.name ?? '',
36
36
  version: params.openapi?.version ?? '',
37
37
  },
38
38
  },
@@ -45,21 +45,24 @@ class Api {
45
45
  if (params.responseValidation) {
46
46
  this.server.register(response_validation_1.default);
47
47
  }
48
- params.endpoints.forEach((e) => {
49
- this.server.route({
50
- url: e.path,
51
- method: e.method,
52
- schema: {
53
- summary: e.name ?? e.path,
54
- description: e.description,
55
- ...e.schema.params ? { params: e.schema.params } : {},
56
- ...e.schema.query ? { query: e.schema.query } : {},
57
- ...e.schema.headers ? { headers: e.schema.headers } : {},
58
- ...e.schema.body ? { body: e.schema.body } : {},
59
- ...e.schema.response ? { response: e.schema.response } : {},
60
- },
61
- handler: e.handler,
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
+ });
62
64
  });
65
+ done();
63
66
  });
64
67
  }
65
68
  async start() {
@@ -68,5 +71,8 @@ class Api {
68
71
  port: this.port,
69
72
  });
70
73
  }
74
+ openapi() {
75
+ return this.server.swagger();
76
+ }
71
77
  }
72
78
  exports.Api = Api;
package/api/Api.ts CHANGED
@@ -6,6 +6,7 @@ import type { Endpoint } from './Endpoint'
6
6
  import type { ErrorHandler } from './ErrorHandler'
7
7
  import type { Handler } from './Handler'
8
8
  import type { FastifyInstance } from 'fastify'
9
+ import type { OpenAPIV3 } from 'openapi-types'
9
10
 
10
11
  class Api {
11
12
  private readonly host: string
@@ -18,12 +19,8 @@ class Api {
18
19
  host: string,
19
20
  port?: number,
20
21
  endpoints: Endpoint[],
21
- onRequest?: Handler,
22
- onResponse?: Handler,
23
- onNotFound?: Handler,
24
- onError?: ErrorHandler,
25
22
  openapi?: {
26
- title?: string,
23
+ name?: string,
27
24
  version?: string,
28
25
  },
29
26
  cors?: {
@@ -31,6 +28,10 @@ class Api {
31
28
  origin?: string[],
32
29
  },
33
30
  responseValidation?: boolean,
31
+ onRequest?: Handler,
32
+ onResponse?: Handler,
33
+ onNotFound?: Handler,
34
+ onError?: ErrorHandler,
34
35
  }) {
35
36
  this.host = params.host
36
37
  this.port = params.port
@@ -57,7 +58,7 @@ class Api {
57
58
  openapi: {
58
59
  openapi: '3.1.0',
59
60
  info: {
60
- title: params.openapi?.title ?? '',
61
+ title: params.openapi?.name ?? '',
61
62
  version: params.openapi?.version ?? '',
62
63
  },
63
64
  },
@@ -73,21 +74,24 @@ class Api {
73
74
  this.server.register(responseValidation)
74
75
  }
75
76
 
76
- params.endpoints.forEach((e) => {
77
- this.server.route({
78
- url: e.path,
79
- method: e.method,
80
- schema: {
81
- summary: e.name ?? e.path,
82
- description: e.description,
83
- ...e.schema.params ? { params: e.schema.params } : {},
84
- ...e.schema.query ? { query: e.schema.query } : {},
85
- ...e.schema.headers ? { headers: e.schema.headers } : {},
86
- ...e.schema.body ? { body: e.schema.body } : {},
87
- ...e.schema.response ? { response: e.schema.response } : {},
88
- },
89
- handler: e.handler,
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
 
@@ -97,6 +101,10 @@ class Api {
97
101
  port: this.port,
98
102
  })
99
103
  }
104
+
105
+ public openapi(): OpenAPIV3.Document {
106
+ return this.server.swagger() as OpenAPIV3.Document
107
+ }
100
108
  }
101
109
 
102
110
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apeframework",
3
- "version": "0.0.0-dev.7",
3
+ "version": "0.0.0-dev.9",
4
4
  "license": "MIT",
5
5
  "author": "Matthieu Symoens",
6
6
  "description": "Node.js app framework",