From ac83cd7cb29ce648c35ed5b6c9236d5759c24b8e Mon Sep 17 00:00:00 2001 From: Anusree Subash Date: Thu, 29 Aug 2024 17:09:50 +0530 Subject: [PATCH 1/5] added validations for spec and ref --- packages/bruno-app/src/utils/importers/openapi-collection.js | 4 ++-- 1 file changed, 2 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 5966563a75..885242faf1 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -224,7 +224,7 @@ const transformOpenapiRequestItem = (request) => { return brunoRequestItem; }; -const resolveRefs = (spec, components = spec.components, visitedItems = new Set()) => { +const resolveRefs = (spec, components = spec?.components, visitedItems = new Set()) => { if (!spec || typeof spec !== 'object') { return spec; } @@ -248,7 +248,7 @@ const resolveRefs = (spec, components = spec.components, visitedItems = new Set( let ref = components; for (const key of refKeys) { - if (ref[key]) { + if (ref && ref[key]) { ref = ref[key]; } else { // Handle invalid references gracefully? From bc3aebf28a4134014e4af8517355c00558d76f02 Mon Sep 17 00:00:00 2001 From: Anusree Subash Date: Fri, 30 Aug 2024 12:40:56 +0530 Subject: [PATCH 2/5] Fix | openapispec import-show proper body for arrays of objects --- .../bruno-app/src/utils/importers/openapi-collection.js | 8 ++++++-- 1 file changed, 6 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 885242faf1..4de1bd52f9 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -41,9 +41,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] = ''; } @@ -355,6 +358,7 @@ const parseOpenApiCollection = (data) => { return new Promise((resolve, reject) => { try { const collectionData = resolveRefs(data); + console.log(collectionData, "llllllllllllllllllll") if (!collectionData) { reject(new BrunoError('Invalid OpenAPI collection. Failed to resolve refs.')); return; From cc2586cd18a6717e7a06c4ef7a3da76fd1d726dd Mon Sep 17 00:00:00 2001 From: Anusree Subash Date: Fri, 30 Aug 2024 12:44:45 +0530 Subject: [PATCH 3/5] removed unwanted changes --- packages/bruno-app/src/utils/importers/openapi-collection.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index 4de1bd52f9..e91dea6a76 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -227,7 +227,7 @@ const transformOpenapiRequestItem = (request) => { return brunoRequestItem; }; -const resolveRefs = (spec, components = spec?.components, visitedItems = new Set()) => { +const resolveRefs = (spec, components = spec.components, visitedItems = new Set()) => { if (!spec || typeof spec !== 'object') { return spec; } @@ -251,7 +251,7 @@ const resolveRefs = (spec, components = spec?.components, visitedItems = new Set let ref = components; for (const key of refKeys) { - if (ref && ref[key]) { + if (ref[key]) { ref = ref[key]; } else { // Handle invalid references gracefully? @@ -358,7 +358,6 @@ const parseOpenApiCollection = (data) => { return new Promise((resolve, reject) => { try { const collectionData = resolveRefs(data); - console.log(collectionData, "llllllllllllllllllll") if (!collectionData) { reject(new BrunoError('Invalid OpenAPI collection. Failed to resolve refs.')); return; From 36e566c169cd9728a5586211905333302879ea8b Mon Sep 17 00:00:00 2001 From: Anusree Subash Date: Tue, 3 Sep 2024 15:47:55 +0530 Subject: [PATCH 4/5] handles body schema of array of objects --- .../bruno-app/src/utils/importers/openapi-collection.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index e91dea6a76..6e95188659 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -37,12 +37,15 @@ const ensureUrl = (url) => { }; const buildEmptyJsonBody = (bodySchema) => { + console.log(bodySchema) let _jsonBody = {}; each(bodySchema.properties || {}, (prop, name) => { if (prop.type === 'object') { _jsonBody[name] = buildEmptyJsonBody(prop); } else if (prop.type === 'array') { + console.log("here array") if (prop.items && prop.items.type === 'object') { + console.log("here object") _jsonBody[name] = [buildEmptyJsonBody(prop.items)]; } else { _jsonBody[name] = []; @@ -168,6 +171,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') { From 3393a17ed1db9a4d17ecd9c00988a9d50192b052 Mon Sep 17 00:00:00 2001 From: Anusree Subash Date: Tue, 3 Sep 2024 15:50:02 +0530 Subject: [PATCH 5/5] removed logs --- packages/bruno-app/src/utils/importers/openapi-collection.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index 6e95188659..cf93cf0c7e 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -37,15 +37,12 @@ const ensureUrl = (url) => { }; const buildEmptyJsonBody = (bodySchema) => { - console.log(bodySchema) let _jsonBody = {}; each(bodySchema.properties || {}, (prop, name) => { if (prop.type === 'object') { _jsonBody[name] = buildEmptyJsonBody(prop); } else if (prop.type === 'array') { - console.log("here array") if (prop.items && prop.items.type === 'object') { - console.log("here object") _jsonBody[name] = [buildEmptyJsonBody(prop.items)]; } else { _jsonBody[name] = [];