Skip to content

Commit

Permalink
Add case-insensitive security scheme support
Browse files Browse the repository at this point in the history
  • Loading branch information
bourdakos1 committed Dec 11, 2021
1 parent 87bf19e commit 75d36c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demo/examples/openapi-cos.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
},
"components": {
"securitySchemes": {
"BearerAuth": { "type": "http", "scheme": "bearer" },
"BearerAuth": { "type": "http", "scheme": "BeAreR" },
"BasicAuth": { "type": "http", "scheme": "basic" }
},
"schemas": {
Expand Down
22 changes: 22 additions & 0 deletions packages/docusaurus-plugin-openapi/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,23 @@ import {
ApiItem,
RequestBodyObject,
SchemaObject,
HttpSecuritySchemeObject,
ApiKeySecuritySchemeObject,
Oauth2SecuritySchemeObject,
OpenIdConnectSecuritySchemeObject,
} from "./types";

function isHttpSecuritySchemeObject(
item:
| ReferenceObject
| ApiKeySecuritySchemeObject
| HttpSecuritySchemeObject
| Oauth2SecuritySchemeObject
| OpenIdConnectSecuritySchemeObject
): item is HttpSecuritySchemeObject {
return (item as HttpSecuritySchemeObject).type === "http";
}

function isOperationObject(
item:
| string
Expand Down Expand Up @@ -234,6 +249,13 @@ export async function loadOpenapi(
// Add security schemes so we know how to handle security.
item.securitySchemes = dereffedSpec.components?.securitySchemes;

// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
Object.values(item.securitySchemes ?? {}).forEach((auth) => {
if (isHttpSecuritySchemeObject(auth)) {
auth.scheme = auth.scheme.toLowerCase();
}
});

item.permalink = normalizeUrl([baseUrl, routeBasePath, item.id]);

const prev =
Expand Down

0 comments on commit 75d36c5

Please sign in to comment.