-
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
bba54cb
commit d1e7336
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/parsers/src/openapi/3.1/extensions/availability-function.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,23 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import { UnreachableCaseError } from "ts-essentials"; | ||
|
||
type Availability = "beta" | "in-development" | "deprecated"; | ||
|
||
export function availabilityFunction<T>(input: T): FdrAPI.Availability | undefined { | ||
const inputWithAvailability = input as T & { | ||
"x-fern-availability"?: Availability; | ||
}; | ||
switch (inputWithAvailability["x-fern-availability"]) { | ||
case "beta": | ||
return FdrAPI.Availability.Beta; | ||
case "in-development": | ||
return FdrAPI.Availability.InDevelopment; | ||
case "deprecated": | ||
return FdrAPI.Availability.Deprecated; | ||
case undefined: | ||
return undefined; | ||
default: | ||
new UnreachableCaseError(inputWithAvailability["x-fern-availability"]); | ||
return undefined; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/parsers/src/openapi/3.1/extensions/availability-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,44 @@ | ||
import { FdrAPI } from "@fern-api/fdr-sdk"; | ||
import { UnreachableCaseError } from "ts-essentials"; | ||
import { | ||
BaseOpenApiV3_1ConverterNode, | ||
BaseOpenApiV3_1ConverterNodeConstructorArgs, | ||
} from "../../BaseOpenApiV3_1Converter.node"; | ||
|
||
type Availability = "beta" | "in-development" | "deprecated"; | ||
|
||
export class AvailabilityNode<T> extends BaseOpenApiV3_1ConverterNode<T, FdrAPI.Availability | undefined> { | ||
availability?: FdrAPI.Availability; | ||
|
||
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<T>) { | ||
super(args); | ||
this.safeParse(); | ||
} | ||
|
||
parse(): void { | ||
const inputWithAvailability = this.input as T & { | ||
"x-fern-availability"?: Availability; | ||
}; | ||
switch (inputWithAvailability["x-fern-availability"]) { | ||
case "beta": | ||
this.availability = FdrAPI.Availability.Beta; | ||
break; | ||
case "in-development": | ||
this.availability = FdrAPI.Availability.InDevelopment; | ||
break; | ||
case "deprecated": | ||
this.availability = FdrAPI.Availability.Deprecated; | ||
break; | ||
case undefined: | ||
this.availability = undefined; | ||
break; | ||
default: | ||
new UnreachableCaseError(inputWithAvailability["x-fern-availability"]); | ||
return undefined; | ||
} | ||
} | ||
|
||
convert(): FdrAPI.Availability | undefined { | ||
return this.availability; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/parsers/src/openapi/3.1/extensions/x-fern-group-name-function.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,4 @@ | ||
// This would be used to set a member on the node, that could be used upstream | ||
export function xFernGroupNameFunction(input: { "x-fern-group-name"?: string }): string | undefined { | ||
return input["x-fern-group-name"]; | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/parsers/src/openapi/3.1/extensions/x-fern-group-name-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,28 @@ | ||
import { | ||
BaseOpenApiV3_1ConverterNode, | ||
BaseOpenApiV3_1ConverterNodeConstructorArgs, | ||
} from "../../BaseOpenApiV3_1Converter.node"; | ||
|
||
export declare namespace XFernGroupNameConverterNode { | ||
export interface Input { | ||
"x-fern-group-name"?: string; | ||
} | ||
} | ||
|
||
export class XFernGroupNameConverterNode<T> extends BaseOpenApiV3_1ConverterNode<T, string | undefined> { | ||
groupName?: string; | ||
|
||
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<T>) { | ||
super(args); | ||
this.safeParse(); | ||
} | ||
|
||
// This would be used to set a member on the node | ||
parse(): void { | ||
this.groupName = (this.input as T & { "x-fern-group-name"?: string })["x-fern-group-name"]; | ||
} | ||
|
||
convert(): string | undefined { | ||
return this.groupName; | ||
} | ||
} |