Skip to content

refactor: use schema extensions for protocol-aware JSON/CBOR naming - #353

Open
jterapin wants to merge 14 commits into
serde-data-drivenfrom
schema-extensions
Open

refactor: use schema extensions for protocol-aware JSON/CBOR naming#353
jterapin wants to merge 14 commits into
serde-data-drivenfrom
schema-extensions

Conversation

@jterapin

@jterapin jterapin commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Context

This is the second PR in the stack and should be reviewed on top of #351.

PR #351 introduced a temporary reverse lookup on StructureShape so JSON and CBOR structure serde could operate on the actual payload or input data. That lookup is protocol-blind: a jsonName wire key can resolve even when the active protocol should be using the modeled member name instead.

This PR replaces that stopgap with lazy, protocol-aware naming resolution for JSON and CBOR.

What changed

  • Added Smithy::Schema::Extension for lazy member indexes keyed by modeled member names.
  • Added Smithy::Json::Extension for jsonName-aware lookup used only when JSON serde opts into json_name behavior.
  • MemberShape now uses model_name as the primary modeled member identity.
  • Codegen now emits model_name: and symbolized serde trait keys needed by the new lookup path.
  • Removed the eager schema-wide reverse-map approach from the previous stopgap.

Behavior after this change

  • JSON with json_name: true uses jsonName
  • JSON with json_name: false uses the modeled member name
  • CBOR uses the modeled member name
  • Union __type is only preserved when it is explicitly modeled through jsonName

Explicit non-goals

  • No XML behavior changes in this PR
  • No Query behavior changes in this PR

Compatibility note

MemberShape#initialize still falls back from model_name: to location_name: for downstream compatibility. That fallback is currently needed because some downstream Query/XML wrapper-member paths still construct members with location_name:.

Testing

  • bundle exec rake smithy-schema:spec
  • bundle exec rake smithy-json:spec
  • bundle exec rake smithy-cbor:spec
  • bundle exec rake smithy:spec:unit
  • bundle exec rake smithy:spec:protocols smithy:rbs:protocols
  • bundle exec rake smithy-schema:rbs

--
Written with AI assistance and reviewed by jterapin.

@jterapin
jterapin changed the base branch from main to serde-data-driven August 19, 2026 22:27
@jterapin jterapin changed the title [DRAFT] feature: implement schema extensions [DRAFT] feature: use schema extensions for JSON and CBOR naming Aug 20, 2026
@jterapin jterapin changed the title [DRAFT] feature: use schema extensions for JSON and CBOR naming refactor: use schema extensions for protocol-aware JSON/CBOR naming Aug 20, 2026
@jterapin
jterapin marked this pull request as ready for review August 20, 2026 15:55
@jterapin
jterapin requested a review from a team as a code owner August 20, 2026 15:55
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