Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MdxServerComponentProseSuspense } from "@/mdx/components/server-compone
import { ObjectProperty } from "../type-definitions/ObjectProperty";
import {
TypeDefinitionAnchorPart,
TypeDefinitionRequest,
TypeDefinitionResponse,
} from "../type-definitions/TypeDefinitionContext";
import { WithSeparator } from "../type-definitions/TypeDefinitionDetails";
Expand Down Expand Up @@ -62,6 +63,7 @@ export async function EndpointContentLeft({
hidden: false,
valueShape: stringShape,
availability: undefined,
propertyAccess: undefined,
};
},
bearerAuth: (bearerAuth) => {
Expand All @@ -73,6 +75,7 @@ export async function EndpointContentLeft({
hidden: false,
valueShape: stringShape,
availability: undefined,
propertyAccess: undefined,
};
},
header: (value) => {
Expand All @@ -85,6 +88,7 @@ export async function EndpointContentLeft({
hidden: false,
valueShape: stringShape,
availability: undefined,
propertyAccess: undefined,
};
},
oAuth: (value) => {
Expand All @@ -104,6 +108,7 @@ export async function EndpointContentLeft({
hidden: false,
valueShape: stringShape,
availability: undefined,
propertyAccess: undefined,
}),
}),
});
Expand Down Expand Up @@ -188,27 +193,29 @@ export async function EndpointContentLeft({
</TypeDefinitionAnchorPart>
)}
{endpoint.requests?.[0] != null && (
<EndpointSection
title="Request"
description={
<MdxServerComponentProseSuspense
size="sm"
className="text-(color:--grayscale-a11)"
mdx={endpoint.requests[0].description}
fallback={createEndpointRequestDescriptionFallback(
endpoint.requests[0],
types
)}
/>
}
>
<TypeDefinitionAnchorPart part="body">
<EndpointRequestSection
request={endpoint.requests[0]}
types={types}
/>
</TypeDefinitionAnchorPart>
</EndpointSection>
<TypeDefinitionRequest>
<EndpointSection
title="Request"
description={
<MdxServerComponentProseSuspense
size="sm"
className="text-(color:--grayscale-a11)"
mdx={endpoint.requests[0].description}
fallback={createEndpointRequestDescriptionFallback(
endpoint.requests[0],
types
)}
/>
}
>
<TypeDefinitionAnchorPart part="body">
<EndpointRequestSection
request={endpoint.requests[0]}
types={types}
/>
</TypeDefinitionAnchorPart>
</EndpointSection>
</TypeDefinitionRequest>
)}
</TypeDefinitionAnchorPart>
<TypeDefinitionResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";

import { ApiDefinition } from "@fern-api/fdr-sdk";

import { FernCollapseWithButtonUncontrolled } from "./FernCollapseWithButtonUncontrolled";
import { ObjectProperty } from "./ObjectProperty";
import {
TypeDefinitionPathPart,
shouldIncludeObjectProperty,
useTypeDefinitionContext,
} from "./TypeDefinitionContext";
import { WithSeparator } from "./TypeDefinitionDetails";

export function FilteredObjectProperties({
properties,
types,
}: {
properties: ApiDefinition.ObjectProperty[];
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>;
}) {
const { isRequest, isResponse } = useTypeDefinitionContext();

const filteredProperties = properties.filter((property) => {
return shouldIncludeObjectProperty(property, isRequest, isResponse);
});

return (
<FernCollapseWithButtonUncontrolled
showText={`Show ${filteredProperties.length} properties`}
hideText={`Hide ${filteredProperties.length} properties`}
>
<WithSeparator>
{filteredProperties.map((property) => (
<TypeDefinitionPathPart
key={property.key}
part={{ type: "objectProperty", propertyName: property.key }}
>
<ObjectProperty property={property} types={types} />
</TypeDefinitionPathPart>
))}
</WithSeparator>
</FernCollapseWithButtonUncontrolled>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { DiscriminatedUnionVariant } from "./DiscriminatedUnionVariant";
import { EnumTypeDefinition } from "./EnumTypeDefinition";
import { EnumValue } from "./EnumValue";
import { FernCollapseWithButtonUncontrolled } from "./FernCollapseWithButtonUncontrolled";
import { ObjectProperty } from "./ObjectProperty";
import { TypeDefinitionPathPart } from "./TypeDefinitionContext";
import { FilteredObjectProperties } from "./FilteredObjectProperties";
import { WithSeparator } from "./TypeDefinitionDetails";
import { UndiscriminatedUnionVariant } from "./UndiscriminatedUnionVariant";

Expand Down Expand Up @@ -84,23 +83,8 @@ export const InternalTypeDefinition = memo(function InternalTypeDefinition({
shape,
types
).properties;
return (
<FernCollapseWithButtonUncontrolled
showText={`Show ${properties.length} properties`}
hideText={`Hide ${properties.length} properties`}
>
<WithSeparator>
{properties.map((property) => (
<TypeDefinitionPathPart
key={property.key}
part={{ type: "objectProperty", propertyName: property.key }}
>
<ObjectProperty property={property} types={types} />
</TypeDefinitionPathPart>
))}
</WithSeparator>
</FernCollapseWithButtonUncontrolled>
);

return <FilteredObjectProperties properties={properties} types={types} />;
}
case "primitive":
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { createContext, useContext, useMemo } from "react";
import React from "react";

import { ApiDefinition } from "@fern-api/fdr-sdk";
import { TypeDefinition } from "@fern-api/fdr-sdk/api-definition";
import { slugToHref } from "@fern-docs/utils";
import { useLazyRef } from "@fern-ui/react-commons";
Expand All @@ -14,11 +15,12 @@ import { useCurrentPathname } from "@/hooks/use-current-pathname";
import { JsonPropertyPath } from "../examples/JsonPropertyPath";
import { JsonPropertyPathPart } from "../examples/JsonPropertyPath";

interface TypeDefinitionContextValue {
export interface TypeDefinitionContextValue {
types: Record<string, TypeDefinition>;
isRootTypeDefinition: boolean;
jsonPropertyPath: JsonPropertyPath;
isResponse: boolean | undefined;
isRequest: boolean | undefined;
slug: string;
anchorIdParts: readonly string[];
collapsible: boolean;
Expand Down Expand Up @@ -47,6 +49,7 @@ export function TypeDefinitionRoot({
isRootTypeDefinition: true,
jsonPropertyPath: [],
isResponse: undefined,
isRequest: undefined,
types,
slug,
anchorIdParts: [],
Expand Down Expand Up @@ -124,6 +127,24 @@ export function TypeDefinitionResponse({
);
}

export function TypeDefinitionRequest({
children,
}: {
children: React.ReactNode;
}) {
const parent = useTypeDefinitionContext();
const contextValue = React.useRef(() => ({
...parent,
isRequest: true,
}));

return (
<TypeDefinitionContext.Provider value={contextValue.current}>
{children}
</TypeDefinitionContext.Provider>
);
}

export function TypeDefinitionCollapsible({
children,
}: {
Expand Down Expand Up @@ -190,3 +211,13 @@ export function useIsActive(): boolean {
const href = useHref();
return currentHref === href;
}

export function shouldIncludeObjectProperty(
property: ApiDefinition.ObjectProperty,
isRequest?: boolean,
isResponse?: boolean
) {
if (isRequest && property.propertyAccess === "READ_ONLY") return false;
if (isResponse && property.propertyAccess === "WRITE_ONLY") return false;
return true;
}