diff --git a/packages/bruno-converters/src/openapi/openapi-to-bruno.js b/packages/bruno-converters/src/openapi/openapi-to-bruno.js index 0d177af30..7d1cf3b11 100644 --- a/packages/bruno-converters/src/openapi/openapi-to-bruno.js +++ b/packages/bruno-converters/src/openapi/openapi-to-bruno.js @@ -57,7 +57,7 @@ const transformOpenapiRequestItem = (request) => { url: ensureUrl(request.global.server + path), method: request.method.toUpperCase(), auth: { - mode: 'none', + mode: 'inherit', basic: null, bearer: null, digest: null @@ -419,6 +419,19 @@ export const parseOpenApiCollection = (data) => { uid: uuid(), name: group.name, type: 'folder', + root: { + request: { + auth: { + mode: 'inherit', + basic: null, + bearer: null, + digest: null + } + }, + meta: { + name: group.name + } + }, items: group.requests.map(transformOpenapiRequestItem) }; }); diff --git a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-circular-references.spec.js b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-circular-references.spec.js index eedf52567..debaedc72 100644 --- a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-circular-references.spec.js +++ b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-circular-references.spec.js @@ -233,7 +233,7 @@ const circularRefsOutput = { "url": "{{baseUrl}}/", "method": "POST", "auth": { - "mode": "none", + "mode": "inherit", }, "headers": [], "params": [], diff --git a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js index 6cffe78f6..91ff66460 100644 --- a/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js +++ b/packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-to-bruno.spec.js @@ -8,6 +8,13 @@ describe('openapi-collection', () => { expect(brunoCollection).toMatchObject(expectedOutput); }); + it('should set auth mode to inherit when no security is defined in the collection', () => { + const brunoCollection = openApiToBruno(openApiCollectionString); + + // The openApiCollectionString has no security defined, so auth mode should be 'inherit' + expect(brunoCollection.items[0].items[0].request.auth.mode).toBe('inherit'); + }); + it('trims whitespace from info.title and uses the trimmed value as the collection name', () => { const openApiWithTitle = ` openapi: '3.0.0' @@ -109,6 +116,124 @@ servers: expect(result.name).toBe('Untitled Collection'); }); + describe('authentication inheritance', () => { + it('should set auth mode to inherit when no security is defined', () => { + const openApiWithoutSecurity = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API without security' +paths: + /test: + get: + summary: 'Test endpoint' + operationId: 'testEndpoint' + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithoutSecurity); + expect(result.items[0].request.auth.mode).toBe('inherit'); + }); + + it('should set auth mode to inherit when no global security schemes exist', () => { + const openApiWithEmptySecurity = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API with empty security' +security: [] +paths: + /test: + get: + summary: 'Test endpoint' + operationId: 'testEndpoint' + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithEmptySecurity); + expect(result.items[0].request.auth.mode).toBe('inherit'); + }); + + it('should set auth mode to inherit when components.securitySchemes is empty', () => { + const openApiWithEmptyComponents = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API with empty components' +components: + securitySchemes: {} +paths: + /test: + get: + summary: 'Test endpoint' + operationId: 'testEndpoint' + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithEmptyComponents); + expect(result.items[0].request.auth.mode).toBe('inherit'); + }); + + it('should set auth mode to inherit when operation has empty security array', () => { + const openApiWithEmptyOperationSecurity = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API with empty operation security' +components: + securitySchemes: + basicAuth: + type: http + scheme: basic +paths: + /test: + get: + summary: 'Test endpoint' + operationId: 'testEndpoint' + security: [] + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithEmptyOperationSecurity); + expect(result.items[0].request.auth.mode).toBe('inherit'); + }); + + it('should set auth mode to inherit for folder root when no security is defined', () => { + const openApiWithTags = ` +openapi: '3.0.0' +info: + version: '1.0.0' + title: 'API with tags' +paths: + /test: + get: + tags: + - TestGroup + summary: 'Test endpoint' + operationId: 'testEndpoint' + responses: + '200': + description: 'OK' +servers: + - url: 'https://example.com' +`; + const result = openApiToBruno(openApiWithTags); + expect(result.items[0].type).toBe('folder'); + expect(result.items[0].root.request.auth.mode).toBe('inherit'); + }); + }); }); const openApiCollectionString = ` @@ -174,7 +299,7 @@ const expectedOutput = { "basic": null, "bearer": null, "digest": null, - "mode": "none", + "mode": "inherit", }, "body": { "formUrlEncoded": [],