Skip to content

[UI] Add support for apiKey in query and cookie param #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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 }),
],
}),
Expand Down Expand Up @@ -142,7 +151,6 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
return "";
}
};

const formatTabLabel = (key: string, type: string, scheme: string) => {
const formattedLabel = key
.replace(/(_|-)/g, " ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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,
Expand Down