mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 11:51:30 +00:00
fix: openapi import fails when requestbody content is empty (#6200)
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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 = `
|
||||
|
||||
Reference in New Issue
Block a user