Skip to content

Commit

Permalink
Bugfix/openapi import array body (#3009)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
anusreesubash and Anusree Subash committed Sep 5, 2024
1 parent 450b1d3 commit ab8afed
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/bruno-app/src/utils/importers/openapi-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = '';
}
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit ab8afed

Please sign in to comment.