Skip to content

feat(xhandler-wasm): generate the bindings' SUNAT answers from the schema - #613

Merged
carlosthe19916 merged 1 commit into
mainfrom
feat/generated-answers
Nov 16, 2026
Merged

carlosthe19916 merged 1 commit into
mainfrom
feat/generated-answers

Conversation

@carlosthe19916

@carlosthe19916 carlosthe19916 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Why

A field added in Rust didn't reach the Go, Python and Java bindings. The SUNAT answers (CDR, fault, ticket, consult status) were untyped json!{} in sender.rs and were typed by hand in each binding. For example, #612 added document_description to the CDR, and none of the three bindings picked it up:

  • Python would fail on it, because its models reject unknown fields.
  • Go and Java dropped it silently.
  • The conformance cases didn't notice, because they compare raw JSON.

What

The answers become part of the contract the bindings generate from, like the documents already are. A field is written down once, in Rust, and arrives in every binding with the next release's sync PRs.

  • xhandler-wasm/src/answer.rs: the answers as Rust types. sender.rs builds them, so it can't emit a field the schema lacks.
  • examples/schema.rs: the schema root now includes the answers.
  • codegen.py:
    • generates two packages, xbuilder (documents) and xsender (answers)
    • supports externally tagged unions, enum names from x-enum-varnames, and the byte and uint16 formats
    • generates lenient answers, which ignore the fields a newer core adds
  • dist/models/<lang>/xsender/: the generated answers. The existing paths don't change, so older binding Makefiles keep working.
  • docs/adrs/BINDINGS.md: the design, the compatibility rules and the rollout.

Verified

  • The conformance cases, recorded from what invoke returns, are byte for byte the same as on main. The JSON doesn't change.
  • The generated xbuilder models are unchanged, except that Python enums now print their value (__str__).
  • The generated answers match today's hand-written Go and Python types field for field. In Go, CDR.StatusCode and Fault.HTTPStatus become pointers.
  • cargo fmt, cargo clippy (with and without schema) and the wasm build pass.
  • The Go, Python and Java test suites pass on the wasm built from this branch, together with the binding PRs below.

Rollout (see the ADR)

  1. Binding PRs, before alpha.2: read document_description; Python's answers become lenient.
  2. This PR.
  3. Release 6.0.0-alpha.2.
  4. Each binding syncs dist/models/<lang>/xsender/ and replaces its hand-written answers with the generated ones.

Senior review

Two passes. The first found three should-fix items, all in the ADR:

  • the Java direction was stated as if already done
  • new enum values were wrongly listed as non-breaking
  • the API differences after the switch were incomplete

It also listed codegen nits: package config in one place, the __all__ slot, a regex comment, and the shape of sender.rs. All are applied. The second pass found nothing left.

🤖 Generated with Claude Code

…hema

The answers of `parse` (CDR, fault, ticket, consult status) were untyped
`json!{}` in sender.rs and typed by hand in each binding, so a field added
in Rust, like the CDR's `document_description`, never reached Go, Python or
Java. They are now Rust types in answer.rs and part of the schema, and
codegen.py generates them into each binding's xsender package, like the
documents: a field is written down once, in Rust, and arrives with the next
release's sync PRs.

- answer.rs: the answers, typed; sender.rs builds them. The JSON doesn't
  change: the conformance cases are byte for byte the same.
- codegen.py: two packages (xbuilder, xsender), externally tagged unions,
  enum names from `x-enum-varnames`, the byte and uint16 formats, and
  lenient answers that ignore fields a newer core adds.
- dist/models/<lang>/xsender/: the generated answers.
- docs/adrs/BINDINGS.md: the design and the rollout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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