-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3913b36
commit cf42860
Showing
33 changed files
with
712 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Logger } from "@playwright/test"; | ||
|
||
export class ErrorCollector { | ||
errors: { | ||
message: string; | ||
path: string; | ||
}[] = []; | ||
|
||
addError(error: string, accessPath: string[], pathId?: string): void { | ||
this.errors.push({ | ||
message: error, | ||
path: `#/${accessPath.join("/")}${pathId ? `/${pathId}` : ""}`, | ||
}); | ||
} | ||
} | ||
|
||
export interface ApiNodeContext { | ||
orgId: string; | ||
apiId: string; | ||
logger: Logger; | ||
errorCollector: ErrorCollector; | ||
} | ||
|
||
abstract class ApiNode<InputShape, FdrShape> { | ||
context: ApiNodeContext; | ||
input: InputShape; | ||
|
||
accessPath: string[]; | ||
|
||
constructor(context: ApiNodeContext, input: InputShape, accessPath: string[]) { | ||
this.context = context; | ||
this.input = input; | ||
this.accessPath = accessPath; | ||
} | ||
|
||
abstract outputFdrShape: () => FdrShape | undefined; | ||
} | ||
|
||
export abstract class InputApiNode<InputShape, FdrShape> extends ApiNode<InputShape, FdrShape> { | ||
constructor(context: ApiNodeContext, input: InputShape, accessPath: string[], pathId?: string) { | ||
if (pathId) { | ||
accessPath.push(pathId); | ||
context.logger.log("a", "info", `Processing #/${accessPath.join("/")}/${pathId}`); | ||
} | ||
super(context, input, accessPath); | ||
} | ||
} | ||
|
||
export abstract class OutputApiNode<InputShape, FdrShape> extends ApiNode<InputShape, FdrShape> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
packages/parsers/openapi/shared/interfaces/api.node.interface.ts
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/parsers/openapi/shared/interfaces/container.node.interface.ts
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/parsers/openapi/shared/interfaces/fdr.stage.interface.ts
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/parsers/openapi/shared/interfaces/primitive.node.interface.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import { ApiNodeContext, OutputApiNode } from "../../base.node.interface"; | ||
import { SchemaObject } from "../openapi.types"; | ||
import { ObjectPropertyNode } from "./objectProperty.node"; | ||
import { TypeReferenceNode, isReferenceObject } from "./typeReference.node"; | ||
|
||
export class ObjectNode extends OutputApiNode<SchemaObject, FdrAPI.api.latest.ObjectType> { | ||
extends: FdrAPI.TypeId[] = []; | ||
properties: ObjectPropertyNode[] = []; | ||
extraProperties: TypeReferenceNode | undefined; | ||
|
||
constructor(context: ApiNodeContext, input: SchemaObject, accessPath: string[], accessorKey?: string) { | ||
super(context, input, accessPath); | ||
|
||
if (input.allOf !== undefined) { | ||
this.extends = input.allOf | ||
.map((type) => (isReferenceObject(type) ? FdrAPI.TypeId(type.$ref) : undefined)) | ||
.filter((id): id is FdrAPI.TypeId => id !== undefined); | ||
} | ||
|
||
if (input.properties !== undefined) { | ||
Object.entries(input.properties).forEach(([key, property]) => { | ||
this.properties.push(new ObjectPropertyNode(key, context, property, accessPath, accessorKey)); | ||
}); | ||
} | ||
} | ||
|
||
outputFdrShape = (): FdrAPI.api.latest.ObjectType | undefined => { | ||
const properties = this.properties | ||
.map((property) => property.outputFdrShape()) | ||
.filter((property): property is FdrAPI.api.latest.ObjectProperty => property !== undefined); | ||
|
||
return { | ||
extends: this.extends, | ||
properties, | ||
extraProperties: undefined, | ||
// TODO: add extraProperties | ||
}; | ||
}; | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/parsers/openapi/shared/nodes/objectProperty.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import { ApiNodeContext, OutputApiNode } from "../../base.node.interface"; | ||
import { ReferenceObject, SchemaObject } from "../openapi.types"; | ||
import { isReferenceObject, mapReferenceObject } from "./typeReference.node"; | ||
import { TypeShapeNode } from "./typeShape.node"; | ||
|
||
export class ObjectPropertyNode extends OutputApiNode< | ||
SchemaObject | ReferenceObject, | ||
FdrAPI.api.latest.ObjectProperty | ||
> { | ||
valueShape: TypeShapeNode; | ||
description: string | undefined; | ||
// availability: AvailabilityNode; | ||
|
||
constructor( | ||
private readonly key: string, | ||
context: ApiNodeContext, | ||
input: SchemaObject | ReferenceObject, | ||
accessPath: string[], | ||
accessorKey?: string, | ||
) { | ||
super(context, input, accessPath); | ||
|
||
if (isReferenceObject(input)) { | ||
input = mapReferenceObject(input); | ||
} | ||
|
||
this.valueShape = new TypeShapeNode(context, input, accessPath, accessorKey); | ||
this.description = input.description; | ||
// this.availability = input.availability; | ||
} | ||
|
||
outputFdrShape = (): FdrAPI.api.latest.ObjectProperty | undefined => { | ||
const valueShape = this.valueShape.outputFdrShape(); | ||
if (valueShape === undefined) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
key: FdrAPI.PropertyKey(this.key), | ||
valueShape, | ||
description: this.description, | ||
availability: undefined, | ||
// TODO: update to availability: this.availability.outputFdrShape(), | ||
}; | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
packages/parsers/openapi/shared/nodes/primitives/enum.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import { OpenAPIV3_1 } from "openapi-types"; | ||
import { ApiNodeContext, InputApiNode } from "../../../base.node.interface"; | ||
|
||
export class EnumNode extends InputApiNode<OpenAPIV3_1.SchemaObject, FdrAPI.api.v1.read.PrimitiveType.Enum> { | ||
default: number | undefined; | ||
format: string | undefined; | ||
minimum: number | undefined; | ||
maximum: number | undefined; | ||
|
||
constructor( | ||
context: ApiNodeContext, | ||
input: OpenAPIV3_1.NonArraySchemaObject, | ||
accessPath: string[], | ||
accessorKey?: string, | ||
) { | ||
super(context, input, accessPath, accessorKey); | ||
if (input.type !== "integer") { | ||
context.errorCollector.addError( | ||
`Expected type "integer" for primitive, but got "${input.type}"`, | ||
accessPath, | ||
accessorKey, | ||
); | ||
} | ||
this.format = input.format; | ||
this.default = input.default; | ||
this.minimum = input.minimum; | ||
this.maximum = input.maximum; | ||
} | ||
|
||
outputFdrShape = (): FdrAPI.api.v1.read.PrimitiveType.Integer => { | ||
return { | ||
type: "integer", | ||
minimum: this.minimum, | ||
maximum: this.maximum, | ||
default: this.default, | ||
}; | ||
}; | ||
} |
Oops, something went wrong.