Skip to content

Emit unescaped JSON key for type fields#559

Merged
leighmcculloch merged 5 commits into
mainfrom
fix-xdr-json-type-field-key
Jul 24, 2026
Merged

Emit unescaped JSON key for type fields#559
leighmcculloch merged 5 commits into
mainfrom
fix-xdr-json-type-field-key

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Jul 23, 2026

Copy link
Copy Markdown
Member

What

Fields named type now serialize to JSON as type instead of the keyword-escaped type_.

Why

SEP-51 says a field's JSON key is its snake_case name with no keyword escaping, so type must serialize as type. Since type is a Rust keyword the generator escaped it to type_, which leaked into the JSON and schemas.

Close #558

Known limitations

This is a breaking change to the generated JSON: output is now type, not type_. Decoding is preserved — type_ still deserializes via an alias.

@leighmcculloch leighmcculloch changed the title Emit unescaped JSON key for type fields Emit unescaped JSON key for type fields Jul 23, 2026
@leighmcculloch
leighmcculloch marked this pull request as ready for review July 24, 2026 05:27
Copilot AI review requested due to automatic review settings July 24, 2026 05:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates generated Rust types and JSON schemas so XDR type fields serialize per SEP-51 while retaining legacy deserialization support.

Changes:

  • Adds generated Serde/Schemars field renames from type_ to type.
  • Preserves type_ as a deserialization alias.
  • Regenerates affected Rust types and JSON schemas with tests.

Reviewed changes

Copilot reviewed 37 out of 44 changed files in this pull request and generated no comments.

Show a summary per file
File Description
xdr-generator-rust/generator/src/naming.rs Detects keyword-escaped JSON fields.
xdr-generator-rust/generator/src/generator.rs Propagates JSON rename metadata.
xdr-generator-rust/generator/src/output.rs Adds field rename metadata.
xdr-generator-rust/generator/src/tests/naming.rs Tests rename detection.
xdr-generator-rust/generator/templates/struct.rs.jinja Emits Serde aliases and schema renames.
tests/serde.rs Tests current and legacy JSON keys.
src/generated/contract_event.rs Regenerates ContractEvent.
src/generated/dont_have.rs Regenerates DontHave.
src/generated/sc_spec_event_param_v0.rs Regenerates event parameters.
src/generated/sc_spec_function_input_v0.rs Regenerates function inputs.
src/generated/sc_spec_udt_struct_field_v0.rs Regenerates struct fields.
src/generated/sc_spec_udt_union_case_tuple_v0.rs Regenerates union tuple cases.
src/generated/serialized_binary_fuse_filter.rs Regenerates binary fuse filters.
xdr-json/AuthenticatedMessage.json Updates embedded schema key.
xdr-json/AuthenticatedMessageV0.json Updates embedded schema key.
xdr-json/ContractEvent.json Updates schema key.
xdr-json/DiagnosticEvent.json Updates embedded schema key.
xdr-json/DontHave.json Updates schema key.
xdr-json/InvokeHostFunctionSuccessPreImage.json Updates embedded schema key.
xdr-json/LedgerCloseMeta.json Updates embedded schema key.
xdr-json/LedgerCloseMetaBatch.json Updates embedded schema key.
xdr-json/LedgerCloseMetaV0.json Updates embedded schema key.
xdr-json/LedgerCloseMetaV1.json Updates embedded schema key.
xdr-json/LedgerCloseMetaV2.json Updates embedded schema key.
xdr-json/OperationMetaV2.json Updates embedded schema key.
xdr-json/ScSpecEntry.json Updates embedded schema keys.
xdr-json/ScSpecEventParamV0.json Updates schema key.
xdr-json/ScSpecEventV0.json Updates embedded schema key.
xdr-json/ScSpecFunctionInputV0.json Updates schema key.
xdr-json/ScSpecFunctionV0.json Updates embedded schema key.
xdr-json/ScSpecUdtStructFieldV0.json Updates schema key.
xdr-json/ScSpecUdtStructV0.json Updates embedded schema key.
xdr-json/ScSpecUdtUnionCaseTupleV0.json Updates schema key.
xdr-json/ScSpecUdtUnionCaseV0.json Updates embedded schema key.
xdr-json/ScSpecUdtUnionV0.json Updates embedded schema key.
xdr-json/SerializedBinaryFuseFilter.json Updates schema key.
xdr-json/SorobanTransactionMeta.json Updates embedded schema key.
xdr-json/StellarMessage.json Updates embedded schema key.
xdr-json/TransactionEvent.json Updates embedded schema key.
xdr-json/TransactionMeta.json Updates embedded schema key.
xdr-json/TransactionMetaV3.json Updates embedded schema key.
xdr-json/TransactionMetaV4.json Updates embedded schema key.
xdr-json/TransactionResultMeta.json Updates embedded schema key.
xdr-json/TransactionResultMetaV1.json Updates embedded schema key.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@leighmcculloch
leighmcculloch added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit d4d4581 Jul 24, 2026
462 checks passed
@leighmcculloch
leighmcculloch deleted the fix-xdr-json-type-field-key branch July 24, 2026 16:37
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.

JSON output uses "type_" for XDR fields named "type", diverging from SEP-51

3 participants