Skip to content

Commit

Permalink
Include apiKey example in CodeSample security headers (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolannbiron authored Feb 4, 2025
1 parent fe8acc9 commit d9029c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-vans-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---

Support apiKey in CodeSample security headers
22 changes: 22 additions & 0 deletions packages/react-openapi/src/OpenAPICodeSample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ function getSecurityHeaders(securities: OpenAPIOperationData['securities']): {
Authorization: scheme + ' ' + (security[1].bearerFormat ?? '<token>'),
};
}
case 'apiKey': {
if (security[1].in !== 'header') return {};

const name = security[1].name ?? 'Authorization';
let scheme = security[0];

switch (scheme) {
case 'bearerAuth':
scheme = 'Bearer';
break;
case 'token':
scheme = 'Token';
break;
case 'basic':
scheme = 'Basic';
break;
}

return {
[name]: scheme + ' ' + '<apiKey>',
};
}
default: {
return {};
}
Expand Down

0 comments on commit d9029c7

Please sign in to comment.