Bugfix/openapi import array body (#3009)

* added validations for spec and ref

* Fix | openapispec import-show proper body for arrays of objects

* removed unwanted changes

* handles body schema of array of objects

* removed logs

---------

Co-authored-by: Anusree Subash <anusree@usebruno.com>
This commit is contained in:
anusreesubash 2024-09-05 19:03:47 +05:30 committed by GitHub
parent 450b1d3ae3
commit ab8afed8f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,9 +40,12 @@ const buildEmptyJsonBody = (bodySchema) => {
each(bodySchema.properties || {}, (prop, name) => {
if (prop.type === 'object') {
_jsonBody[name] = buildEmptyJsonBody(prop);
// handle arrays
} else if (prop.type === 'array') {
_jsonBody[name] = [];
if (prop.items && prop.items.type === 'object') {
_jsonBody[name] = [buildEmptyJsonBody(prop.items)];
} else {
_jsonBody[name] = [];
}
} else {
_jsonBody[name] = '';
}
@ -164,6 +167,9 @@ const transformOpenapiRequestItem = (request) => {
let _jsonBody = buildEmptyJsonBody(bodySchema);
brunoRequestItem.request.body.json = JSON.stringify(_jsonBody, null, 2);
}
if (bodySchema && bodySchema.type === 'array') {
brunoRequestItem.request.body.json = JSON.stringify([buildEmptyJsonBody(bodySchema.items)], null, 2);
}
} else if (mimeType === 'application/x-www-form-urlencoded') {
brunoRequestItem.request.body.mode = 'formUrlEncoded';
if (bodySchema && bodySchema.type === 'object') {