Skip to content

fix: handle TypeScript Fetch tagged union payloads#127

Merged
adamcavendish merged 1 commit into
mainfrom
adamcavendish/fix-typescript-fetch-tagged-nullable-unions
Jun 22, 2026
Merged

fix: handle TypeScript Fetch tagged union payloads#127
adamcavendish merged 1 commit into
mainfrom
adamcavendish/fix-typescript-fetch-tagged-nullable-unions

Conversation

@adamcavendish

@adamcavendish adamcavendish commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes TypeScript Fetch generation for tagged union payloads and nullable/union-heavy model shapes exposed by a VP-generated client.

What changed

  • Promote object-shaped adjacent and external tagged payloads during IR lowering so the TypeScript emitter can inspect variant structure safely.
  • Preserve snake_case wire keys while emitting camelCase ergonomic payload keys under property_naming = "camelCase".
  • Convert nested tagged payloads recursively in fromJSON and toJSON, including array/map/union wrappers around named models.
  • Treat discriminator-only variants as tag-only only when the resolved object is closed; variants with additionalProperties remain contentful.
  • Add null guards for nullable required array/ref fields and simplify redundant TypeScript union members.
  • Add a masked VP camelCase golden fixture covering tagged payload mapping, tag-only variants, nullable conversion, and union simplification.

Root cause

Tagged-union payload emission assumed payloads were directly named object schemas and could not consistently distinguish closed discriminator-only variants from object-shaped content after lowering. The TypeScript converter path also only applied named-model conversion at the top level, so wrapped named payloads could bypass conversion.

Validation

  • UPDATE_GOLDEN=1 cargo test --test golden_tests_typescript_fetch test_toolchain_vp_camel_case_tagged_nullable_unions_golden -- --nocapture
  • cargo fmt --all -- --check
  • cargo test --test golden_tests_typescript_fetch -- --nocapture
  • ./scripts/golden-build-typescript.sh vp
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace --quiet
  • Downstream VP-generated client check with the fixed local openapi-nexus binary: VP_NODE_VERSION=24.15.0 vp check --no-fmt passed with no warnings, lint errors, or type errors in 869 files.

- Promote object-shaped tagged payloads before TypeScript Fetch emission
- Preserve camelCase ergonomic keys, wire keys, nullable guards, and simplified unions
- Add VP camelCase tagged nullable union goldens for masked schemas
@adamcavendish adamcavendish marked this pull request as ready for review June 22, 2026 06:22
@adamcavendish adamcavendish merged commit a1ec8c2 into main Jun 22, 2026
23 of 24 checks passed
@adamcavendish adamcavendish deleted the adamcavendish/fix-typescript-fetch-tagged-nullable-unions branch June 22, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant