fix: openapi spec export crash on websocket request (#8132)

* fix: only accept http and graphql for openapi spec

* chore: add test

Co-authored-by: Prateek Sunal <41370460+prateekmedia@users.noreply.github.com>

---------

Co-authored-by: Prateek Sunal <41370460+prateekmedia@users.noreply.github.com>
This commit is contained in:
prateek-bruno
2026-06-03 16:54:25 +05:30
committed by GitHub
parent 462a39308d
commit 026dbfb108
2 changed files with 89 additions and 2 deletions

View File

@@ -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: {},

View File

@@ -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();
});
});