From 9a5f963756408f8c502778aab5f4cf1e5f96b7ee Mon Sep 17 00:00:00 2001 From: Alexandre Bouthinon Date: Fri, 17 Jan 2025 07:39:39 +0100 Subject: [PATCH 1/3] feat: fetch Kuzzle Application OpenAPI specs to prefill controller:action documented options --- src/components/ApiAction.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/ApiAction.vue b/src/components/ApiAction.vue index 024e11570..95f099cf7 100644 --- a/src/components/ApiAction.vue +++ b/src/components/ApiAction.vue @@ -308,11 +308,17 @@ export default { }, async getKuzzleOpenApi() { try { - const openApi = await this.$kuzzle.query({ + const openApiKuzzle = await this.$kuzzle.query({ controller: 'server', action: 'openapi', + scope: 'kuzzle', }); - this.openapi = openApi.paths; + const openApiApp = await this.$kuzzle.query({ + controller: 'server', + action: 'openapi', + scope: 'app', + }); + this.openapi = { ...openApiApp.paths, ...openApiKuzzle.paths }; } catch (error) { this.$log.error(error); this.$bvToast.toast( From cd831ccf9ca95e1fc9e754982030d11038f9e7b3 Mon Sep 17 00:00:00 2001 From: Alexandre Bouthinon Date: Fri, 17 Jan 2025 08:07:33 +0100 Subject: [PATCH 2/3] fix: make body content reset when selecting an other controller:action --- src/components/ApiAction/QueryCard.vue | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/ApiAction/QueryCard.vue b/src/components/ApiAction/QueryCard.vue index c4812be7c..912497018 100644 --- a/src/components/ApiAction/QueryCard.vue +++ b/src/components/ApiAction/QueryCard.vue @@ -230,7 +230,7 @@ export default { const obj = { controller: query.controller, action: query.action, - body: query.body, + body: {}, }; this.jsonQuery = JSON.stringify(obj, null, 2); this.$refs[`queryEditorWrapper-${this.tabIdx}`].setContent(this.jsonQuery); @@ -246,6 +246,28 @@ export default { query[param.name] = ''; } } + const body = _.get(this.openapi, `${openApiPath}.${verb}.requestBody`, null); + if (body && body.content['application/json']) { + const prefilledBody = body.content['application/json'].schema.properties; + for (const key of Object.keys(prefilledBody)) { + switch (prefilledBody[key].type) { + case 'string': + query.body[key] = ''; + break; + case 'number': + query.body[key] = 0; + break; + case 'boolean': + query.body[key] = false; + break; + case 'array': + query.body[key] = []; + break; + default: + query.body[key] = ''; + } + } + } this.jsonQuery = JSON.stringify(query, null, 2); this.$refs[`queryEditorWrapper-${this.tabIdx}`].setContent(this.jsonQuery); }, From efa2bbb97e9806053f7dc4b8062532698dc1f543 Mon Sep 17 00:00:00 2001 From: Alexandre Bouthinon Date: Fri, 17 Jan 2025 08:11:30 +0100 Subject: [PATCH 3/3] fix: handle all the official OpenAPI types --- src/components/ApiAction/QueryCard.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/ApiAction/QueryCard.vue b/src/components/ApiAction/QueryCard.vue index 912497018..cf5652dc0 100644 --- a/src/components/ApiAction/QueryCard.vue +++ b/src/components/ApiAction/QueryCard.vue @@ -254,7 +254,7 @@ export default { case 'string': query.body[key] = ''; break; - case 'number': + case 'number' || 'integer': query.body[key] = 0; break; case 'boolean': @@ -263,6 +263,9 @@ export default { case 'array': query.body[key] = []; break; + case 'object': + query.body[key] = {}; + break; default: query.body[key] = ''; }