Skip to content

Commit

Permalink
fix(cli): Move swagger2openapi to workspace loader (#5347)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Dec 5, 2024
1 parent 4673aec commit f2e3288
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 8,254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
"@redocly/openapi-core": "^1.4.1",
"lodash-es": "^4.17.21",
"openapi-types": "^12.1.3",
"swagger2openapi": "7.0.8",
"zod": "^3.22.3"
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/swagger2openapi": "^7.0.4",
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"organize-imports-cli": "^0.10.0",
Expand Down

This file was deleted.

42 changes: 10 additions & 32 deletions packages/cli/api-importers/openapi/openapi-ir-parser/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { assertNever } from "@fern-api/core-utils";
import { OpenApiIntermediateRepresentation, Schemas, Source as OpenApiIrSource } from "@fern-api/openapi-ir";
import { TaskContext } from "@fern-api/task-context";
import { OpenAPI, OpenAPIV2, OpenAPIV3 } from "openapi-types";
import { OpenAPIV3 } from "openapi-types";
import { DEFAULT_PARSE_ASYNCAPI_SETTINGS, ParseAsyncAPIOptions } from "./asyncapi/options";
import { parseAsyncAPI } from "./asyncapi/parse";
import { AsyncAPIV2 } from "./asyncapi/v2";
import { generateIr as generateIrFromV2 } from "./openapi/v2/generateIr";
import { generateIr as generateIrFromV3 } from "./openapi/v3/generateIr";
import { getParseOptions, ParseOpenAPIOptions } from "./options";

export type Document = OpenAPIDocument | AsyncAPIDocument;

export interface OpenAPIDocument {
type: "openapi";
value: OpenAPI.Document;
value: OpenAPIV3.Document;
source?: OpenApiIrSource;
namespace?: string;
settings?: ParseOpenAPIOptions;
Expand Down Expand Up @@ -65,25 +64,14 @@ export async function parse({
const source = document.source != null ? document.source : OpenApiIrSource.openapi({ file: "<memory>" });
switch (document.type) {
case "openapi": {
if (isOpenApiV3(document.value)) {
const openapiIr = generateIrFromV3({
taskContext: context,
openApi: document.value,
options: getParseOptions({ options: document.settings, overrides: options }),
source,
namespace: document.namespace
});
ir = merge(ir, openapiIr);
} else if (isOpenApiV2(document.value)) {
const openapiIr = await generateIrFromV2({
taskContext: context,
openApi: document.value,
options: getParseOptions({ options: document.settings, overrides: options }),
source,
namespace: document.namespace
});
ir = merge(ir, openapiIr);
}
const openapiIr = generateIrFromV3({
taskContext: context,
openApi: document.value,
options: getParseOptions({ options: document.settings, overrides: options }),
source,
namespace: document.namespace
});
ir = merge(ir, openapiIr);
break;
}
case "asyncapi": {
Expand Down Expand Up @@ -184,13 +172,3 @@ function mergeSchemaMaps(schemas1: Schemas, schemas2: Schemas): Schemas {

return schemas1;
}

function isOpenApiV3(openApi: OpenAPI.Document): openApi is OpenAPIV3.Document {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return (openApi as OpenAPIV3.Document).openapi != null;
}

function isOpenApiV2(openApi: OpenAPI.Document): openApi is OpenAPIV2.Document {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return (openApi as OpenAPIV2.Document).swagger != null;
}
Loading

0 comments on commit f2e3288

Please sign in to comment.