Skip to content

Commit

Permalink
fix: accept vnd.openapi+json
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Mar 14, 2024
1 parent 63205e5 commit ccc6255
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/openapi3/parseOpenApi3Documentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Api } from "../Api.js";
import handleJson, { removeTrailingSlash } from "./handleJson.js";
import type { OpenAPIV3 } from "openapi-types";
import type { RequestInitExtended } from "./types";

export interface ParsedOpenApi3Documentation {
api: Api;
Expand All @@ -9,10 +10,16 @@ export interface ParsedOpenApi3Documentation {
}

export default function parseOpenApi3Documentation(
entrypointUrl: string
entrypointUrl: string,
options: RequestInitExtended = {}
): Promise<ParsedOpenApi3Documentation> {
entrypointUrl = removeTrailingSlash(entrypointUrl);
return fetch(entrypointUrl)
let headers: HeadersInit | undefined =
typeof options.headers === "function" ? options.headers() : options.headers;
headers = new Headers(headers);
headers.append("Accept", "application/vnd.openapi+json");

return fetch(entrypointUrl, { ...options, headers: headers })
.then((res) => Promise.all([res, res.json()]))
.then(
([res, response]: [res: Response, response: OpenAPIV3.Document]) => {
Expand Down
3 changes: 3 additions & 0 deletions src/openapi3/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface RequestInitExtended extends Omit<RequestInit, "headers"> {
headers?: HeadersInit | (() => HeadersInit);
}

0 comments on commit ccc6255

Please sign in to comment.