From ab8afed8f9c7fa79c61a94766bcdbcf80ae53da8 Mon Sep 17 00:00:00 2001 From: anusreesubash <65728079+anusreesubash@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:03:47 +0530 Subject: [PATCH] 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 --- .../src/utils/importers/openapi-collection.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index 1b6a2dd92..55719e74f 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -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') {