-
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
0ad83a4
commit 539136e
Showing
4 changed files
with
77 additions
and
3 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
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
65 changes: 65 additions & 0 deletions
65
packages/parsers/src/openapi/3.1/extensions/XFernGlobalHeadersConverter.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,65 @@ | ||
import { isNonNullish } from "@fern-api/ui-core-utils"; | ||
import { OpenAPIV3_1 } from "openapi-types"; | ||
import { FernRegistry } from "../../../client/generated"; | ||
import { | ||
BaseOpenApiV3_1ConverterNode, | ||
BaseOpenApiV3_1ConverterNodeConstructorArgs, | ||
} from "../../BaseOpenApiV3_1Converter.node"; | ||
import { extendType } from "../../utils/extendType"; | ||
import { maybeSingleValueToArray } from "../../utils/maybeSingleValueToArray"; | ||
import { SchemaConverterNode } from "../schemas"; | ||
import { X_FERN_GLOBAL_HEADERS } from "./fernExtension.consts"; | ||
|
||
export declare namespace XFernGlobalHeadersConverterNode { | ||
export interface Input { | ||
[X_FERN_GLOBAL_HEADERS]?: (( | ||
| OpenAPIV3_1.SchemaObject | ||
| OpenAPIV3_1.ReferenceObject | ||
) & { | ||
header: string; | ||
})[]; | ||
} | ||
} | ||
|
||
export class XFernGlobalHeadersConverterNode extends BaseOpenApiV3_1ConverterNode< | ||
unknown, | ||
FernRegistry.api.latest.ObjectProperty[] | ||
> { | ||
globalHeaders?: Record<string, SchemaConverterNode> | undefined; | ||
|
||
constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<unknown>) { | ||
super(args); | ||
this.safeParse(); | ||
} | ||
|
||
// This would be used to set a member on the node | ||
parse(): void { | ||
extendType<XFernGlobalHeadersConverterNode.Input>(this.input)[ | ||
X_FERN_GLOBAL_HEADERS | ||
]?.forEach((header) => { | ||
const { header: headerName, ...schema } = header; | ||
this.globalHeaders ??= {}; | ||
this.globalHeaders[headerName] = new SchemaConverterNode({ | ||
input: schema, | ||
context: this.context, | ||
accessPath: this.accessPath, | ||
pathId: this.pathId, | ||
}); | ||
}); | ||
} | ||
|
||
convert(): FernRegistry.api.latest.ObjectProperty[] | undefined { | ||
return Object.entries(this.globalHeaders ?? {}) | ||
.flatMap(([headerName, headerSchema]) => { | ||
const convertedSchema = maybeSingleValueToArray(headerSchema.convert()); | ||
|
||
return convertedSchema?.map((schema) => ({ | ||
key: FernRegistry.PropertyKey(headerName), | ||
valueShape: schema, | ||
description: headerSchema.description, | ||
availability: headerSchema.availability?.convert(), | ||
})); | ||
}) | ||
.filter(isNonNullish); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/parsers/src/openapi/3.1/extensions/fernExtension.consts.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