Skip to content

Commit

Permalink
fix: make body content reset when selecting an other controller:action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebouthinon committed Jan 17, 2025
1 parent 9a5f963 commit cd831cc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 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,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);
},
Expand Down

0 comments on commit cd831cc

Please sign in to comment.