diff --git a/packages/bruno-app/src/utils/exporters/openapi-spec.js b/packages/bruno-app/src/utils/exporters/openapi-spec.js index d9ed25e0e..4613add40 100644 --- a/packages/bruno-app/src/utils/exporters/openapi-spec.js +++ b/packages/bruno-app/src/utils/exporters/openapi-spec.js @@ -4,8 +4,8 @@ import { isValidUrl } from 'utils/url/index'; const xml2js = require('xml2js'); export const exportApiSpec = ({ variables, items, name, environments }) => { - // Filter out transient items and grpc requests - items = items.filter((item) => !['grpc-request'].includes(item.type) && !item.isTransient); + // Filter only include http-request and graphql-request items that aren't transient + items = items.filter((item) => ['http-request', 'graphql-request'].includes(item.type) && !item.isTransient); const components = { schemas: {}, diff --git a/packages/bruno-app/src/utils/exporters/openapi-spec.spec.js b/packages/bruno-app/src/utils/exporters/openapi-spec.spec.js index 87f668e20..6cbb122d8 100644 --- a/packages/bruno-app/src/utils/exporters/openapi-spec.spec.js +++ b/packages/bruno-app/src/utils/exporters/openapi-spec.spec.js @@ -881,3 +881,90 @@ describe('exportApiSpec - OAuth2 scope handling (BRU-3297)', () => { }); }); }); + +describe('exportApiSpec - non-HTTP request type filtering', () => { + it('should keep only http-request and graphql-request items and not crash on others', () => { + const items = [ + { + name: 'HTTP Request', + type: 'http-request', + pathname: 'folder/http', + depth: 2, + request: { + url: 'https://api.example.com/http', + method: 'GET', + params: [], + headers: [], + body: {}, + auth: {} + }, + examples: [] + }, + { + name: 'GraphQL Request', + type: 'graphql-request', + pathname: 'folder/graphql', + depth: 2, + request: { + url: 'https://api.example.com/graphql', + method: 'POST', + params: [], + headers: [], + body: {}, + auth: {} + }, + examples: [] + }, + { + name: 'gRPC Request', + type: 'grpc-request', + request: { url: 'grpc://example.com/service' } + }, + { + name: 'WebSocket Request', + type: 'ws-request', + request: { url: 'wss://example.com/socket' } + }, + { + name: 'Folder', + type: 'folder', + items: [] + }, + { + name: 'script.js', + type: 'js' + }, + { + name: 'Transient', + type: 'http-request', + isTransient: true, + pathname: 'folder/transient', + depth: 2, + request: { + url: 'https://api.example.com/transient', + method: 'GET', + params: [], + headers: [], + body: {}, + auth: {} + }, + examples: [] + } + ]; + + let result; + expect(() => { + result = exportApiSpec({ variables: {}, items, name: 'Test API' }); + }).not.toThrow(); + + const spec = require('js-yaml').load(result.content); + const pathKeys = Object.keys(spec.paths); + + expect(pathKeys).toHaveLength(2); + expect(spec.paths['/http']).toBeDefined(); + expect(spec.paths['/http'].get).toBeDefined(); + expect(spec.paths['/graphql']).toBeDefined(); + expect(spec.paths['/graphql'].post).toBeDefined(); + expect(spec.paths['/transient']).toBeUndefined(); + }); +});