Skip to content

Commit

Permalink
fix shorthand in api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-support committed Jan 17, 2025
1 parent 33574c1 commit 334b49b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/fern-docs/ui/src/type-shorthand/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
visitDiscriminatedUnion,
} from "@fern-api/ui-core-utils";
import { uniq } from "es-toolkit/array";
import { sum } from "es-toolkit/math";
import { ReactNode } from "react";

export interface TypeShorthandOptions {
Expand Down Expand Up @@ -210,7 +211,13 @@ export function renderTypeShorthand(
plural ? "objects" : maybeWithArticle("an", "object"),
enum: (enumValue) => {
// if there are only 1 or 2 values, we can list them like literals (e.g. "apple" or "banana")
if (enumValue.values.length > 0 && enumValue.values.length < 3) {
if (enumValue.values.length === 1) {
return `"${enumValue.values[0]?.value}"`;
}
if (
enumValue.values.length > 1 &&
sum(enumValue.values.map((value) => value.value.length)) < 20
) {
return enumValue.values.map((value) => `"${value.value}"`).join(" or ");
}
return plural ? "enums" : maybeWithArticle("an", "enum");
Expand Down

0 comments on commit 334b49b

Please sign in to comment.