Support x-enable-proxy at operation level (#4080)

This commit is contained in:
Nolann B.
2026-03-05 10:05:17 +01:00
committed by GitHub
parent 56ce5dfd74
commit 8ab419a47e
4 changed files with 80 additions and 1 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"@gitbook/openapi-parser": patch
"@gitbook/react-openapi": patch
---
Support x-enable-proxy at operation level
+6
View File
@@ -69,6 +69,12 @@ export interface OpenAPICustomOperationProperties {
};
};
/**
* If `true`, the Scalar API client will proxy requests through the server
* to avoid CORS issues.
*/
'x-enable-proxy'?: boolean;
/**
* Stability of the operation.
* @enum 'experimental' | 'alpha' | 'beta'
@@ -243,7 +243,7 @@ function OpenAPICodeSampleFooter(props: {
{!hideTryItPanel && hasValidHost && (
<ScalarApiButton
context={getOpenAPIClientContext(context)}
withProxy={Boolean(data['x-enable-proxy'])}
withProxy={Boolean(data.operation['x-enable-proxy'] ?? data['x-enable-proxy'])}
method={method}
path={path}
securities={securities}
@@ -259,6 +259,73 @@ describe('#resolveOpenAPIOperation', () => {
expect(resolved?.['x-enable-proxy']).toBeUndefined();
});
it('should be available at the operation level', async () => {
const filesystem = await loadFixture({
openapi: '3.1.0',
info: { title: 'Test', version: '1.0' },
paths: {
'/test': {
get: {
'x-enable-proxy': true,
responses: { '200': { description: 'OK' } },
},
},
},
});
const resolved = await resolveOpenAPIOperation(filesystem, {
method: 'get',
path: '/test',
});
expect(resolved?.operation['x-enable-proxy']).toBe(true);
});
it('should allow operation-level to override spec-level', async () => {
const filesystem = await loadFixture({
openapi: '3.1.0',
info: { title: 'Test', version: '1.0' },
'x-enable-proxy': true,
paths: {
'/test': {
get: {
'x-enable-proxy': false,
responses: { '200': { description: 'OK' } },
},
},
},
});
const resolved = await resolveOpenAPIOperation(filesystem, {
method: 'get',
path: '/test',
});
expect(resolved?.['x-enable-proxy']).toBe(true);
expect(resolved?.operation['x-enable-proxy']).toBe(false);
});
it('should allow operation-level true to override spec-level false', async () => {
const filesystem = await loadFixture({
openapi: '3.1.0',
info: { title: 'Test', version: '1.0' },
'x-enable-proxy': false,
paths: {
'/test': {
get: {
'x-enable-proxy': true,
responses: { '200': { description: 'OK' } },
},
},
},
});
const resolved = await resolveOpenAPIOperation(filesystem, {
method: 'get',
path: '/test',
});
expect(resolved?.['x-enable-proxy']).toBe(false);
expect(resolved?.operation['x-enable-proxy']).toBe(true);
});
});
describe('server precedence', () => {