diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/createAuthentication.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/createAuthentication.ts index e49c36e89..fe075200c 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/createAuthentication.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/createAuthentication.ts @@ -13,8 +13,15 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) { if (!securitySchemes || !Object.keys(securitySchemes).length) return ""; const createAuthenticationTable = (securityScheme: any) => { - const { bearerFormat, flows, name, scheme, type, openIdConnectUrl } = - securityScheme; + const { + bearerFormat, + flows, + name, + scheme, + type, + openIdConnectUrl, + in: paramIn, + } = securityScheme; const createSecuritySchemeTypeRow = () => create("tr", { @@ -70,7 +77,9 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) { createSecuritySchemeTypeRow(), create("tr", { children: [ - create("th", { children: "Header parameter name:" }), + create("th", { + children: `${paramIn.charAt(0).toUpperCase() + paramIn.slice(1)} parameter name:`, + }), create("td", { children: name }), ], }), @@ -142,7 +151,6 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) { return ""; } }; - const formatTabLabel = (key: string, type: string, scheme: string) => { const formattedLabel = key .replace(/(_|-)/g, " ") diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts index fe077a2f2..53af07e36 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts +++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts @@ -430,10 +430,9 @@ function buildPostmanRequest( clonedPostman.url.host = [url]; } - setQueryParams(clonedPostman, queryParams); - setPathParams(clonedPostman, pathParams); + const enhancedQueryParams = [...queryParams]; + const enhancedCookieParams = [...cookieParams]; - const cookie = buildCookie(cookieParams); let otherHeaders = []; let selectedAuth: Scheme[] = []; @@ -491,24 +490,46 @@ function buildPostmanRequest( continue; } - // API Key + // API Key in header if (a.type === "apiKey" && a.in === "header") { const { apiKey } = auth.data[a.key]; - if (apiKey === undefined) { - otherHeaders.push({ - key: a.name, - value: `<${a.name ?? a.type}>`, - }); - continue; - } otherHeaders.push({ key: a.name, - value: apiKey, + value: apiKey || `<${a.name ?? a.type}>`, + }); + continue; + } + + // API Key in query + if (a.type === "apiKey" && a.in === "query") { + const { apiKey } = auth.data[a.key]; + enhancedQueryParams.push({ + name: a.name, + in: "query", + value: apiKey || `<${a.name ?? a.type}>`, + }); + continue; + } + + // API Key in cookie + if (a.type === "apiKey" && a.in === "cookie") { + const { apiKey } = auth.data[a.key]; + enhancedCookieParams.push({ + name: a.name, + in: "cookie", + value: apiKey || `<${a.name ?? a.type}>`, }); continue; } } + // Use the enhanced params that might include API keys + setQueryParams(clonedPostman, enhancedQueryParams); + setPathParams(clonedPostman, pathParams); + + // Use enhanced cookie params that might include API keys + const cookie = buildCookie(enhancedCookieParams); + setHeaders( clonedPostman, contentType,