Skip to content

fix: preserve nested JSON Schema grouping in TypeScript - #17

Merged
shivros merged 1 commit into
mainfrom
runner/COD-521-nested-ts-grouping
Sep 23, 2026
Merged

shivros merged 1 commit into
mainfrom
runner/COD-521-nested-ts-grouping

Conversation

@shivros

@shivros shivros commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Track TypeScript JSON Schema expression precedence instead of flattening nested unions/intersections as strings.
  • Parenthesize lower-precedence union operands when they are rendered inside intersections, while preserving existing scalar, nullable, array, object, and deterministic output behavior.
  • Add a real nested-schema fixture with strict TypeScript assignments, baseline evidence, two-write byte comparison, hydra check, and CI invocation.

Linear

COD-521 — Hydra: preserve nested JSON Schema union/intersection grouping in TypeScript.

Baseline evidence

The pre-fix fixture was generated from Hydra origin/main at b210ff55147dbf5667b2c098c833a94a96126fba and compiled with the pinned TypeScript 5.9.2 toolchain. The compiler exited 2 with four TS2578: Unused '@ts-expect-error' directive failures at type-tests.ts lines 21, 24, 26, and 29, proving the ungrouped renderer accepted invalid values. The reproducible record is committed at crates/hydra-codegen/tests/fixtures/nested-ts-schema/baseline.md.

Verification

  • cargo build --all-targets
  • cargo test --all-targets — 59 codegen tests plus Notes/Security Scan suites passed
  • cargo clippy --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • cargo run -p hydra-codegen --bin hydra-codegen -- check in examples/notes, examples/security-scan, and examples/ts-client
  • npm run test:nested-schema — two writes byte-identical across CLI/HTTP/MCP/TypeScript, hydra check passed, strict TypeScript 5.9.2 positive/negative assignments passed
  • npm run typecheck
  • npm run build
  • creed diff
  • git diff --check
  • cargo metadata --locked --no-deps --format-version 1

No consumer repin, release/tag, npm publication, deployment, credential, or runtime transport behavior is included.

@shivros

shivros commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated Review Panel

Reviewer A

APPROVE

  • The precedence-aware TsTypeExpression model correctly ranks unions below intersections and parenthesizes lower-precedence operands inside & expressions.
  • The generated-output assertions cover anyOf, oneOf, enum, nested intersections, and array/object nesting.
  • The strict TypeScript fixture covers valid assignments and rejects out-of-domain intersection and union values. The committed baseline.md records the pre-fix b210ff5 compiler failure with the four unused @ts-expect-error diagnostics.
  • The fixture checks two byte-identical writes across all four artifacts and runs hydra check; no unrelated runtime or transport behavior was introduced.

No remaining correctness or acceptance blockers found.

Reviewer B

APPROVE

  • The renderer preserves TypeScript operator precedence and produces the required ("a" | "b") & "b" grouping for the target schema.
  • Recursive handling remains correct for oneOf, anyOf, allOf, enum, nullable types, arrays, and objects, with deterministic ordering preserved.
  • The checked-in fixture validates the generated result with TypeScript 5.9.2, and the two-write determinism plus freshness checks provide reproducible evidence.
  • The change stays bounded to Hydra code generation and CI evidence; it does not add runtime transport behavior, consumer adoption, or release work.

No blocking findings.

@shivros
shivros marked this pull request as ready for review September 23, 2026 08:10
@shivros

shivros commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Auto-Merge Gate

Confidence: 0.95

The implementation directly satisfies COD-521: it replaces precedence-blind TypeScript schema rendering with an explicit precedence model and adds real generated-output, strict TypeScript, determinism, and CI coverage for the reported nested union/intersection bug.

Checks observed: CI Test and Creed context drift succeeded. The PR's review panel found no remaining blockers. The linked Linear issue contains no manual-review or do-not-merge requirement, and this change excludes releases, deployment, credentials, and consumer adoption.

Scope reviewed: Hydra code-generation correctness plus focused fixtures and CI invocation only.

@shivros
shivros merged commit a15cf8f into main Sep 23, 2026
2 checks passed
@shivros
shivros deleted the runner/COD-521-nested-ts-grouping branch September 23, 2026 08:14
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