Skip to content

Commit

Permalink
(chore): support undiscriminated union example generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Feb 29, 2024
1 parent f35680c commit fb6d74f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -25,7 +25,11 @@ export class GeneratedUndiscriminatedUnionTypeImpl<Context extends ModelContext>
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);
}
}
6 changes: 6 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.2
0.12.3-rc1

0 comments on commit fb6d74f

Please sign in to comment.