mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Improve OpenAPI Securities sample and headers (#2816)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Better securities sample and headers
|
||||||
@@ -136,34 +136,28 @@ function getSecurityHeaders(securities: OpenAPIOperationData['securities']): {
|
|||||||
switch (security[1].type) {
|
switch (security[1].type) {
|
||||||
case 'http': {
|
case 'http': {
|
||||||
let scheme = security[1].scheme;
|
let scheme = security[1].scheme;
|
||||||
if (scheme === 'bearer') {
|
let format = security[1].bearerFormat ?? 'YOUR_SECRET_TOKEN';
|
||||||
|
|
||||||
|
if (scheme?.includes('bearer')) {
|
||||||
scheme = 'Bearer';
|
scheme = 'Bearer';
|
||||||
|
} else if (scheme?.includes('basic')) {
|
||||||
|
scheme = 'Basic';
|
||||||
|
format = 'username:password';
|
||||||
|
} else if (scheme?.includes('token')) {
|
||||||
|
scheme = 'Token';
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Authorization: scheme + ' ' + (security[1].bearerFormat ?? '<token>'),
|
Authorization: scheme + ' ' + format,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'apiKey': {
|
case 'apiKey': {
|
||||||
if (security[1].in !== 'header') return {};
|
if (security[1].in !== 'header') return {};
|
||||||
|
|
||||||
const name = security[1].name ?? 'Authorization';
|
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 {
|
return {
|
||||||
[name]: scheme + ' ' + '<apiKey>',
|
[name]: 'YOUR_API_KEY',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
@@ -53,10 +53,16 @@ export function OpenAPISecurities(props: {
|
|||||||
function getLabelForType(security: OpenAPIV3_1.SecuritySchemeObject) {
|
function getLabelForType(security: OpenAPIV3_1.SecuritySchemeObject) {
|
||||||
switch (security.type) {
|
switch (security.type) {
|
||||||
case 'apiKey':
|
case 'apiKey':
|
||||||
return <OpenAPISchemaName propertyName="apiKey" type="string" required />;
|
return (
|
||||||
|
<OpenAPISchemaName
|
||||||
|
propertyName={security.name ?? 'apiKey'}
|
||||||
|
type="string"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
);
|
||||||
case 'http':
|
case 'http':
|
||||||
if (security.scheme === 'basic') {
|
if (security.scheme === 'basic') {
|
||||||
return 'Basic Auth';
|
return <OpenAPISchemaName propertyName="Authorization" type="string" required />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (security.scheme == 'bearer') {
|
if (security.scheme == 'bearer') {
|
||||||
|
|||||||
Reference in New Issue
Block a user