From fb6d74f37e625dd67e82b588de62906eacde4713 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Thu, 29 Feb 2024 09:41:32 -0500 Subject: [PATCH] (chore): support undiscriminated union example generation --- .../GeneratedUndiscriminatedUnionTypeImpl.ts | 12 ++++++++---- generators/typescript/sdk/CHANGELOG.md | 6 ++++++ generators/typescript/sdk/VERSION | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts b/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts index e30e9b7c202..94a347ab875 100644 --- a/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts +++ b/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts @@ -1,5 +1,5 @@ -import { UndiscriminatedUnionTypeDeclaration } from "@fern-fern/ir-sdk/api"; -import { getWriterForMultiLineUnionType, maybeAddDocs } from "@fern-typescript/commons"; +import { ExampleTypeShape, UndiscriminatedUnionTypeDeclaration } from "@fern-fern/ir-sdk/api"; +import { GetReferenceOpts, getWriterForMultiLineUnionType, maybeAddDocs } from "@fern-typescript/commons"; import { GeneratedUndiscriminatedUnionType, ModelContext } from "@fern-typescript/contexts"; import { ts } from "ts-morph"; import { AbstractGeneratedType } from "../AbstractGeneratedType"; @@ -25,7 +25,11 @@ export class GeneratedUndiscriminatedUnionTypeImpl maybeAddDocs(type, this.getDocs(context)); } - public buildExample(): ts.Expression { - throw new Error("Examples are not supported for undiscriminated unions"); + public buildExample(example: ExampleTypeShape, context: Context, opts: GetReferenceOpts): ts.Expression { + if (example.type !== "undiscriminatedUnion") { + throw new Error("Example is not for an undiscriminated union"); + } + + return context.type.getGeneratedExample(example.singleUnionType).build(context, opts); } } diff --git a/generators/typescript/sdk/CHANGELOG.md b/generators/typescript/sdk/CHANGELOG.md index 6492c13553f..145c3de7020 100644 --- a/generators/typescript/sdk/CHANGELOG.md +++ b/generators/typescript/sdk/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.3-rc1] - 2024-02-27 + +- Fix: Previously SDK code snippets would not support generation with undiscriminated + unions. Now, it does. + + ## [0.12.2] - 2024-02-27 - Fix: Previously SDK code snippets would not take into account default parameter values diff --git a/generators/typescript/sdk/VERSION b/generators/typescript/sdk/VERSION index 26acbf080be..d294b5831ed 100644 --- a/generators/typescript/sdk/VERSION +++ b/generators/typescript/sdk/VERSION @@ -1 +1 @@ -0.12.2 +0.12.3-rc1