Skip to content

Commit

Permalink
Merge branch 'main' into sulaiman/fer-2377-syndicate-monite-surface-a…
Browse files Browse the repository at this point in the history
…uth-scheme-in-generated-docs
  • Loading branch information
sulaiman-fern committed Jul 30, 2024
2 parents 815108d + 373f7ef commit 770f603
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-fdr-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }}

- name: 📥 Install
uses: ./.github/actions/install
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }}

- name: 📥 Install
uses: ./.github/actions/install
Expand Down
57 changes: 35 additions & 22 deletions packages/ui/app/src/api-page/types/type-shorthand/TypeShorthand.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { APIV1Read } from "@fern-api/fdr-sdk";
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import clsx from "clsx";
import numeral from "numeral";
import { ReactNode } from "react";
import {
DereferencedTypeShape,
ResolvedTypeDefinition,
ResolvedTypeShape,
ResolvedUnknownTypeShape,
Expand All @@ -26,10 +26,7 @@ export function renderTypeShorthandRoot(
): ReactNode {
const typeShorthand = renderTypeShorthand(unwrapOptional(shape, types), { nullable: isResponse }, types);
const unaliasedShape = unwrapAlias(shape, types);
const defaultsTo =
unaliasedShape.type === "optional" && unaliasedShape.shape.type === "primitive"
? renderDefaultTo(unaliasedShape.shape.value)
: null;
const defaultsTo = renderDefaultsTo(unaliasedShape);
return (
<span className={clsx("fern-api-property-meta", className)}>
<span>{typeShorthand}</span>
Expand All @@ -38,30 +35,46 @@ export function renderTypeShorthandRoot(
) : !isResponse ? (
<span className="t-danger">Required</span>
) : null}
{defaultsTo != null && <span>{`Defaults to ${defaultsTo}`}</span>}
{defaultsTo != null && (
<span>
{"Defaults to "}
<code>{defaultsTo}</code>
</span>
)}
</span>
);
}

function renderDefaultTo(shape: APIV1Read.PrimitiveType): string | undefined {
function renderDefaultsTo(shape: DereferencedTypeShape): string | undefined {
if (shape.type !== "optional") {
return undefined;
}

if (shape.shape.type === "primitive") {
return renderDefaultToPrimitive(shape.shape.value);
}

if (shape.shape.type === "enum") {
return shape.shape.default;
}

return undefined;
}

function renderDefaultToPrimitive(shape: APIV1Read.PrimitiveType): string | undefined {
return visitDiscriminatedUnion(shape, "type")._visit<string | undefined>({
string: (string) => string.default,
integer: (integer) => {
if (integer.default == null) {
return undefined;
}
return numeral(integer.default).format("0,0");
},
double: (double) => double.default?.toString(),
string: (value) => value.default,
integer: (value) => value.default?.toString(),
double: (value) => value.default?.toString(),
uint: () => undefined,
uint64: () => undefined,
boolean: () => undefined,
long: () => undefined,
datetime: () => undefined,
uuid: () => undefined,
base64: () => undefined,
date: () => undefined,
bigInteger: () => undefined,
boolean: (value) => value.default?.toString(),
long: (value) => value.default?.toString(),
datetime: (datetime) => datetime.default,
uuid: (uuid) => uuid.default,
base64: (base64) => base64.default,
date: (value) => value.default,
bigInteger: (value) => value.default,
_other: () => undefined,
});
}
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/app/src/docs/HeaderLogoSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cn from "clsx";
import { useAtomValue } from "jotai";
import { PropsWithChildren, ReactElement } from "react";
import { LOGO_HREF_ATOM, LOGO_TEXT_ATOM, VERSIONS_ATOM, useColors, useFile, useLogoHeight } from "../atoms";
import { DOCS_ATOM, LOGO_HREF_ATOM, LOGO_TEXT_ATOM, VERSIONS_ATOM, useColors, useFile, useLogoHeight } from "../atoms";
import { FernImage } from "../components/FernImage";
import { FernLink } from "../components/FernLink";
import { VersionDropdown } from "./VersionDropdown";
Expand Down Expand Up @@ -40,11 +40,14 @@ function FernLogoImage(): ReactElement | null {
const colors = useColors();
const logoImageHeight = useLogoHeight();
const imageClassName = "max-h-full object-contain";
const title = useAtomValue(DOCS_ATOM).title ?? "Logo";

if (colors.dark != null && colors.light != null) {
return (
<>
{colors.light.logo != null && (
<FernFileImage
alt={title}
fileId={colors.light.logo}
className={cn(imageClassName, "block dark:hidden")}
height={logoImageHeight}
Expand All @@ -56,6 +59,7 @@ function FernLogoImage(): ReactElement | null {
)}
{colors.dark.logo != null && (
<FernFileImage
alt={title}
fileId={colors.dark.logo}
className={cn(imageClassName, "hidden dark:block")}
height={logoImageHeight}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/app/src/resolver/ApiTypeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ApiTypeResolver {
files: this.mdxOptions?.files,
}),
availability,
default: enum_.default,
}),
undiscriminatedUnion: async (undiscriminatedUnion) => ({
type: "undiscriminatedUnion",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/app/src/resolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ interface ResolvedEnumShape extends WithMetadata {
name: string | undefined;
type: "enum";
values: ResolvedEnumValue[];
default: string | undefined;
}

export interface ResolvedEnumValue extends WithMetadata {
Expand Down

0 comments on commit 770f603

Please sign in to comment.