diff --git a/packages/bruno-converters/src/postman/postman-to-bruno.js b/packages/bruno-converters/src/postman/postman-to-bruno.js index de5f05707..de86808ee 100644 --- a/packages/bruno-converters/src/postman/postman-to-bruno.js +++ b/packages/bruno-converters/src/postman/postman-to-bruno.js @@ -159,7 +159,7 @@ const importCollectionLevelVariables = (variables, requestObject) => { const vars = variables.filter((v) => !(v.key == null && v.value == null)).map((v) => ({ uid: uuid(), name: (v.key ?? '').replace(invalidVariableCharacterRegex, '_'), - value: v.value ?? '', + value: v.value == null ? '' : typeof v.value === 'string' ? v.value : JSON.stringify(v.value), enabled: true })); diff --git a/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js b/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js index d55a8115b..387fe47d9 100644 --- a/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js +++ b/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js @@ -238,6 +238,43 @@ describe('postman-collection', () => { ]); }); + it('should convert non-string variable values to strings', async () => { + const collectionWithNonStringVars = { + info: { + name: 'Non-String Variable Demo', + _postman_id: 'abcd1234-5678-90ef-ghij-1234567890ab', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + variable: [ + { key: 'timeout', value: 5000 }, + { key: 'enabled', value: true }, + { key: 'user', value: { id: 1, name: 'Alice' } } + ], + item: [ + { + name: 'Sample Request', + request: { + method: 'GET', + url: { + raw: 'https://postman-echo.com/get', + protocol: 'https', + host: ['postman-echo', 'com'], + path: ['get'] + } + } + } + ] + }; + + const brunoCollection = await postmanToBruno(collectionWithNonStringVars); + const vars = brunoCollection.root.request.vars.req; + + expect(vars).toHaveLength(3); + expect(vars[0]).toMatchObject({ name: 'timeout', value: '5000' }); + expect(vars[1]).toMatchObject({ name: 'enabled', value: 'true' }); + expect(vars[2]).toMatchObject({ name: 'user', value: '{"id":1,"name":"Alice"}' }); + }); + it('should handle empty variables', async () => { const collectionWithEmptyVars = { info: {