From 6aaccabc04b6fe75982ab39d2830fd803cf6281f Mon Sep 17 00:00:00 2001 From: sanish chirayath Date: Tue, 25 Nov 2025 16:19:57 +0530 Subject: [PATCH] fix: openapi import fails when requestbody content is empty (#6200) --- .../src/openapi/openapi-to-bruno.js | 4 +-- .../openapi-to-bruno/openapi-to-bruno.spec.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/bruno-converters/src/openapi/openapi-to-bruno.js b/packages/bruno-converters/src/openapi/openapi-to-bruno.js index 54d459f18..8569d5c8a 100644 --- a/packages/bruno-converters/src/openapi/openapi-to-bruno.js +++ b/packages/bruno-converters/src/openapi/openapi-to-bruno.js @@ -199,7 +199,7 @@ const getExampleFromSchema = (schema) => { * @param {string} params.contentType - Content type (e.g., 'application/json', 'application/ld+json') */ const populateRequestBody = ({ body, requestBodyValue, contentType }) => { - if (!requestBodyValue || !contentType) return; + if (!requestBodyValue || !contentType || typeof contentType !== 'string') return; // Normalize: lowercase (content types from OpenAPI spec object keys may vary in case) const normalizedContentType = contentType.toLowerCase(); @@ -485,7 +485,7 @@ const transformOpenapiRequestItem = (request, usedNames = new Set()) => { let bodySchema = body.schema; // Normalize: lowercase (object keys may vary in case) - const normalizedMimeType = mimeType.toLowerCase(); + const normalizedMimeType = typeof mimeType === 'string' ? mimeType.toLowerCase() : ''; if (CONTENT_TYPE_PATTERNS.JSON.test(normalizedMimeType)) { brunoRequestItem.request.body.mode = 'json'; diff --git a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js index 717e9cace..9a88018bc 100644 --- a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js +++ b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js @@ -234,6 +234,32 @@ servers: expect(result.items[0].root.request.auth.mode).toBe('inherit'); }); }); + + it('should handle requestBody with empty content object (undefined mimeType)', () => { + const openApiWithEmptyContent = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API with empty requestBody content' +paths: + /test: + post: + summary: 'Test endpoint with empty content' + operationId: 'testEndpoint' + requestBody: + content: {} + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithEmptyContent); + expect(result.items[0].request.body.mode).toBe('none'); + expect(result.items[0].request.body.json).toBe(null); + expect(result.items[0].request.body.text).toBe(null); + expect(result.items[0].request.body.xml).toBe(null); + }); }); const openApiCollectionString = `