Skip to content

Commit 873363a

Browse files
committed
fix(parseOpenApi3Documentation): append the header only if it's not already present
Signed-off-by: J3m5 <[email protected]>
1 parent 60aa614 commit 873363a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/openapi3/parseOpenApi3Documentation.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ export default function parseOpenApi3Documentation(
1616
options: RequestInitExtended = {},
1717
): Promise<ParsedOpenApi3Documentation> {
1818
entrypointUrl = removeTrailingSlash(entrypointUrl);
19-
let headers: HeadersInit | undefined =
19+
const headersObject =
2020
typeof options.headers === "function" ? options.headers() : options.headers;
21-
headers = new Headers(headers);
22-
headers.append("Accept", "application/vnd.openapi+json");
21+
const headers = new Headers(headersObject);
22+
if (!headers.get("Accept")?.includes("application/vnd.openapi+json")) {
23+
headers.append("Accept", "application/vnd.openapi+json");
24+
}
2325

2426
return fetch(entrypointUrl, { ...options, headers: headers })
2527
.then((res) => Promise.all([res, res.json()]))

0 commit comments

Comments
 (0)