feat(go): read union base-property dedupe facts from the IR#17042
Draft
fern-support wants to merge 1 commit into
Draft
feat(go): read union base-property dedupe facts from the IR#17042fern-support wants to merge 1 commit into
fern-support wants to merge 1 commit into
Conversation
Consume UnionTypeDeclaration.InheritedBaseProperties (computed once upstream in the IR) in the Go model instead of re-deriving the dedupe decision from the variants. Delete the re-derivation helpers everyVariantHasMatchingGetter and objectExportedProperties; keep the delegating-getter emission (writeUnionInheritedBasePropertyGetters) and a thin local filter that keeps literal-typed inherited properties on the envelope (they render as methods, not delegatable fields). Gate stays on the opt-in dedupeUnionBaseProperties flag. Hand-adds the InheritedBaseProperties field to the vendored IR struct; the final step (post IR publish) is to regenerate generators/go/internal/fern/ir from the published IR and move go-sdk to irVersion 67 so the field is populated at runtime. BLOCKED: stacks on the IR PR (#17041). Does nothing at runtime until (1) the new IR minor publishes and (2) go-sdk moves from irVersion 66 to 67 (today the CLI migrates the IR down to v66 and strips these fields). Go build/test not run locally (no Go toolchain in this environment); gofmt the vendored struct on regen. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Linear ticket: Refs
PR 2 of 3 (stacked on the IR PR #17041). Makes the Go v1 model consume the discriminated-union base-property dedupe decision from the IR instead of re-deriving it. Companion to #17041 (IR facts) and the C# PR.
Changes Made
internal/generator/model.go: rewroteunionInheritedBasePropertyNamesto readunion.InheritedBaseProperties(computed once in the IR) instead of re-deriving it from the variants. DeletedeveryVariantHasMatchingGetterandobjectExportedProperties. KeptwriteUnionInheritedBasePropertyGetters(getter emission is Go policy) and a thin local filter that keeps literal-typed inherited properties on the envelope (they render as methods, not delegatable fields).internal/fern/ir/types.go: hand-added theInheritedBasePropertiesfield + getter to the vendoredUnionTypeDeclaration(stand-in for regenerating the vendored structs from the published IR).internal/generator/model_union_test.go: refocused the unit test on the Go side's consumption (flag gate, literal local filter, name mapping); the "which props are inherited" decision is now covered by the IR-generator tests in feat(ir): compute discriminated-union base-property dedupe facts in the IR #17041.Behavior note
Go previously deduped on rendered-Go-type equality (a superset of the IR's structural equality). Reading
inheritedBasePropertiesmeans Go dedupes strictly fewer cases — a few previously-suppressed fields may reappear on the envelope. This is safe (it can only keep a field, never drop a needed one → nogo vetregressions) and removes the drift between the Go model and the Go dynamic snippets.Remaining before this can merge
@fern-fern/ir-sdkpublish.go-sdktoirVersion: 67and regenerategenerators/go/internal/fern/ir/from the published IR (replacing the hand-added struct field).DynamicTypeInstantiationMapper) — coordinate with the fix(go): stop dynamic snippets from setting deduped union base properties at the union root #16994 effort; needs@fern-api/dynamic-ir-sdkrepublished withinheritedBaseProperties. Not included here.go build ./... && go test ./...(no Go toolchain in the authoring environment) andgofmtthe regenerated struct.pnpm seed test --generator go-sdkwith the flag on — expect only additive field reappearances, no removals.Testing
model_union_test.go) — not executed locally (no Go toolchain); runs in CI once unblocked.Generated with Claude Code