mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Support x-enable-proxy at operation level (#4080)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/openapi-parser": patch
|
||||||
|
"@gitbook/react-openapi": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support x-enable-proxy at operation level
|
||||||
@@ -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.
|
* Stability of the operation.
|
||||||
* @enum 'experimental' | 'alpha' | 'beta'
|
* @enum 'experimental' | 'alpha' | 'beta'
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ function OpenAPICodeSampleFooter(props: {
|
|||||||
{!hideTryItPanel && hasValidHost && (
|
{!hideTryItPanel && hasValidHost && (
|
||||||
<ScalarApiButton
|
<ScalarApiButton
|
||||||
context={getOpenAPIClientContext(context)}
|
context={getOpenAPIClientContext(context)}
|
||||||
withProxy={Boolean(data['x-enable-proxy'])}
|
withProxy={Boolean(data.operation['x-enable-proxy'] ?? data['x-enable-proxy'])}
|
||||||
method={method}
|
method={method}
|
||||||
path={path}
|
path={path}
|
||||||
securities={securities}
|
securities={securities}
|
||||||
|
|||||||
@@ -259,6 +259,73 @@ describe('#resolveOpenAPIOperation', () => {
|
|||||||
|
|
||||||
expect(resolved?.['x-enable-proxy']).toBeUndefined();
|
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', () => {
|
describe('server precedence', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user