Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/ApiAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 26 additions & 1 deletion src/components/ApiAction/QueryCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
},
Expand Down
Loading