fix(codegen): preserve asset_type discriminator on Individual*Asset slot types (#1498)#1514
Merged
Merged
Conversation
…lot types (closes #1498) json-schema-to-typescript was flattening the schema's allOf:[baseIndividualAsset] + properties.asset_type.const discriminator on the 14 IndividualXAsset slot types, leaving them as bare BaseIndividualAsset aliases. Adopters writing TS-clean code that constructed one of these without asset_type got runtime VALIDATION_ERROR against the wire schema with no compile-time signal. Adds a codegen post-processor (applyIndividualAssetDiscriminators) that rewrites the affected aliases into discriminated intersections: type IndividualImageAsset = BaseIndividualAsset & { asset_type: 'image'; requirements?: ImageAssetRequirements; }; Same treatment for the other 13. The requirements field is omitted on tools.generated.ts where the per-type *AssetRequirements interface isn't redeclared. No runtime change — the wire validator already rejected these. The new TS error catches a strictly pre-existing bug at build time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bokelley
added a commit
that referenced
this pull request
May 3, 2026
Pulls in 4 commits: - docs(skills): close three #1496 follow-up review items + seller adapter format slot sweep (#1515) - docs(migration): add recipe #10b for derived-mode account_id refusal (#1492) (#1512) - fix(codegen): preserve asset_type discriminator on Individual*Asset slot types (closes #1498) (#1514) - fix(examples): wire assertMediaBuyTransition into hello_seller_adapter_non_guaranteed (closes #1499) (#1513) Conflict resolution: - src/lib/types/core.generated.ts: kept the 3.0.6 generation header from HEAD; ran `npm run generate-types:all` against the local mirror to pull in main's #1514 codegen fix (asset_type discriminator preserved on Individual*Asset slots) layered on top of 3.0.6 schemas. - test/examples/hello-seller-adapter-non-guaranteed.test.js: kept main's empty allowlist + new helper-shape conditional. Main's #1513 closes #1416 by actually wiring `assertMediaBuyTransition` into the non-guaranteed adapter — superseding the follow-up note my branch carried. Verified post-merge: - npm run build clean - 6/6 hello-adapter tests for the modified files green - npm run format:check clean Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
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.
Closes #1498.
Why
json-schema-to-typescriptwas flattening the schema'sallOf:[baseIndividualAsset]+properties.asset_type.constdiscriminator on the 14IndividualXAssetslot types, leaving them as bareBaseIndividualAssetaliases. Adopters writing TS-clean code constructing one of these withoutasset_typegot runtimeVALIDATION_ERRORagainst the wire schema with no compile-time signal — exactly the class of codegen mismatch we've burned down before (date vs date-time, Foo/Foo1 dedupe).What
applyIndividualAssetDiscriminatorspost-processor inscripts/generate-types.ts.Individual*Asset = BaseIndividualAssetaliases into discriminated intersections:core.generated.tsandtools.generated.ts. Therequirements?:field is conditionally emitted — only when the per-type*AssetRequirementsinterface is declared in the same file (avoids TS2304 intools.generated.tswhere these aren't redeclared).core.generated.ts,tools.generated.ts, and the downstreamschemas.generated.ts(Zod schemas auto-derived from TS types).Compat
Strictly additive at runtime — wire validator already rejected these. The new TS errors catch a pre-existing bug at compile time. Adopters who construct
IndividualImageAssetliterals withoutasset_typewill see TS errors that tell them what they were already getting at runtime.Test plan
npm run format:check— cleannpm run typecheck— cleannpm run build:lib— cleannode --test test/examples/hello-creative-adapter-template.test.js— 3/3 pass (the gate most likely to use these types)asset_typevia standalone TS test:🤖 Generated with Claude Code