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:
shubh-bruno
2026-02-26 17:33:02 +05:30
committed by GitHub
parent 8ce38e8480
commit 234d0df449
22 changed files with 139 additions and 64 deletions

View 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;
};