Skip to content

Commit a6bf8c6

Browse files
feat: fetch Kuzzle Application OpenAPI specs to prefill documented options (#1010)
* feat: fetch Kuzzle Application OpenAPI specs to prefill controller:action documented options * fix: make body content reset when selecting an other controller:action * fix: handle all the official OpenAPI types
1 parent a531554 commit a6bf8c6

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/components/ApiAction.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,17 @@ export default {
308308
},
309309
async getKuzzleOpenApi() {
310310
try {
311-
const openApi = await this.$kuzzle.query({
311+
const openApiKuzzle = await this.$kuzzle.query({
312312
controller: 'server',
313313
action: 'openapi',
314+
scope: 'kuzzle',
314315
});
315-
this.openapi = openApi.paths;
316+
const openApiApp = await this.$kuzzle.query({
317+
controller: 'server',
318+
action: 'openapi',
319+
scope: 'app',
320+
});
321+
this.openapi = { ...openApiApp.paths, ...openApiKuzzle.paths };
316322
} catch (error) {
317323
this.$log.error(error);
318324
this.$bvToast.toast(

src/components/ApiAction/QueryCard.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default {
230230
const obj = {
231231
controller: query.controller,
232232
action: query.action,
233-
body: query.body,
233+
body: {},
234234
};
235235
this.jsonQuery = JSON.stringify(obj, null, 2);
236236
this.$refs[`queryEditorWrapper-${this.tabIdx}`].setContent(this.jsonQuery);
@@ -246,6 +246,31 @@ export default {
246246
query[param.name] = '';
247247
}
248248
}
249+
const body = _.get(this.openapi, `${openApiPath}.${verb}.requestBody`, null);
250+
if (body && body.content['application/json']) {
251+
const prefilledBody = body.content['application/json'].schema.properties;
252+
for (const key of Object.keys(prefilledBody)) {
253+
switch (prefilledBody[key].type) {
254+
case 'string':
255+
query.body[key] = '';
256+
break;
257+
case 'number' || 'integer':
258+
query.body[key] = 0;
259+
break;
260+
case 'boolean':
261+
query.body[key] = false;
262+
break;
263+
case 'array':
264+
query.body[key] = [];
265+
break;
266+
case 'object':
267+
query.body[key] = {};
268+
break;
269+
default:
270+
query.body[key] = '';
271+
}
272+
}
273+
}
249274
this.jsonQuery = JSON.stringify(query, null, 2);
250275
this.$refs[`queryEditorWrapper-${this.tabIdx}`].setContent(this.jsonQuery);
251276
},

0 commit comments

Comments
 (0)