Skip to content

Commit

Permalink
nested array object update
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Feb 6, 2025
2 parents c044827 + b6c699a commit 06340c5
Show file tree
Hide file tree
Showing 15 changed files with 527 additions and 5,984 deletions.
6 changes: 6 additions & 0 deletions packages/fern-docs/components/src/FernButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@
}
}

#fern-search-desktop-command {
.fern-copy-button {
top: 0.1rem !important;
}
}

.fern-copy-button {
@apply size-fit backdrop-blur;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,6 @@ const AskAICommandItems = memo<{
message.assistant?.id ?? message.user?.id
}
value={message.assistant?.id ?? message.user?.id}
onSelect={() => {
const content = message.assistant?.content;
if (content) {
void navigator.clipboard.writeText(content);
}
}}
asChild
scrollLogicalPosition="start"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const CodeBlockWithClipboardButton: React.FC<
{children}
<CopyToClipboardButton
className={cn(
"absolute z-20",
"z-10 opacity-0 backdrop-blur transition group-hover/cb-container:opacity-100",
"fern-copy-button absolute z-20",
"opacity-0 backdrop-blur transition group-hover/cb-container:opacity-100",
"right-3 top-2"
)}
content={code}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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 { convertToObjectProperties } from "../../utils/3.1/convertToObjectProperties";
import { resolveParameterReference } from "../../utils/3.1/resolveParameterReference";
import { extendType } from "../../utils/extendType";
import { maybeSingleValueToArray } from "../../utils/maybeSingleValueToArray";
import { SchemaConverterNode } from "../schemas";
import { ParameterBaseObjectConverterNode } from "../paths";
import { X_FERN_GLOBAL_HEADERS } from "./fernExtension.consts";

export declare namespace XFernGlobalHeadersConverterNode {
export interface Input {
[X_FERN_GLOBAL_HEADERS]?: ((
| OpenAPIV3_1.SchemaObject
| OpenAPIV3_1.ParameterObject
| OpenAPIV3_1.ReferenceObject
) & {
header: string;
optional?: boolean;
})[];
}
}
Expand All @@ -25,7 +26,8 @@ export class XFernGlobalHeadersConverterNode extends BaseOpenApiV3_1ConverterNod
unknown,
FernRegistry.api.latest.ObjectProperty[]
> {
globalHeaders?: [string, SchemaConverterNode][] | undefined;
globalHeaders?: Record<string, ParameterBaseObjectConverterNode> | undefined;
requiredProperties?: string[] | undefined;

constructor(args: BaseOpenApiV3_1ConverterNodeConstructorArgs<unknown>) {
super(args);
Expand All @@ -34,35 +36,36 @@ export class XFernGlobalHeadersConverterNode extends BaseOpenApiV3_1ConverterNod

// This would be used to set a member on the node
parse(): void {
this.globalHeaders = extendType<XFernGlobalHeadersConverterNode.Input>(
const headers = extendType<XFernGlobalHeadersConverterNode.Input>(
this.input
)[X_FERN_GLOBAL_HEADERS]?.map((header) => {
const { header: headerName, ...schema } = header;
if (
(schema.optional != null && !schema.optional) ||
resolveParameterReference(schema, this.context.document)?.required
) {
this.requiredProperties ??= [];
this.requiredProperties?.push(headerName);
}
return [
headerName,
new SchemaConverterNode({
new ParameterBaseObjectConverterNode({
input: schema,
context: this.context,
accessPath: this.accessPath,
pathId: this.pathId,
seenSchemas: new Set(),
}),
];
});
if (headers != null) {
this.globalHeaders = Object.fromEntries(headers);
}
}

convert(): FernRegistry.api.latest.ObjectProperty[] | undefined {
return 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);
return convertToObjectProperties(
this.globalHeaders,
this.requiredProperties
)?.flat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ describe("XFernGlobalHeadersConverterNode", () => {
});

expect(converter.globalHeaders).toBeDefined();
expect(converter.globalHeaders?.length).toBe(1);
expect(converter.globalHeaders?.[0][0]).toBe("X-API-Key");
expect(Object.keys(converter.globalHeaders)[0]).toEqual("X-API-Key");
expect(converter.globalHeaders?.["X-API-Key"].description).toEqual(
"API Key for authentication"
);
});

it("should handle empty input", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "test-uuid-replacement",
"endpoints": {},
"websockets": {},
"webhooks": {},
"types": {},
"subpackages": {},
"auths": {},
"globalHeaders": [
{
"key": "RequiredGlobalHeader",
"valueShape": {
"type": "alias",
"value": {
"type": "primitive",
"value": {
"type": "string"
}
}
},
"description": "required global header"
},
{
"key": "OptionalGlobalHeader",
"valueShape": {
"type": "alias",
"value": {
"type": "optional",
"shape": {
"type": "alias",
"value": {
"type": "primitive",
"value": {
"type": "string"
}
}
}
}
},
"description": "optional global header"
}
]
}
Loading

0 comments on commit 06340c5

Please sign in to comment.