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( diff --git a/src/components/ApiAction/QueryCard.vue b/src/components/ApiAction/QueryCard.vue index c4812be7c..cf5652dc0 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,31 @@ 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' || 'integer': + query.body[key] = 0; + break; + case 'boolean': + query.body[key] = false; + break; + case 'array': + query.body[key] = []; + break; + case 'object': + query.body[key] = {}; + break; + default: + query.body[key] = ''; + } + } + } this.jsonQuery = JSON.stringify(query, null, 2); this.$refs[`queryEditorWrapper-${this.tabIdx}`].setContent(this.jsonQuery); },