Skip to content

Commit da84310

Browse files
committed
remove x-gitbook-token-placeholder for http
1 parent 8747382 commit da84310

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/react-openapi/src/util/tryit-prefill.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ describe('resolvePrefillCodePlaceholderFromSecurityScheme (integration style)',
419419
it('should prioritize x-gitbook-prefill over x-gitbook-token-placeholder when both are present', () => {
420420
const result = resolvePrefillCodePlaceholderFromSecurityScheme({
421421
security: {
422-
type: 'http',
423-
scheme: 'bearer',
422+
type: 'apiKey',
423+
in: 'header',
424424
'x-gitbook-prefill': '{{ visitor.claims.apiToken }}',
425425
'x-gitbook-token-placeholder': 'API_TOKEN_KEY',
426426
},
@@ -441,6 +441,19 @@ describe('resolvePrefillCodePlaceholderFromSecurityScheme (integration style)',
441441

442442
expect(result).toBe('YOUR_API_KEY_HERE');
443443
});
444+
445+
it('should not use x-gitbook-token-placeholder for http scheme', () => {
446+
const result = resolvePrefillCodePlaceholderFromSecurityScheme({
447+
security: {
448+
type: 'http',
449+
scheme: 'bearer',
450+
'x-gitbook-token-placeholder': 'YOUR_API_KEY_HERE',
451+
},
452+
defaultPlaceholderValue: 'YOUR_API_TOKEN',
453+
});
454+
455+
expect(result).toBe('YOUR_API_TOKEN');
456+
});
444457
});
445458

446459
describe('resolveURLWithPrefillCodePlaceholdersFromServer', () => {

packages/react-openapi/src/util/tryit-prefill.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ export function resolvePrefillCodePlaceholderFromSecurityScheme(args: {
178178

179179
if (prefillExprParts.length === 0) {
180180
// If no x-gitbook-prefill, check for x-gitbook-token-placeholder
181-
if (security['x-gitbook-token-placeholder']) {
181+
// We also disable it for http schemes to avoid confusion with the Authorization header.
182+
if (security.type !== 'http' && security['x-gitbook-token-placeholder']) {
182183
return security['x-gitbook-token-placeholder'];
183184
}
184185
return defaultPlaceholderValue ?? '';

0 commit comments

Comments
 (0)