diff --git a/demo/examples/openapi-cos.json b/demo/examples/openapi-cos.json index ce5a01fb..c784b3a1 100644 --- a/demo/examples/openapi-cos.json +++ b/demo/examples/openapi-cos.json @@ -138,7 +138,7 @@ }, "components": { "securitySchemes": { - "BearerAuth": { "type": "http", "scheme": "bearer" }, + "BearerAuth": { "type": "http", "scheme": "BeAreR" }, "BasicAuth": { "type": "http", "scheme": "basic" } }, "schemas": { diff --git a/packages/docusaurus-plugin-openapi/src/openapi.ts b/packages/docusaurus-plugin-openapi/src/openapi.ts index a15d9b87..6462e787 100644 --- a/packages/docusaurus-plugin-openapi/src/openapi.ts +++ b/packages/docusaurus-plugin-openapi/src/openapi.ts @@ -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 @@ -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 =