kuzzle 2.14.16 → 2.16.0
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/lib/api/controllers/adminController.js +5 -0
- package/lib/api/controllers/documentController.js +1 -5
- package/lib/api/controllers/serverController.js +24 -4
- package/lib/api/funnel.js +19 -0
- package/lib/{config → api}/httpRoutes.js +30 -14
- package/lib/api/openApiGenerator.d.ts +6 -0
- package/lib/api/openApiGenerator.js +167 -126
- package/lib/api/openapi/documents/document.d.ts +21 -0
- package/lib/api/openapi/documents/document.js +57 -0
- package/lib/api/openapi/tools.d.ts +2 -0
- package/lib/api/openapi/tools.js +10 -0
- package/lib/api/request/kuzzleRequest.d.ts +30 -32
- package/lib/api/request/kuzzleRequest.js +30 -102
- package/lib/api/request/requestContext.d.ts +17 -22
- package/lib/api/request/requestContext.js +44 -109
- package/lib/api/request/requestInput.d.ts +19 -22
- package/lib/api/request/requestInput.js +115 -173
- package/lib/api/request/requestResponse.d.ts +12 -8
- package/lib/api/request/requestResponse.js +35 -29
- package/lib/cluster/idCardHandler.d.ts +140 -0
- package/lib/cluster/idCardHandler.js +218 -214
- package/lib/cluster/node.js +11 -0
- package/lib/cluster/protobuf/sync.proto +4 -0
- package/lib/cluster/subscriber.js +9 -12
- package/lib/cluster/workers/IDCardRenewer.js +13 -7
- package/lib/config/default.config.js +1 -1
- package/lib/core/network/router.js +33 -0
- package/lib/core/plugin/pluginsManager.js +3 -1
- package/lib/core/realtime/hotelClerk.d.ts +7 -0
- package/lib/core/realtime/hotelClerk.js +14 -0
- package/lib/core/realtime/notifier.js +16 -18
- package/lib/core/storage/clientAdapter.js +11 -5
- package/lib/core/storage/indexCache.d.ts +55 -0
- package/lib/core/storage/indexCache.js +97 -130
- package/lib/kuzzle/kuzzle.js +11 -7
- package/lib/service/storage/elasticsearch.js +14 -9
- package/package-lock.json +286 -260
- package/package.json +18 -17
|
@@ -37,6 +37,7 @@ class AdminController extends NativeController {
|
|
|
37
37
|
'loadFixtures',
|
|
38
38
|
'loadMappings',
|
|
39
39
|
'loadSecurities',
|
|
40
|
+
'refreshIndexCache',
|
|
40
41
|
'resetCache',
|
|
41
42
|
'resetDatabase',
|
|
42
43
|
'resetSecurity',
|
|
@@ -46,6 +47,10 @@ class AdminController extends NativeController {
|
|
|
46
47
|
this.shuttingDown = false;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
async refreshIndexCache () {
|
|
51
|
+
await global.kuzzle.ask('core:storage:public:cache:refresh');
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
/**
|
|
50
55
|
* Reset Redis cache
|
|
51
56
|
*/
|
|
@@ -25,7 +25,7 @@ const os = require('os');
|
|
|
25
25
|
const jsonToYaml = require('json2yaml');
|
|
26
26
|
|
|
27
27
|
const { NativeController } = require('./baseController');
|
|
28
|
-
const generateOpenApi = require('../openApiGenerator');
|
|
28
|
+
const { generateOpenApi } = require('../openApiGenerator');
|
|
29
29
|
|
|
30
30
|
const kerror = require('../../kerror');
|
|
31
31
|
|
|
@@ -42,10 +42,12 @@ class ServerController extends NativeController {
|
|
|
42
42
|
'getStats',
|
|
43
43
|
'healthCheck',
|
|
44
44
|
'info',
|
|
45
|
+
'metrics',
|
|
45
46
|
'now',
|
|
46
47
|
'publicApi',
|
|
47
|
-
'openapi'
|
|
48
|
+
'openapi',
|
|
48
49
|
]);
|
|
50
|
+
this._docOpenapi = generateOpenApi();
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -53,6 +55,8 @@ class ServerController extends NativeController {
|
|
|
53
55
|
*
|
|
54
56
|
* @param {Request} request
|
|
55
57
|
* @returns {Promise<Object>}
|
|
58
|
+
*
|
|
59
|
+
* @deprecated
|
|
56
60
|
*/
|
|
57
61
|
getStats (request) {
|
|
58
62
|
return global.kuzzle.statistics.getStats(request);
|
|
@@ -62,6 +66,8 @@ class ServerController extends NativeController {
|
|
|
62
66
|
* Returns the last statistics frame
|
|
63
67
|
*
|
|
64
68
|
* @returns {Promise<Object>}
|
|
69
|
+
*
|
|
70
|
+
* @deprecated
|
|
65
71
|
*/
|
|
66
72
|
getLastStats () {
|
|
67
73
|
return global.kuzzle.statistics.getLastStats();
|
|
@@ -71,6 +77,8 @@ class ServerController extends NativeController {
|
|
|
71
77
|
* Returns all stored statistics frames
|
|
72
78
|
*
|
|
73
79
|
* @returns {Promise<Object>}
|
|
80
|
+
*
|
|
81
|
+
* @deprecated
|
|
74
82
|
*/
|
|
75
83
|
getAllStats () {
|
|
76
84
|
return global.kuzzle.statistics.getAllStats();
|
|
@@ -241,8 +249,8 @@ class ServerController extends NativeController {
|
|
|
241
249
|
? 'application/yaml'
|
|
242
250
|
: 'application/json';
|
|
243
251
|
const specifications = format === 'yaml'
|
|
244
|
-
? jsonToYaml.stringify(
|
|
245
|
-
:
|
|
252
|
+
? jsonToYaml.stringify(this._docOpenapi)
|
|
253
|
+
: this._docOpenapi;
|
|
246
254
|
|
|
247
255
|
request.response.configure({
|
|
248
256
|
format: 'raw',
|
|
@@ -253,6 +261,18 @@ class ServerController extends NativeController {
|
|
|
253
261
|
return specifications;
|
|
254
262
|
}
|
|
255
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Fetches and returns Kuzzle core metrics
|
|
266
|
+
* @returns {Promise<Object>}
|
|
267
|
+
*/
|
|
268
|
+
async metrics () {
|
|
269
|
+
return {
|
|
270
|
+
api: await global.kuzzle.ask('kuzzle:api:funnel:metrics'),
|
|
271
|
+
network: await global.kuzzle.ask('core:network:router:metrics'),
|
|
272
|
+
realtime: await global.kuzzle.ask('core:realtime:hotelClerk:metrics'),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
256
276
|
_buildApiDefinition (controllers, httpRoutes) {
|
|
257
277
|
const apiDefinition = {};
|
|
258
278
|
|
package/lib/api/funnel.js
CHANGED
|
@@ -101,6 +101,14 @@ class Funnel {
|
|
|
101
101
|
'kuzzle:api:funnel:controller:isNative',
|
|
102
102
|
name => this.isNativeController(name));
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Returns inner metrics from the Funnel
|
|
106
|
+
* @returns {Object}
|
|
107
|
+
*/
|
|
108
|
+
global.kuzzle.onAsk(
|
|
109
|
+
'kuzzle:api:funnel:metrics',
|
|
110
|
+
() => this.metrics());
|
|
111
|
+
|
|
104
112
|
this.rateLimiter.init();
|
|
105
113
|
|
|
106
114
|
this.controllers.set('auth', new AuthController());
|
|
@@ -716,6 +724,17 @@ class Funnel {
|
|
|
716
724
|
return this.controllers.has(controller);
|
|
717
725
|
}
|
|
718
726
|
|
|
727
|
+
/**
|
|
728
|
+
* Returns inner metrics from the Funnel
|
|
729
|
+
* @returns {Object}
|
|
730
|
+
*/
|
|
731
|
+
metrics () {
|
|
732
|
+
return {
|
|
733
|
+
concurrentRequests: this.concurrentRequests,
|
|
734
|
+
pendingRequests: this.pendingRequestsQueue.length,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
|
|
719
738
|
/**
|
|
720
739
|
* If the request is coming from an official SDK,
|
|
721
740
|
* then checks the compatibility of the SDK against current Kuzzle version.
|
|
@@ -23,6 +23,20 @@
|
|
|
23
23
|
|
|
24
24
|
'use strict';
|
|
25
25
|
|
|
26
|
+
const {
|
|
27
|
+
OpenApiDocumentCount,
|
|
28
|
+
OpenApiDocumentDeleteByQuery,
|
|
29
|
+
OpenApiDocumentDelete,
|
|
30
|
+
OpenApiDocumentScroll,
|
|
31
|
+
OpenApiDocumentExists,
|
|
32
|
+
OpenApiDocumentUpdate,
|
|
33
|
+
OpenApiDocumentReplace,
|
|
34
|
+
OpenApiDocumentGet,
|
|
35
|
+
OpenApiDocumentCreate,
|
|
36
|
+
OpenApiDocumentCreateOrReplace,
|
|
37
|
+
} = require('../api/openapi/documents/document');
|
|
38
|
+
|
|
39
|
+
|
|
26
40
|
const routes = [
|
|
27
41
|
// GET (idempotent)
|
|
28
42
|
{ verb: 'get', path: '/_me', controller: 'auth', action: 'getCurrentUser' },
|
|
@@ -46,6 +60,7 @@ const routes = [
|
|
|
46
60
|
{ verb: 'get', path: '/validations/_scroll/:scrollId', controller: 'collection', action: 'scrollSpecifications' },
|
|
47
61
|
{ verb: 'get', path: '/:index/_list', controller: 'collection', action: 'list' },
|
|
48
62
|
|
|
63
|
+
{ verb: 'post', path: '/admin/_refreshIndexCache', controller: 'admin', action: 'refreshIndexCache' },
|
|
49
64
|
{ verb: 'post', path: '/admin/_resetCache', controller: 'admin', action: 'resetCache' },
|
|
50
65
|
{ verb: 'post', path: '/admin/_resetSecurity', controller: 'admin', action: 'resetSecurity' },
|
|
51
66
|
{ verb: 'post', path: '/admin/_resetDatabase', controller: 'admin', action: 'resetDatabase' },
|
|
@@ -56,10 +71,10 @@ const routes = [
|
|
|
56
71
|
{ verb: 'post', path: '/admin/_loadMappings', controller: 'admin', action: 'loadMappings' },
|
|
57
72
|
{ verb: 'post', path: '/admin/_loadSecurities', controller: 'admin', action: 'loadSecurities' },
|
|
58
73
|
|
|
59
|
-
{ verb: 'get', path: '/:index/:collection/:_id', controller: 'document', action: 'get' },
|
|
74
|
+
{ verb: 'get', path: '/:index/:collection/:_id', controller: 'document', action: 'get', openapi: OpenApiDocumentGet },
|
|
60
75
|
{ verb: 'get', path: '/:index/:collection/_mGet', controller: 'document', action: 'mGet' },
|
|
61
|
-
{ verb: 'get', path: '/:index/:collection/:_id/_exists', controller: 'document', action: 'exists' },
|
|
62
|
-
{ verb: 'get', path: '/_scroll/:scrollId', controller: 'document', action: 'scroll' },
|
|
76
|
+
{ verb: 'get', path: '/:index/:collection/:_id/_exists', controller: 'document', action: 'exists', openapi: OpenApiDocumentExists },
|
|
77
|
+
{ verb: 'get', path: '/_scroll/:scrollId', controller: 'document', action: 'scroll', openapi: OpenApiDocumentScroll },
|
|
63
78
|
|
|
64
79
|
{ verb: 'get', path: '/:index/_exists', controller: 'index', action: 'exists' },
|
|
65
80
|
{ verb: 'get', path: '/:index/_autoRefresh', controller: 'index', action: 'getAutoRefresh' },
|
|
@@ -87,16 +102,17 @@ const routes = [
|
|
|
87
102
|
{ verb: 'get', path: '/profiles/_scroll/:scrollId', controller: 'security', action: 'scrollProfiles' },
|
|
88
103
|
|
|
89
104
|
{ verb: 'get', path: '/_adminExists', controller: 'server', action: 'adminExists' },
|
|
90
|
-
{ verb: 'get', path: '/_getAllStats', controller: 'server', action: 'getAllStats' },
|
|
105
|
+
{ verb: 'get', path: '/_getAllStats', controller: 'server', action: 'getAllStats', deprecated: { since: 'auto-version', message: 'Use this route instead: http://kuzzle:7512/_metrics' } }, // @deprecated
|
|
91
106
|
{ verb: 'get', path: '/_getConfig', controller: 'server', action: 'getConfig' },
|
|
92
|
-
{ verb: 'get', path: '/_getLastStats', controller: 'server', action: 'getLastStats' },
|
|
93
|
-
{ verb: 'get', path: '/_getStats', controller: 'server', action: 'getStats' },
|
|
107
|
+
{ verb: 'get', path: '/_getLastStats', controller: 'server', action: 'getLastStats', deprecated: { since: 'auto-version', message: 'Use this route instead: http://kuzzle:7512/_metrics' } }, // @deprecated
|
|
108
|
+
{ verb: 'get', path: '/_getStats', controller: 'server', action: 'getStats', deprecated: { since: 'auto-version', message: 'Use this route instead: http://kuzzle:7512/_metrics' } }, // @deprecated
|
|
94
109
|
{ verb: 'get', path: '/', controller: 'server', action: 'info' },
|
|
95
110
|
{ verb: 'get', path: '/_healthCheck', controller: 'server', action: 'healthCheck' },
|
|
96
111
|
{ verb: 'get', path: '/_serverInfo', controller: 'server', action: 'info' },
|
|
97
112
|
{ verb: 'get', path: '/_now', controller: 'server', action: 'now' },
|
|
98
113
|
{ verb: 'get', path: '/_publicApi', controller: 'server', action: 'publicApi', deprecated: { since: '2.5.0', message: 'Use this route instead: http://kuzzle:7512/_openapi' } }, // @deprecated
|
|
99
114
|
{ verb: 'get', path: '/_openapi', controller: 'server', action: 'openapi' },
|
|
115
|
+
{ verb: 'get', path: '/_metrics', controller: 'server', action: 'metrics' },
|
|
100
116
|
|
|
101
117
|
{ verb: 'get', path: '/ms/_bitcount/:_id', controller: 'ms', action: 'bitcount' },
|
|
102
118
|
{ verb: 'get', path: '/ms/_bitpos/:_id', controller: 'ms', action: 'bitpos' },
|
|
@@ -182,8 +198,8 @@ const routes = [
|
|
|
182
198
|
|
|
183
199
|
{ verb: 'post', path: '/:index/_create', controller: 'index', action: 'create' },
|
|
184
200
|
|
|
185
|
-
{ verb: 'post', path: '/:index/:collection/_count', controller: 'document', action: 'count' },
|
|
186
|
-
{ verb: 'post', path: '/:index/:collection/_create', controller: 'document', action: 'create' },
|
|
201
|
+
{ verb: 'post', path: '/:index/:collection/_count', controller: 'document', action: 'count', openapi: OpenApiDocumentCount },
|
|
202
|
+
{ verb: 'post', path: '/:index/:collection/_create', controller: 'document', action: 'create', openapi: OpenApiDocumentCreate },
|
|
187
203
|
{ verb: 'post', path: '/:index/:collection/:_id/_create', controller: 'document', action: 'create' },
|
|
188
204
|
{ verb: 'post', path: '/:index/:collection/_publish', controller: 'realtime', action: 'publish' },
|
|
189
205
|
{ verb: 'post', path: '/:index/:collection/_search', controller: 'document', action: 'search' },
|
|
@@ -288,9 +304,9 @@ const routes = [
|
|
|
288
304
|
{ verb: 'delete', path: '/:index/:collection/_specifications', controller: 'collection', action: 'deleteSpecifications' },
|
|
289
305
|
{ verb: 'delete', path: '/:index/:collection/_truncate', controller: 'collection', action: 'truncate' },
|
|
290
306
|
|
|
291
|
-
{ verb: 'delete', path: '/:index/:collection/:_id', controller: 'document', action: 'delete' },
|
|
307
|
+
{ verb: 'delete', path: '/:index/:collection/:_id', controller: 'document', action: 'delete', openapi: OpenApiDocumentDelete },
|
|
292
308
|
{ verb: 'delete', path: '/:index/:collection/:_id/_fields', controller: 'document', action: 'deleteFields' },
|
|
293
|
-
{ verb: 'delete', path: '/:index/:collection/_query', controller: 'document', action: 'deleteByQuery' },
|
|
309
|
+
{ verb: 'delete', path: '/:index/:collection/_query', controller: 'document', action: 'deleteByQuery', openapi: OpenApiDocumentDeleteByQuery },
|
|
294
310
|
{ verb: 'delete', path: '/:index/:collection/_bulk/_query', controller: 'bulk', action: 'deleteByQuery' },
|
|
295
311
|
|
|
296
312
|
{ verb: 'delete', path: '/:index/:collection/_mDelete', controller: 'document', action: 'mDelete' },
|
|
@@ -333,18 +349,18 @@ const routes = [
|
|
|
333
349
|
|
|
334
350
|
{ verb: 'put', path: '/:index/:collection/_specifications', controller: 'collection', action: 'updateSpecifications' },
|
|
335
351
|
|
|
336
|
-
{ verb: 'put', path: '/:index/:collection/:_id', controller: 'document', action: 'createOrReplace' },
|
|
352
|
+
{ verb: 'put', path: '/:index/:collection/:_id', controller: 'document', action: 'createOrReplace', openapi: OpenApiDocumentCreateOrReplace },
|
|
337
353
|
{ verb: 'put', path: '/:index/:collection/_mCreateOrReplace', controller: 'document', action: 'mCreateOrReplace' },
|
|
338
|
-
{ verb: 'put', path: '/:index/:collection/:_id/_replace', controller: 'document', action: 'replace' },
|
|
354
|
+
{ verb: 'put', path: '/:index/:collection/:_id/_replace', controller: 'document', action: 'replace', openapi: OpenApiDocumentReplace },
|
|
339
355
|
{ verb: 'put', path: '/:index/:collection/_mReplace', controller: 'document', action: 'mReplace' },
|
|
340
356
|
{ verb: 'put', path: '/:index/:collection/_mUpdate', controller: 'document', action: 'mUpdate', deprecated: { since: '2.11.0', message: 'Use "document:mUpdate" route with PATCH instead of PUT' } }, // @deprecated
|
|
341
|
-
{ verb: 'put', path: '/:index/:collection/:_id/_update', controller: 'document', action: 'update', deprecated: { since: '2.11.0', message: 'Use "document:update" route with PATCH instead of PUT' } }, // @deprecated
|
|
357
|
+
{ verb: 'put', path: '/:index/:collection/:_id/_update', controller: 'document', action: 'update', openapi: OpenApiDocumentUpdate, deprecated: { since: '2.11.0', message: 'Use "document:update" route with PATCH instead of PUT' } }, // @deprecated
|
|
342
358
|
{ verb: 'put', path: '/:index/:collection/:_id/_upsert', controller: 'document', action: 'upsert', deprecated: { since: '2.11.0', message: 'Use "document:upsert" route with POST instead of PUT' } }, // @deprecated
|
|
343
359
|
{ verb: 'put', path: '/:index/:collection/_query', controller: 'document', action: 'updateByQuery' },
|
|
344
360
|
|
|
345
361
|
{ verb: 'put', path: '/profiles/:_id', controller: 'security', action: 'createOrReplaceProfile' },
|
|
346
362
|
{ verb: 'put', path: '/roles/:_id', controller: 'security', action: 'createOrReplaceRole' },
|
|
347
|
-
{ verb: 'put', path: '/credentials/:strategy/:_id/_update', controller: 'security', action: 'updateCredentials' },
|
|
363
|
+
{ verb: 'put', path: '/credentials/:strategy/:_id/_update', controller: 'security', action: 'updateCredentials', },
|
|
348
364
|
{ verb: 'put', path: '/profiles/:_id/_update', controller: 'security', action: 'updateProfile' },
|
|
349
365
|
{ verb: 'put', path: '/roles/:_id/_update', controller: 'security', action: 'updateRole' },
|
|
350
366
|
{ verb: 'put', path: '/users/:_id/_update', controller: 'security', action: 'updateUser' },
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateOpenApi = void 0;
|
|
1
7
|
/*
|
|
2
8
|
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
9
|
* to power modern apps
|
|
@@ -18,141 +24,176 @@
|
|
|
18
24
|
* See the License for the specific language governing permissions and
|
|
19
25
|
* limitations under the License.
|
|
20
26
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
27
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
28
|
+
const package_json_1 = require("./../../package.json");
|
|
29
|
+
const document_1 = require("./openapi/documents/document");
|
|
30
|
+
const inflector_1 = require("./../util/inflector");
|
|
26
31
|
const routeUrlMatch = /:([^/]*)/g;
|
|
27
|
-
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @returns {object} openApi object
|
|
33
|
+
* Genrate basic openApi Controller
|
|
32
34
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
description: 'The Kuzzle HTTP API',
|
|
45
|
-
contact: {
|
|
46
|
-
name: 'Kuzzle team',
|
|
47
|
-
url: 'http://kuzzle.io',
|
|
48
|
-
email: 'hello@kuzzle.io'
|
|
49
|
-
},
|
|
50
|
-
license: {
|
|
51
|
-
name: 'Apache 2',
|
|
52
|
-
url: 'http://opensource.org/licenses/apache2.0'
|
|
53
|
-
},
|
|
54
|
-
version: require('../../package').version
|
|
55
|
-
},
|
|
56
|
-
externalDocs: {
|
|
57
|
-
description: 'Kuzzle API Documentation',
|
|
58
|
-
url: 'https://docs.kuzzle.io/core/2/api/'
|
|
59
|
-
},
|
|
60
|
-
servers: [
|
|
61
|
-
{
|
|
62
|
-
url: 'https://{baseUrl}:{port}',
|
|
63
|
-
description: 'Kuzzle Base Url',
|
|
64
|
-
variables: {
|
|
65
|
-
baseUrl: {
|
|
66
|
-
default: 'localhost'
|
|
67
|
-
},
|
|
68
|
-
port: {
|
|
69
|
-
default: '7512'
|
|
70
|
-
}
|
|
35
|
+
function generateController(route, response) {
|
|
36
|
+
if (route.controller !== undefined) {
|
|
37
|
+
if (!lodash_1.default.some(response.tags, { name: route.controller })) {
|
|
38
|
+
const capitalizedController = inflector_1.Inflector.upFirst(route.controller);
|
|
39
|
+
response.tags.push({ description: `${capitalizedController} Controller`, name: route.controller });
|
|
40
|
+
}
|
|
41
|
+
if (route.openapi.tags === undefined) {
|
|
42
|
+
route.openapi.tags = [];
|
|
43
|
+
}
|
|
44
|
+
if (!route.openapi.tags.includes(route.controller)) {
|
|
45
|
+
route.openapi.tags.push(route.controller);
|
|
71
46
|
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
tags: [],
|
|
76
|
-
paths: {},
|
|
77
|
-
};
|
|
78
|
-
/* eslint-enable sort-keys */
|
|
79
|
-
|
|
80
|
-
routes.forEach(route => {
|
|
81
|
-
// Make sure route verbs are lowercase
|
|
82
|
-
if (route.verb !== undefined) {
|
|
83
|
-
route.verb = route.verb.toLowerCase();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Set :param notation to {param}
|
|
87
|
-
route.formattedPath = route.path.replace(routeUrlMatch, '{$1}');
|
|
88
|
-
|
|
89
|
-
if (response.paths[route.formattedPath] === undefined) {
|
|
90
|
-
response.paths[route.formattedPath] = {};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (response.paths[route.formattedPath][route.verb] !== undefined) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// If custom specification, return as it is
|
|
98
|
-
if (route.openapi) {
|
|
99
|
-
response.paths[route.formattedPath][route.verb] = route.openapi;
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (route.info === undefined) {
|
|
104
|
-
route.info = {};
|
|
105
47
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
route.
|
|
113
|
-
}
|
|
114
|
-
if (!route.info.tags.includes(route.controller)) {
|
|
115
|
-
route.info.tags.push(route.controller);
|
|
116
|
-
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Genrate basic openApi Summary
|
|
51
|
+
*/
|
|
52
|
+
function generateSummary(route) {
|
|
53
|
+
if (route.openapi.description === undefined) {
|
|
54
|
+
route.openapi.description = `Controller: ${route.controller}.`;
|
|
117
55
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
route.info.description = `Controller: ${route.controller}.`;
|
|
56
|
+
if (route.openapi.summary === undefined) {
|
|
57
|
+
route.openapi.summary = `Action: ${route.action}.`;
|
|
121
58
|
}
|
|
122
|
-
|
|
123
|
-
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Genrate basic openApi Parameters
|
|
62
|
+
*/
|
|
63
|
+
function generateParameters(route) {
|
|
64
|
+
if (route.openapi.parameters === undefined) {
|
|
65
|
+
route.openapi.parameters = [];
|
|
66
|
+
let m = routeUrlMatch.exec(route.path);
|
|
67
|
+
while (m !== null) {
|
|
68
|
+
routeUrlMatch.lastIndex++;
|
|
69
|
+
route.openapi.parameters.push({
|
|
70
|
+
in: 'path',
|
|
71
|
+
name: m[1],
|
|
72
|
+
required: true,
|
|
73
|
+
schema: { type: 'string' }
|
|
74
|
+
});
|
|
75
|
+
m = routeUrlMatch.exec(route.path);
|
|
76
|
+
}
|
|
124
77
|
}
|
|
125
|
-
if (route.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
let m = routeUrlMatch.exec(route.path);
|
|
129
|
-
while (m !== null) {
|
|
130
|
-
routeUrlMatch.lastIndex++;
|
|
131
|
-
route.info.parameters.push({
|
|
132
|
-
in: 'path',
|
|
133
|
-
name: m[1],
|
|
134
|
-
required: true,
|
|
135
|
-
schema: {type: 'string'}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
m = routeUrlMatch.exec(route.path);
|
|
139
|
-
}
|
|
78
|
+
if (route.openapi.parameters.length === 0) {
|
|
79
|
+
route.openapi.parameters = undefined;
|
|
140
80
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Genrate basic openApi Response
|
|
84
|
+
*/
|
|
85
|
+
function generateResponse(route) {
|
|
86
|
+
if (route.openapi.responses === undefined) {
|
|
87
|
+
route.openapi.responses = {
|
|
88
|
+
'200': {
|
|
89
|
+
description: 'OK'
|
|
90
|
+
}
|
|
91
|
+
};
|
|
144
92
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generates JSON OpenApi object
|
|
96
|
+
*
|
|
97
|
+
* @returns {object} openApi object
|
|
98
|
+
*/
|
|
99
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
100
|
+
function generateOpenApi() {
|
|
101
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
102
|
+
const routes = [];
|
|
103
|
+
global.kuzzle.config.http.routes.forEach(_route => routes.push({ ..._route }));
|
|
104
|
+
global.kuzzle.pluginsManager.routes.forEach(_route => routes.push({ ..._route }));
|
|
105
|
+
/* eslint-disable sort-keys */
|
|
106
|
+
const response = {
|
|
107
|
+
swagger: '2.0',
|
|
108
|
+
info: {
|
|
109
|
+
title: 'Kuzzle API',
|
|
110
|
+
description: 'The Kuzzle HTTP API',
|
|
111
|
+
contact: {
|
|
112
|
+
name: 'Kuzzle team',
|
|
113
|
+
url: 'http://kuzzle.io',
|
|
114
|
+
email: 'hello@kuzzle.io',
|
|
115
|
+
discord: 'http://join.discord.kuzzle.io'
|
|
116
|
+
},
|
|
117
|
+
license: {
|
|
118
|
+
name: 'Apache 2',
|
|
119
|
+
url: 'http://opensource.org/licenses/apache2.0'
|
|
120
|
+
},
|
|
121
|
+
version: package_json_1.version
|
|
122
|
+
},
|
|
123
|
+
externalDocs: {
|
|
124
|
+
description: 'Kuzzle API Documentation',
|
|
125
|
+
url: 'https://docs.kuzzle.io/core/2/api/'
|
|
126
|
+
},
|
|
127
|
+
servers: [
|
|
128
|
+
{
|
|
129
|
+
url: 'https://{baseUrl}:{port}',
|
|
130
|
+
description: 'Kuzzle Base Url',
|
|
131
|
+
variables: {
|
|
132
|
+
baseUrl: {
|
|
133
|
+
default: 'localhost'
|
|
134
|
+
},
|
|
135
|
+
port: {
|
|
136
|
+
default: '7512'
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
tags: [
|
|
142
|
+
{
|
|
143
|
+
name: 'document',
|
|
144
|
+
description: 'document controller'
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
schemes: [
|
|
148
|
+
'https',
|
|
149
|
+
'http'
|
|
150
|
+
],
|
|
151
|
+
paths: {},
|
|
152
|
+
components: {
|
|
153
|
+
...document_1.DefinitionsDocument,
|
|
154
|
+
schemas: {
|
|
155
|
+
...document_1.OpenApiDocumentCountComponent,
|
|
156
|
+
...document_1.OpenApiDocumentDeleteByQueryComponent,
|
|
157
|
+
...document_1.OpenApiDocumentDeleteComponent,
|
|
158
|
+
...document_1.OpenApiDocumentScrollComponent,
|
|
159
|
+
...document_1.OpenApiDocumentExistsComponent,
|
|
160
|
+
...document_1.OpenApiDocumentUpdateComponent,
|
|
161
|
+
...document_1.OpenApiDocumentReplaceComponent,
|
|
162
|
+
...document_1.OpenApiDocumentGetComponent,
|
|
163
|
+
...document_1.OpenApiDocumentCreateOrReplaceComponent,
|
|
164
|
+
...document_1.OpenApiDocumentCreateComponent,
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/* eslint-enable sort-keys */
|
|
169
|
+
for (const route of routes) {
|
|
170
|
+
// Make sure route verbs are lowercase
|
|
171
|
+
if (route.verb !== undefined) {
|
|
172
|
+
route.verb = route.verb.toLowerCase();
|
|
173
|
+
}
|
|
174
|
+
// Set :param notation to {param}
|
|
175
|
+
route.formattedPath = route.path.replace(routeUrlMatch, '{$1}');
|
|
176
|
+
if (response.paths[route.formattedPath] === undefined) {
|
|
177
|
+
response.paths[route.formattedPath] = {};
|
|
178
|
+
}
|
|
179
|
+
if (response.paths[route.formattedPath][route.verb] !== undefined) {
|
|
180
|
+
continue;
|
|
150
181
|
}
|
|
151
|
-
|
|
182
|
+
// If custom specification, return as it is
|
|
183
|
+
if (route.openapi) {
|
|
184
|
+
response.paths[route.formattedPath][route.verb] = route.openapi;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (route.openapi === undefined) {
|
|
188
|
+
route.openapi = {};
|
|
189
|
+
}
|
|
190
|
+
generateController(route, response);
|
|
191
|
+
generateSummary(route);
|
|
192
|
+
generateParameters(route);
|
|
193
|
+
generateResponse(route);
|
|
194
|
+
response.paths[route.formattedPath][route.verb] = route.openapi;
|
|
152
195
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return response;
|
|
158
|
-
};
|
|
196
|
+
return response;
|
|
197
|
+
}
|
|
198
|
+
exports.generateOpenApi = generateOpenApi;
|
|
199
|
+
//# sourceMappingURL=openApiGenerator.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const OpenApiDocumentCount: any;
|
|
2
|
+
export declare const OpenApiDocumentCountComponent: any;
|
|
3
|
+
export declare const OpenApiDocumentCreate: any;
|
|
4
|
+
export declare const OpenApiDocumentCreateComponent: any;
|
|
5
|
+
export declare const OpenApiDocumentCreateOrReplace: any;
|
|
6
|
+
export declare const OpenApiDocumentCreateOrReplaceComponent: any;
|
|
7
|
+
export declare const OpenApiDocumentGet: any;
|
|
8
|
+
export declare const OpenApiDocumentGetComponent: any;
|
|
9
|
+
export declare const OpenApiDocumentReplace: any;
|
|
10
|
+
export declare const OpenApiDocumentReplaceComponent: any;
|
|
11
|
+
export declare const OpenApiDocumentExists: any;
|
|
12
|
+
export declare const OpenApiDocumentExistsComponent: any;
|
|
13
|
+
export declare const OpenApiDocumentUpdate: any;
|
|
14
|
+
export declare const OpenApiDocumentUpdateComponent: any;
|
|
15
|
+
export declare const OpenApiDocumentScroll: any;
|
|
16
|
+
export declare const OpenApiDocumentScrollComponent: any;
|
|
17
|
+
export declare const OpenApiDocumentDelete: any;
|
|
18
|
+
export declare const OpenApiDocumentDeleteComponent: any;
|
|
19
|
+
export declare const OpenApiDocumentDeleteByQuery: any;
|
|
20
|
+
export declare const OpenApiDocumentDeleteByQueryComponent: any;
|
|
21
|
+
export declare const DefinitionsDocument: any;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefinitionsDocument = exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
|
|
4
|
+
const tools_1 = require("../tools");
|
|
5
|
+
// reading the description of the Count action in the controller document.
|
|
6
|
+
// The yaml objects are then stored in the variables below
|
|
7
|
+
const countObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/count.yaml');
|
|
8
|
+
exports.OpenApiDocumentCount = countObject.DocumentCount;
|
|
9
|
+
exports.OpenApiDocumentCountComponent = countObject.components.schemas;
|
|
10
|
+
// reading the description of the Create action in the controller document.
|
|
11
|
+
// The yaml objects are then stored in the variables below
|
|
12
|
+
const createObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/create.yaml');
|
|
13
|
+
exports.OpenApiDocumentCreate = createObject.DocumentCreate;
|
|
14
|
+
exports.OpenApiDocumentCreateComponent = createObject.components.schemas;
|
|
15
|
+
// reading the description of the CreateOrReplace action in the controller document.
|
|
16
|
+
// The yaml objects are then stored in the variables below
|
|
17
|
+
const createOrReplaceObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/createOrReplace.yaml');
|
|
18
|
+
exports.OpenApiDocumentCreateOrReplace = createOrReplaceObject.DocumentCreateOrReplace;
|
|
19
|
+
exports.OpenApiDocumentCreateOrReplaceComponent = createOrReplaceObject.components.schemas;
|
|
20
|
+
// reading the description of the Get action in the controller document.
|
|
21
|
+
// The yaml objects are then stored in the variables below
|
|
22
|
+
const getObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/get.yaml');
|
|
23
|
+
exports.OpenApiDocumentGet = getObject.DocumentGet;
|
|
24
|
+
exports.OpenApiDocumentGetComponent = getObject.components.schemas;
|
|
25
|
+
// reading the description of the Replace action in the controller document.
|
|
26
|
+
// The yaml objects are then stored in the variables below
|
|
27
|
+
const replaceObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/replace.yaml');
|
|
28
|
+
exports.OpenApiDocumentReplace = replaceObject.DocumentReplace;
|
|
29
|
+
exports.OpenApiDocumentReplaceComponent = replaceObject.components.schemas;
|
|
30
|
+
// reading the description of the Exists action in the controller document.
|
|
31
|
+
// The yaml objects are then stored in the variables below
|
|
32
|
+
const existsObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/exists.yaml');
|
|
33
|
+
exports.OpenApiDocumentExists = existsObject.DocumentExists;
|
|
34
|
+
exports.OpenApiDocumentExistsComponent = existsObject.components.schemas;
|
|
35
|
+
// reading the description of the Update action in the controller document.
|
|
36
|
+
// The yaml objects are then stored in the variables below
|
|
37
|
+
const updateObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/update.yaml');
|
|
38
|
+
exports.OpenApiDocumentUpdate = updateObject.DocumentUpdate;
|
|
39
|
+
exports.OpenApiDocumentUpdateComponent = updateObject.components.schemas;
|
|
40
|
+
// reading the description of the Scroll action in the controller document.
|
|
41
|
+
// The yaml objects are then stored in the variables below
|
|
42
|
+
const scrollObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/scroll.yaml');
|
|
43
|
+
exports.OpenApiDocumentScroll = scrollObject.DocumentScroll;
|
|
44
|
+
exports.OpenApiDocumentScrollComponent = scrollObject.components.schemas;
|
|
45
|
+
// reading the description of the Delete action in the controller document.
|
|
46
|
+
// The yaml objects are then stored in the variables below
|
|
47
|
+
const deleteObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/delete.yaml');
|
|
48
|
+
exports.OpenApiDocumentDelete = deleteObject.DocumentDelete;
|
|
49
|
+
exports.OpenApiDocumentDeleteComponent = deleteObject.components.schemas;
|
|
50
|
+
// reading the description of the DeleteByQuery action in the controller document.
|
|
51
|
+
// The yaml objects are then stored in the variables below
|
|
52
|
+
const deleteByQueryObject = (0, tools_1.readYamlFile)('./lib/api/openapi/documents/deleteByQuery.yaml');
|
|
53
|
+
exports.OpenApiDocumentDeleteByQuery = deleteByQueryObject.DocumentDeleteByQuery;
|
|
54
|
+
exports.OpenApiDocumentDeleteByQueryComponent = deleteByQueryObject.components.schemas;
|
|
55
|
+
// Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
|
|
56
|
+
exports.DefinitionsDocument = (0, tools_1.readYamlFile)('./lib/api/openapi/payloads.yaml').definitions;
|
|
57
|
+
//# sourceMappingURL=document.js.map
|