Skip to content

Fix TypeScript Fetch tagged oneOf union member conversion - #145

Merged
adamcavendish merged 1 commit into
mainfrom
fix/typescript-fetch-tagged-union-member-conversion
Aug 19, 2026
Merged

Fix TypeScript Fetch tagged oneOf union member conversion#145
adamcavendish merged 1 commit into
mainfrom
fix/typescript-fetch-tagged-union-member-conversion

Conversation

@adamcavendish

Copy link
Copy Markdown
Collaborator

Problem

typescript-fetch generated correct camelCase-to-wire converters for each member of a tagged oneOf, but the union converter itself used an unchecked cast. This happened when the tagged oneOf members were plain inline objects whose discriminator is a required single-value string enum alongside two or more content properties.

TaggedEnumPattern only recognized internally tagged oneOf members wrapped in allOf, so these plain inline members fell back to an untagged Union. TypeScript camelCase mode emits cast-through converters for untagged unions, so nested request and response models kept the wrong property spelling.

Fix

  • Detect plain internally tagged oneOf variants for OAS 3.0, 3.1, and 3.2:
    • object has more than two properties
    • no allOf
    • has a required property whose schema is a single-value string enum (the discriminator)
  • Add lower-level regression tests for all three OAS versions.
  • Add a TypeScript camelCase golden fixture that exercises the union converters through a nested request and response model.

Validation

  • cargo fmt --check passes
  • cargo clippy --lib passes
  • cargo test --lib passes (665 tests)
  • cargo test --test golden_tests_typescript_fetch test_property_naming_camel_case_tagged_union_plain_internal_golden passes

Plain inline oneOf members with the discriminator alongside two or more
content properties were not recognized by TaggedEnumPattern. They fell
back to an untagged Union, so TypeScript camelCase mode emitted
cast-through union converters and skipped member field conversion.

Add detection for required single-value string enum tag fields on
plain object oneOf members with more than two properties, for OAS 3.0,
3.1, and 3.2, and add a nested-request TypeScript camelCase golden test
that exercises the generated union converters.
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.54455% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/ir/tagged_enum_pattern.rs 91.30% 6 Missing ⚠️
src/ir/lower/v30.rs 97.56% 1 Missing ⚠️
src/ir/lower/v31.rs 98.03% 1 Missing ⚠️
src/ir/lower/v32.rs 97.56% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adamcavendish
adamcavendish merged commit 0a20c3d into main Aug 19, 2026
25 checks passed
@adamcavendish
adamcavendish deleted the fix/typescript-fetch-tagged-union-member-conversion branch August 19, 2026 08:25
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