Skip to content

Commit

Permalink
hygeine
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Nov 25, 2024
1 parent ec1b9df commit bba54cb
Show file tree
Hide file tree
Showing 35 changed files with 142 additions and 94 deletions.
6 changes: 3 additions & 3 deletions packages/parsers/src/BaseApiConverter.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ErrorCollector } from "./ErrorCollector";
* Base context class for API converter nodes.
* Provides logging and error collection capabilities.
*/
export abstract class BaseAPIConverterNodeContext {
export abstract class BaseApiConverterNodeContext {
public abstract readonly logger: Logger;
public readonly errors: ErrorCollector = new ErrorCollector();
}
Expand All @@ -17,10 +17,10 @@ export abstract class BaseAPIConverterNodeContext {
* @typeparam Input - The type from the source format
* @typeparam Output - The type from the target format
*/
export abstract class BaseAPIConverterNode<Input, Output> {
export abstract class BaseApiConverterNode<Input, Output> {
constructor(
protected readonly input: Input,
protected readonly context: BaseAPIConverterNodeContext,
protected readonly context: BaseApiConverterNodeContext,
) {}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { v4 } from "uuid";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../BaseOpenApiV3_1Converter.node";
import { coalesceServers } from "../utils/3.1/coalesceServers";
import { PathsObjectConverterNode } from "./paths/PathsObjectConverter.node";
import { ServerObjectConverterNode } from "./paths/ServerObjectConverter.node";
import { ComponentsConverterNode } from "./schemas/ComponentsConverter.node";

export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1Node<
export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.Document,
FdrAPI.api.latest.ApiDefinition
> {
Expand All @@ -16,7 +19,7 @@ export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1Node<
components: ComponentsConverterNode | undefined;
servers: ServerObjectConverterNode[] | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.Document>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.Document>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { coalesceServers } from "../../utils/3.1/coalesceServers";
import { isReferenceObject } from "../guards/isReferenceObject";
import { convertProperties } from "../schemas/ObjectConverter.node";
import { SchemaConverterNode } from "../schemas/SchemaConverter.node";
import { ServerObjectConverterNode } from "./ServerObjectConverter.node";

export class OperationObjectConverterNode extends BaseOpenApiV3_1Node<
export class OperationObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.OperationObject,
FdrAPI.api.latest.EndpointDefinition
> {
Expand All @@ -19,7 +22,7 @@ export class OperationObjectConverterNode extends BaseOpenApiV3_1Node<
// availability: AvailabilityConverterNode | undefined;

constructor(
args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.OperationObject>,
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.OperationObject>,
protected servers: ServerObjectConverterNode[] | undefined,
protected path: string | undefined,
protected method: "GET" | "POST" | "PUT" | "DELETE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { coalesceServers } from "../../utils/3.1/coalesceServers";
import { OperationObjectConverterNode } from "./OperationObjectConverter.node";
import { ServerObjectConverterNode } from "./ServerObjectConverter.node";

export class PathItemObjectConverterNode extends BaseOpenApiV3_1Node<
export class PathItemObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.PathItemObject,
FdrAPI.api.latest.EndpointDefinition[]
> {
Expand All @@ -22,7 +25,7 @@ export class PathItemObjectConverterNode extends BaseOpenApiV3_1Node<
path: string | undefined;

constructor(
args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.PathItemObject>,
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.PathItemObject>,
protected servers: ServerObjectConverterNode[] | undefined,
) {
super(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { v4 } from "uuid";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { coalesceServers } from "../../utils/3.1/coalesceServers";
import { PathItemObjectConverterNode } from "./PathItemObjectConverter.node";
import { ServerObjectConverterNode } from "./ServerObjectConverter.node";

export class PathsObjectConverterNode extends BaseOpenApiV3_1Node<
export class PathsObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.PathsObject,
Record<FdrAPI.EndpointId, FdrAPI.api.latest.EndpointDefinition>
> {
paths: PathItemObjectConverterNode[] | undefined;

constructor(
args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.PathsObject>,
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.PathsObject>,
protected readonly servers: ServerObjectConverterNode[] | undefined,
) {
super(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";

export class ServerObjectConverterNode extends BaseOpenApiV3_1Node<
export class ServerObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.ServerObject,
FdrAPI.api.latest.Environment
> {
url: string | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.ServerObject>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.ServerObject>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { describe, expect, it } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { OperationObjectConverterNode } from "../../paths/OperationObjectConverter.node";
import { OperationObjectConverterNode } from "../OperationObjectConverter.node";

describe("OperationObjectConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OpenAPIV3_1 } from "openapi-types";
import { describe, expect, it } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { PathItemObjectConverterNode } from "../../paths/PathItemObjectConverter.node";
import { PathItemObjectConverterNode } from "../PathItemObjectConverter.node";

describe("PathItemObjectConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OpenAPIV3_1 } from "openapi-types";
import { describe, expect, it } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { PathsObjectConverterNode } from "../../paths/PathsObjectConverter.node";
import { PathsObjectConverterNode } from "../PathsObjectConverter.node";

describe("PathsObjectConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { describe, expect, it } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { ServerObjectConverterNode } from "../../paths/ServerObjectConverter.node";
import { ServerObjectConverterNode } from "../ServerObjectConverter.node";

describe("ServerObjectConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { SchemaConverterNode } from "./SchemaConverter.node";

export declare namespace ArrayConverterNode {
Expand All @@ -13,13 +16,13 @@ export declare namespace ArrayConverterNode {
}
}

export class ArrayConverterNode extends BaseOpenApiV3_1Node<
export class ArrayConverterNode extends BaseOpenApiV3_1ConverterNode<
ArrayConverterNode.Input,
ArrayConverterNode.Output | undefined
> {
item: SchemaConverterNode | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<ArrayConverterNode.Input>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<ArrayConverterNode.Input>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { SchemaConverterNode } from "./SchemaConverter.node";

export class ComponentsConverterNode extends BaseOpenApiV3_1Node<
export class ComponentsConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.ComponentsObject,
FdrAPI.api.latest.ApiDefinition["types"]
> {
typeSchemas: Record<string, SchemaConverterNode> | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.ComponentsObject>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.ComponentsObject>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { getSchemaIdFromReference } from "../../utils/3.1/getSchemaIdFromReference";
import { isReferenceObject } from "../guards/isReferenceObject";
import { SchemaConverterNode } from "./SchemaConverter.node";
Expand Down Expand Up @@ -36,7 +39,7 @@ export function convertProperties(
.filter(isNonNullish);
}

export class ObjectConverterNode extends BaseOpenApiV3_1Node<
export class ObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
ObjectConverterNode.Input,
FdrAPI.api.latest.TypeShape.Object_
> {
Expand All @@ -45,7 +48,7 @@ export class ObjectConverterNode extends BaseOpenApiV3_1Node<
properties: Record<string, SchemaConverterNode> | undefined;
extraProperties: string | SchemaConverterNode | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<ObjectConverterNode.Input>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<ObjectConverterNode.Input>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { isNonNullish } from "@fern-api/ui-core-utils";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { resolveSchemaReference } from "../../utils/3.1/resolveSchemaReference";
import { isReferenceObject } from "../guards/isReferenceObject";
import { SchemaConverterNode } from "./SchemaConverter.node";
Expand All @@ -12,7 +15,7 @@ export declare namespace OneOfConverterNode {
}
}

export class OneOfConverterNode extends BaseOpenApiV3_1Node<
export class OneOfConverterNode extends BaseOpenApiV3_1ConverterNode<
OneOfConverterNode.Input,
FdrAPI.api.latest.TypeShape.DiscriminatedUnion | FdrAPI.api.latest.TypeShape.UndiscriminatedUnion
> {
Expand All @@ -22,7 +25,7 @@ export class OneOfConverterNode extends BaseOpenApiV3_1Node<

undiscriminatedMapping: SchemaConverterNode[] | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OneOfConverterNode.Input>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OneOfConverterNode.Input>) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { getSchemaIdFromReference } from "../../utils/3.1/getSchemaIdFromReference";

export class ReferenceConverterNode extends BaseOpenApiV3_1Node<
export class ReferenceConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.ReferenceObject,
FdrAPI.api.latest.TypeShape.Alias
> {
schemaId: string | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.ReferenceObject>) {
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.ReferenceObject>) {
super(args);
this.safeParse();
}
Expand Down
13 changes: 9 additions & 4 deletions packages/parsers/src/openapi/3.1/schemas/SchemaConverter.node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { UnreachableCaseError } from "ts-essentials";
import { BaseOpenApiV3_1Node, BaseOpenApiV3_1NodeConstructorArgs } from "../../BaseOpenApiV3_1Converter.node";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
} from "../../BaseOpenApiV3_1Converter.node";
import { isArraySchema } from "../guards/isArraySchema";
import { isBooleanSchema } from "../guards/isBooleanSchema";
import { isIntegerSchema } from "../guards/isIntegerSchema";
Expand All @@ -27,16 +30,18 @@ export type PrimitiveType =
| BooleanConverterNode.Input
| StringConverterNode.Input;

export class SchemaConverterNode extends BaseOpenApiV3_1Node<
export class SchemaConverterNode extends BaseOpenApiV3_1ConverterNode<
OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject,
FdrAPI.api.latest.TypeShape | undefined
> {
typeShapeNode: BaseOpenApiV3_1Node<unknown, FdrAPI.api.latest.TypeShape | undefined> | undefined;
typeShapeNode: BaseOpenApiV3_1ConverterNode<unknown, FdrAPI.api.latest.TypeShape | undefined> | undefined;

description: string | undefined;
name: string | undefined;

constructor(args: BaseOpenApiV3_1NodeConstructorArgs<OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject>) {
constructor(
args: BaseOpenApiV3_1ConverterNodeConstructorArgs<OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject>,
) {
super(args);
this.safeParse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { OpenAPIV3_1 } from "openapi-types";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { ArrayConverterNode } from "../../schemas/ArrayConverter.node";
import { StringConverterNode } from "../../schemas/primitives/StringConverter.node";
import { ArrayConverterNode } from "../ArrayConverter.node";
import { StringConverterNode } from "../primitives/StringConverter.node";

describe("ArrayConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FdrAPI } from "@fern-api/fdr-sdk";
import { OpenAPIV3_1 } from "openapi-types";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { ComponentsConverterNode } from "../../schemas/ComponentsConverter.node";
import { ComponentsConverterNode } from "../ComponentsConverter.node";

describe("ComponentsConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { ObjectConverterNode } from "../../schemas/ObjectConverter.node";
import { SchemaConverterNode } from "../../schemas/SchemaConverter.node";
import { ObjectConverterNode } from "../ObjectConverter.node";
import { SchemaConverterNode } from "../SchemaConverter.node";

describe("ObjectConverterNode", () => {
const mockContext = createMockContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createMockContext } from "../../../../__test__/createMockContext.util";
import { OneOfConverterNode } from "../../schemas/OneOfConverter.node";
import { OneOfConverterNode } from "../OneOfConverter.node";

describe("OneOfConverterNode", () => {
const mockContext = createMockContext({
Expand Down
Loading

0 comments on commit bba54cb

Please sign in to comment.