mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
fix: storing status in example for yml file (#6876)
* fix: storing status in example for yml file * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: test cases for status and statusText * chore: removed logs * fix: test cases for response status and text * fix: test cases for response status and text * fix: resolved comments * fix: openapi test import test cases * chore: removed console logs * fix: status type in response example while import/export of collection * fix: postman to bruno import --------- Co-authored-by: shubh-bruno <shubh-bruno@shubh-bruno.local>
This commit is contained in:
41
packages/bruno-common/src/example-status/index.ts
Normal file
41
packages/bruno-common/src/example-status/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import each from 'lodash/each';
|
||||
import get from 'lodash/get';
|
||||
|
||||
interface Collection {
|
||||
items?: any[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward compatibility: Convert string status to number in examples
|
||||
* Old collections exported before the fix had status as string
|
||||
* This function ensures status is always a number for schema validation
|
||||
*/
|
||||
export const transformExampleStatusInCollection = (collection: Collection | Collection[]): Collection => {
|
||||
const transformItems = (items: any[] = []) => {
|
||||
each(items, (item) => {
|
||||
const examples = item.examples;
|
||||
if (examples && Array.isArray(examples)) {
|
||||
each(examples, (example) => {
|
||||
if (example.response && typeof example.response.status === 'string') {
|
||||
const statusValue = example.response.status;
|
||||
// Convert string status to number, default to null if conversion fails
|
||||
example.response.status = statusValue ? Number(statusValue) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (item.items && item.items.length) {
|
||||
transformItems(item.items);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (Array.isArray(collection)) {
|
||||
collection.forEach((col) => transformItems(col.items));
|
||||
} else {
|
||||
transformItems(collection.items);
|
||||
}
|
||||
|
||||
return collection;
|
||||
};
|
||||
Reference in New Issue
Block a user