mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
feat: support newer Postman export format with collection envelope (#8038)
- Updated the Postman collection importer to handle collections wrapped in a { collection: { ... } } format.
- Enhanced the parsing logic to extract collection info correctly from both legacy and newer formats.
- Added a new test case for importing a Postman v2.1 collection with the wrapped format to ensure compatibility.
This commit is contained in:
@@ -23,7 +23,8 @@ const postmanToBruno = (collection) => {
|
||||
};
|
||||
|
||||
const isPostmanCollection = (data) => {
|
||||
const info = data.info;
|
||||
// Newer Postman exports wrap the collection in a { collection: { ... } } envelope
|
||||
const info = data.info || data?.collection?.info;
|
||||
if (!info || typeof info !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -950,7 +950,10 @@ const importPostmanV2Collection = async (collection, { useWorkers = false }) =>
|
||||
|
||||
const parsePostmanCollection = async (collection, { useWorkers = false }) => {
|
||||
try {
|
||||
let schema = get(collection, 'info.schema');
|
||||
// Newer Postman exports wrap the collection in a { collection: { ... } } envelope
|
||||
const parsedCollection = collection.collection?.info ? collection.collection : collection;
|
||||
|
||||
let schema = get(parsedCollection, 'info.schema');
|
||||
|
||||
let v2Schemas = [
|
||||
'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
|
||||
@@ -960,7 +963,7 @@ const parsePostmanCollection = async (collection, { useWorkers = false }) => {
|
||||
];
|
||||
|
||||
if (v2Schemas.includes(schema)) {
|
||||
return await importPostmanV2Collection(collection, { useWorkers });
|
||||
return await importPostmanV2Collection(parsedCollection, { useWorkers });
|
||||
}
|
||||
|
||||
throw new Error('Unsupported Postman schema version. Only Postman Collection v2.0 and v2.1 are supported.');
|
||||
|
||||
@@ -1120,6 +1120,15 @@ describe('postman-collection', () => {
|
||||
expect(headers[1].value).toBe('example.com');
|
||||
});
|
||||
|
||||
it('should unwrap and import a Postman collection with { collection: { ... } } envelope', async () => {
|
||||
const wrappedCollection = {
|
||||
collection: { ...postmanCollection }
|
||||
};
|
||||
|
||||
const brunoCollection = await postmanToBruno(wrappedCollection);
|
||||
expect(brunoCollection).toMatchObject(expectedOutput);
|
||||
});
|
||||
|
||||
it('should handle string headers with no value', async () => {
|
||||
const collectionWithNoValueHeader = {
|
||||
info: {
|
||||
|
||||
Reference in New Issue
Block a user