mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-23 12:45:38 +00:00
fix: generate examples for description only responses in swagger 2.0 converter (#7717)
This commit is contained in:
@@ -322,6 +322,18 @@ const transformSwaggerRequestItem = (request, usedNames = new Set(), options = {
|
||||
requestBodySchema,
|
||||
requestBodyContentType
|
||||
}));
|
||||
} else if (response.description) {
|
||||
// description only (e.g., 204 No Content) — create example without body
|
||||
examples.push(createBrunoExample({
|
||||
brunoRequestItem,
|
||||
exampleValue: '',
|
||||
exampleName: `${statusCode} Response`,
|
||||
exampleDescription: response.description,
|
||||
statusCode,
|
||||
contentType: null,
|
||||
requestBodySchema,
|
||||
requestBodyContentType
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ describe('swagger2-to-bruno response examples', () => {
|
||||
expect(req.examples[0].response.status).toBe(200);
|
||||
});
|
||||
|
||||
it('should not generate examples when responses have no schema or examples', () => {
|
||||
it('should generate examples from description only responses', () => {
|
||||
const spec = {
|
||||
swagger: '2.0',
|
||||
info: { title: 'No Schema API', version: '1.0' },
|
||||
@@ -229,8 +229,20 @@ describe('swagger2-to-bruno response examples', () => {
|
||||
const collection = swagger2ToBruno(spec);
|
||||
const req = collection.items.find((i) => i.name === 'Delete data');
|
||||
|
||||
// No schema or examples → no examples array
|
||||
expect(req.examples).toBeUndefined();
|
||||
expect(req.examples).toBeDefined();
|
||||
expect(req.examples.length).toBe(2);
|
||||
|
||||
const noContentExample = req.examples.find((e) => e.response.status === 204);
|
||||
expect(noContentExample).toBeDefined();
|
||||
expect(noContentExample.name).toBe('204 Response');
|
||||
expect(noContentExample.description).toBe('No Content');
|
||||
expect(noContentExample.response.body.content).toBe('');
|
||||
expect(noContentExample.response.headers).toEqual([]);
|
||||
|
||||
const notFoundExample = req.examples.find((e) => e.response.status === 404);
|
||||
expect(notFoundExample).toBeDefined();
|
||||
expect(notFoundExample.name).toBe('404 Response');
|
||||
expect(notFoundExample.description).toBe('Not Found');
|
||||
});
|
||||
|
||||
it('should set correct statusText in response examples', () => {
|
||||
|
||||
Reference in New Issue
Block a user