Skip to content

Commit

Permalink
feat: add display name to discriminated union variant (#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava authored Sep 11, 2024
1 parent b5fdb4f commit dcb0f74
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 3 deletions.
1 change: 1 addition & 0 deletions fern/apis/fdr/definition/api/v1/read/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ types:
- commons.WithAvailability
properties:
discriminantValue: string
displayName: optional<string>
additionalProperties: ObjectType

LiteralType:
Expand Down
1 change: 1 addition & 0 deletions fern/apis/fdr/definition/api/v1/register/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ types:
- commons.WithAvailability
properties:
discriminantValue: string
displayName: optional<string>
additionalProperties: ObjectType

LiteralType:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ function transformDiscriminatedVariant({
return {
description: writeShape.description,
availability: writeShape.availability,
displayName: writeShape.displayName,
// htmlDescription,
// descriptionContainsMarkdown: true,
discriminantValue: writeShape.discriminantValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const DiscriminatedUnionVariant: React.FC<DiscriminatedUnionVariant.Props
"px-3": !isRootTypeDefinition,
})}
>
<span className="fern-api-property-key">{titleCase(unionVariant.discriminantValue)}</span>
<span className="fern-api-property-key">
{unionVariant.displayName ?? titleCase(unionVariant.discriminantValue)}
</span>
{unionVariant.availability != null && (
<EndpointAvailabilityTag availability={unionVariant.availability} minimal={true} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const PlaygroundDiscriminatedUnionForm = memo<PlaygroundDiscriminatedUnio
discriminatedUnion.variants.map(
(variant): FernDropdown.Option => ({
type: "value",
label: titleCase(variant.discriminantValue),
label: variant.displayName ?? titleCase(variant.discriminantValue),
value: variant.discriminantValue,
// todo: handle availability
tooltip: variant.description != null ? <Markdown size="xs" mdx={variant.description} /> : undefined,
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 @@ -111,6 +111,7 @@ export class ApiTypeResolver {
description: await serializeMdx(variant.description, {
files: this.mdxOptions?.files,
}),
displayName: variant.displayName,
availability: variant.availability,
})),
),
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 @@ -487,6 +487,7 @@ export interface ResolvedDiscriminatedUnionShapeVariant extends WithMetadata {
discriminantValue: string;
extends: string[];
properties: ResolvedObjectProperty[];
displayName?: string;
}

export interface ResolvedDiscriminatedUnionShape extends WithMetadata {
Expand Down
1 change: 1 addition & 0 deletions servers/fdr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"docker:dev": "dotenv -e .env.dev -- ./create_docker.sh",
"docker:prod": "dotenv -e .env.prod -- ./create_docker.sh",
"test": "vitest --run src/** --globals",
"test:update": "vitest --run src/** --globals -u",
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../.eslintignore",
"lint:eslint:fix": "pnpm lint:eslint --fix",
"test:local": "dotenv -e .env.test -- vitest src/__test__/local --globals --config src/__test__/local/vitest.config.ts --no-file-parallelism",
Expand Down
Loading

0 comments on commit dcb0f74

Please sign in to comment.