diff --git a/packages/cli/api-importers/openapi/openapi-ir-parser/src/openapi/v2/generateIr.ts b/packages/cli/api-importers/openapi/openapi-ir-parser/src/openapi/v2/generateIr.ts index c630dc4708b..71d3da556ab 100644 --- a/packages/cli/api-importers/openapi/openapi-ir-parser/src/openapi/v2/generateIr.ts +++ b/packages/cli/api-importers/openapi/openapi-ir-parser/src/openapi/v2/generateIr.ts @@ -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, @@ -18,7 +19,11 @@ export async function generateIr({ source: Source; namespace: string | undefined; }): Promise { - 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,