Skip to content
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

chore(cli): @fern-api/openapi-ir-parser conditionally imports swagger2openapi #5344

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
@@ -1,10 +1,11 @@
import { OpenApiIntermediateRepresentation, Source } from "@fern-api/openapi-ir";
import { TaskContext } from "@fern-api/task-context";
import { OpenAPIV2 } from "openapi-types";
import { convertObj } from "swagger2openapi";
import { ParseOpenAPIOptions } from "../../options";
import { generateIr as generateIrFromV3 } from "../v3/generateIr";

const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";

export async function generateIr({
openApi,
taskContext,
Expand All @@ -18,7 +19,11 @@ export async function generateIr({
source: Source;
namespace: string | undefined;
}): Promise<OpenApiIntermediateRepresentation> {
const conversionResult = await convertObj(openApi, {});
if (isBrowser) {
throw new Error("Swagger 2.0 is not supported in the browser");
}
const swagger2openapi = await import("swagger2openapi");
const conversionResult = await swagger2openapi.convertObj(openApi, {});
return generateIrFromV3({
openApi: conversionResult.openapi,
taskContext,
Expand Down
Loading