kuzzle 2.15.0 → 2.16.1
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/serverController.js +24 -4
- package/lib/api/funnel.js +19 -0
- package/lib/{config → api}/httpRoutes.js +29 -14
- package/lib/api/openApiGenerator.d.ts +6 -0
- package/lib/api/openApiGenerator.js +167 -126
- package/lib/api/openapi/document/count.yaml +47 -0
- package/lib/api/openapi/document/create.yaml +46 -0
- package/lib/api/openapi/document/createOrReplace.yaml +61 -0
- package/lib/api/openapi/document/delete.yaml +67 -0
- package/lib/api/openapi/document/deleteByQuery.yaml +90 -0
- package/lib/api/openapi/document/exists.yaml +35 -0
- package/lib/api/openapi/document/get.yaml +68 -0
- package/lib/api/openapi/document/index.d.ts +21 -0
- package/lib/api/openapi/document/index.js +57 -0
- package/lib/api/openapi/document/replace.yaml +66 -0
- package/lib/api/openapi/document/scroll.yaml +49 -0
- package/lib/api/openapi/document/update.yaml +78 -0
- package/lib/api/openapi/payloads.yaml +32 -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/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/storage/clientAdapter.js +1 -1
- package/lib/kuzzle/kuzzle.js +9 -5
- package/lib/service/storage/elasticsearch.js +14 -9
- package/lib/util/readYamlFile.d.ts +2 -0
- package/lib/util/readYamlFile.js +10 -0
- package/package-lock.json +173 -188
- package/package.json +13 -27
- package/.kuzzlerc.sample +0 -988
- package/CONTRIBUTING.md +0 -116
- package/bin/.lib/colorOutput.js +0 -71
- package/bin/.upgrades/connectors/es.js +0 -90
- package/bin/.upgrades/connectors/redis.js +0 -112
- package/bin/.upgrades/lib/connectorContext.js +0 -38
- package/bin/.upgrades/lib/context.js +0 -142
- package/bin/.upgrades/lib/formatters.js +0 -103
- package/bin/.upgrades/lib/inquirerExtended.js +0 -46
- package/bin/.upgrades/lib/logger.js +0 -99
- package/bin/.upgrades/lib/progressBar.js +0 -70
- package/bin/.upgrades/versions/v1/checkConfiguration.js +0 -85
- package/bin/.upgrades/versions/v1/index.js +0 -35
- package/bin/.upgrades/versions/v1/upgradeCache.js +0 -149
- package/bin/.upgrades/versions/v1/upgradeStorage.js +0 -450
- package/protocols/available/.gitignore +0 -4
- package/protocols/enabled/.gitignore +0 -4
|
@@ -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('./openapi/document');
|
|
38
|
+
|
|
39
|
+
|
|
26
40
|
const routes = [
|
|
27
41
|
// GET (idempotent)
|
|
28
42
|
{ verb: 'get', path: '/_me', controller: 'auth', action: 'getCurrentUser' },
|
|
@@ -57,10 +71,10 @@ const routes = [
|
|
|
57
71
|
{ verb: 'post', path: '/admin/_loadMappings', controller: 'admin', action: 'loadMappings' },
|
|
58
72
|
{ verb: 'post', path: '/admin/_loadSecurities', controller: 'admin', action: 'loadSecurities' },
|
|
59
73
|
|
|
60
|
-
{ verb: 'get', path: '/:index/:collection/:_id', controller: 'document', action: 'get' },
|
|
74
|
+
{ verb: 'get', path: '/:index/:collection/:_id', controller: 'document', action: 'get', openapi: OpenApiDocumentGet },
|
|
61
75
|
{ verb: 'get', path: '/:index/:collection/_mGet', controller: 'document', action: 'mGet' },
|
|
62
|
-
{ verb: 'get', path: '/:index/:collection/:_id/_exists', controller: 'document', action: 'exists' },
|
|
63
|
-
{ 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 },
|
|
64
78
|
|
|
65
79
|
{ verb: 'get', path: '/:index/_exists', controller: 'index', action: 'exists' },
|
|
66
80
|
{ verb: 'get', path: '/:index/_autoRefresh', controller: 'index', action: 'getAutoRefresh' },
|
|
@@ -88,16 +102,17 @@ const routes = [
|
|
|
88
102
|
{ verb: 'get', path: '/profiles/_scroll/:scrollId', controller: 'security', action: 'scrollProfiles' },
|
|
89
103
|
|
|
90
104
|
{ verb: 'get', path: '/_adminExists', controller: 'server', action: 'adminExists' },
|
|
91
|
-
{ 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
|
|
92
106
|
{ verb: 'get', path: '/_getConfig', controller: 'server', action: 'getConfig' },
|
|
93
|
-
{ verb: 'get', path: '/_getLastStats', controller: 'server', action: 'getLastStats' },
|
|
94
|
-
{ 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
|
|
95
109
|
{ verb: 'get', path: '/', controller: 'server', action: 'info' },
|
|
96
110
|
{ verb: 'get', path: '/_healthCheck', controller: 'server', action: 'healthCheck' },
|
|
97
111
|
{ verb: 'get', path: '/_serverInfo', controller: 'server', action: 'info' },
|
|
98
112
|
{ verb: 'get', path: '/_now', controller: 'server', action: 'now' },
|
|
99
113
|
{ verb: 'get', path: '/_publicApi', controller: 'server', action: 'publicApi', deprecated: { since: '2.5.0', message: 'Use this route instead: http://kuzzle:7512/_openapi' } }, // @deprecated
|
|
100
114
|
{ verb: 'get', path: '/_openapi', controller: 'server', action: 'openapi' },
|
|
115
|
+
{ verb: 'get', path: '/_metrics', controller: 'server', action: 'metrics' },
|
|
101
116
|
|
|
102
117
|
{ verb: 'get', path: '/ms/_bitcount/:_id', controller: 'ms', action: 'bitcount' },
|
|
103
118
|
{ verb: 'get', path: '/ms/_bitpos/:_id', controller: 'ms', action: 'bitpos' },
|
|
@@ -183,8 +198,8 @@ const routes = [
|
|
|
183
198
|
|
|
184
199
|
{ verb: 'post', path: '/:index/_create', controller: 'index', action: 'create' },
|
|
185
200
|
|
|
186
|
-
{ verb: 'post', path: '/:index/:collection/_count', controller: 'document', action: 'count' },
|
|
187
|
-
{ 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 },
|
|
188
203
|
{ verb: 'post', path: '/:index/:collection/:_id/_create', controller: 'document', action: 'create' },
|
|
189
204
|
{ verb: 'post', path: '/:index/:collection/_publish', controller: 'realtime', action: 'publish' },
|
|
190
205
|
{ verb: 'post', path: '/:index/:collection/_search', controller: 'document', action: 'search' },
|
|
@@ -289,9 +304,9 @@ const routes = [
|
|
|
289
304
|
{ verb: 'delete', path: '/:index/:collection/_specifications', controller: 'collection', action: 'deleteSpecifications' },
|
|
290
305
|
{ verb: 'delete', path: '/:index/:collection/_truncate', controller: 'collection', action: 'truncate' },
|
|
291
306
|
|
|
292
|
-
{ verb: 'delete', path: '/:index/:collection/:_id', controller: 'document', action: 'delete' },
|
|
307
|
+
{ verb: 'delete', path: '/:index/:collection/:_id', controller: 'document', action: 'delete', openapi: OpenApiDocumentDelete },
|
|
293
308
|
{ verb: 'delete', path: '/:index/:collection/:_id/_fields', controller: 'document', action: 'deleteFields' },
|
|
294
|
-
{ verb: 'delete', path: '/:index/:collection/_query', controller: 'document', action: 'deleteByQuery' },
|
|
309
|
+
{ verb: 'delete', path: '/:index/:collection/_query', controller: 'document', action: 'deleteByQuery', openapi: OpenApiDocumentDeleteByQuery },
|
|
295
310
|
{ verb: 'delete', path: '/:index/:collection/_bulk/_query', controller: 'bulk', action: 'deleteByQuery' },
|
|
296
311
|
|
|
297
312
|
{ verb: 'delete', path: '/:index/:collection/_mDelete', controller: 'document', action: 'mDelete' },
|
|
@@ -334,18 +349,18 @@ const routes = [
|
|
|
334
349
|
|
|
335
350
|
{ verb: 'put', path: '/:index/:collection/_specifications', controller: 'collection', action: 'updateSpecifications' },
|
|
336
351
|
|
|
337
|
-
{ verb: 'put', path: '/:index/:collection/:_id', controller: 'document', action: 'createOrReplace' },
|
|
352
|
+
{ verb: 'put', path: '/:index/:collection/:_id', controller: 'document', action: 'createOrReplace', openapi: OpenApiDocumentCreateOrReplace },
|
|
338
353
|
{ verb: 'put', path: '/:index/:collection/_mCreateOrReplace', controller: 'document', action: 'mCreateOrReplace' },
|
|
339
|
-
{ 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 },
|
|
340
355
|
{ verb: 'put', path: '/:index/:collection/_mReplace', controller: 'document', action: 'mReplace' },
|
|
341
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
|
|
342
|
-
{ 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
|
|
343
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
|
|
344
359
|
{ verb: 'put', path: '/:index/:collection/_query', controller: 'document', action: 'updateByQuery' },
|
|
345
360
|
|
|
346
361
|
{ verb: 'put', path: '/profiles/:_id', controller: 'security', action: 'createOrReplaceProfile' },
|
|
347
362
|
{ verb: 'put', path: '/roles/:_id', controller: 'security', action: 'createOrReplaceRole' },
|
|
348
|
-
{ verb: 'put', path: '/credentials/:strategy/:_id/_update', controller: 'security', action: 'updateCredentials' },
|
|
363
|
+
{ verb: 'put', path: '/credentials/:strategy/:_id/_update', controller: 'security', action: 'updateCredentials', },
|
|
349
364
|
{ verb: 'put', path: '/profiles/:_id/_update', controller: 'security', action: 'updateProfile' },
|
|
350
365
|
{ verb: 'put', path: '/roles/:_id/_update', controller: 'security', action: 'updateRole' },
|
|
351
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/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,47 @@
|
|
|
1
|
+
DocumentCount:
|
|
2
|
+
summary: "Counts documents in a collection."
|
|
3
|
+
tags:
|
|
4
|
+
- document
|
|
5
|
+
parameters:
|
|
6
|
+
- in: path
|
|
7
|
+
name: index
|
|
8
|
+
schema:
|
|
9
|
+
type: string
|
|
10
|
+
- in: path
|
|
11
|
+
name: collection
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
- in: body
|
|
15
|
+
name: "body"
|
|
16
|
+
description: "Counts documents in a collection."
|
|
17
|
+
required: true
|
|
18
|
+
schema:
|
|
19
|
+
$ref: "#/components/schemas/DocumentCountRequest"
|
|
20
|
+
responses:
|
|
21
|
+
200:
|
|
22
|
+
description: "Counts documents in a collection."
|
|
23
|
+
schema:
|
|
24
|
+
$ref: "#/components/schemas/DocumentCountResponse"
|
|
25
|
+
|
|
26
|
+
components:
|
|
27
|
+
schemas:
|
|
28
|
+
DocumentCountRequest:
|
|
29
|
+
allOf:
|
|
30
|
+
- type: "object"
|
|
31
|
+
properties:
|
|
32
|
+
query:
|
|
33
|
+
type: "object"
|
|
34
|
+
properties:
|
|
35
|
+
match_all:
|
|
36
|
+
type: "object"
|
|
37
|
+
|
|
38
|
+
DocumentCountResponse:
|
|
39
|
+
allOf:
|
|
40
|
+
- $ref: "#/components/ResponsePayload"
|
|
41
|
+
- type: "object"
|
|
42
|
+
properties:
|
|
43
|
+
result:
|
|
44
|
+
type: "object"
|
|
45
|
+
properties:
|
|
46
|
+
count:
|
|
47
|
+
type: "integer"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
DocumentCreate:
|
|
2
|
+
summary: "Creates a new document in the persistent data storage."
|
|
3
|
+
tags:
|
|
4
|
+
- document
|
|
5
|
+
parameters:
|
|
6
|
+
- in: path
|
|
7
|
+
name: index
|
|
8
|
+
schema:
|
|
9
|
+
type: string
|
|
10
|
+
- in: path
|
|
11
|
+
name: collection
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
- name: body
|
|
15
|
+
in: "body"
|
|
16
|
+
description: "Creates a new document in the persistent data storage."
|
|
17
|
+
required: true
|
|
18
|
+
schema:
|
|
19
|
+
$ref: "#/components/schemas/DocumentCreateRequest"
|
|
20
|
+
responses:
|
|
21
|
+
200:
|
|
22
|
+
description: "Creates a new document in the persistent data storage."
|
|
23
|
+
schema:
|
|
24
|
+
$ref: "#/components/schemas/DocumentCreateResponse"
|
|
25
|
+
|
|
26
|
+
components:
|
|
27
|
+
schemas:
|
|
28
|
+
DocumentCreateRequest:
|
|
29
|
+
allOf:
|
|
30
|
+
- type: "object"
|
|
31
|
+
description: "document content"
|
|
32
|
+
DocumentCreateResponse:
|
|
33
|
+
allOf:
|
|
34
|
+
- $ref: "#/components/ResponsePayload"
|
|
35
|
+
- type: "object"
|
|
36
|
+
properties:
|
|
37
|
+
result:
|
|
38
|
+
type: "object"
|
|
39
|
+
properties:
|
|
40
|
+
_id:
|
|
41
|
+
type: "string"
|
|
42
|
+
description: "documentId"
|
|
43
|
+
_version:
|
|
44
|
+
type: "integer"
|
|
45
|
+
_sources:
|
|
46
|
+
type: "object"
|