Skip to content

feat(types): ByteStrategy::Base64UrlUnpadded for RFC 7515 alphabets#21

Open
lightsofapollo wants to merge 2 commits into
mainfrom
worktree-base64url-unpadded
Open

feat(types): ByteStrategy::Base64UrlUnpadded for RFC 7515 alphabets#21
lightsofapollo wants to merge 2 commits into
mainfrom
worktree-base64url-unpadded

Conversation

@lightsofapollo
Copy link
Copy Markdown
Contributor

Summary

  • Adds a third [generator.types] byte variant, base64_url_unpadded, that swaps the inlined base64_serde helper's engine from STANDARD to URL_SAFE_NO_PAD (RFC 7515 §2). Per-field #[serde(with = \"base64_serde\")] attributes are unchanged — the alphabet is picked once at codec-emit time from the config, so the variant is opaque to call sites.
  • Driven by gpu-cli portal-schema work: JWK thumbprints, DPoP, and JOSE-adjacent pubkey fields don't round-trip through the standard padded alphabet. Without this, format: byte had to be specced as plain string with the alphabet documented in field descriptions.
  • Spec-global, not per-field. Specs that need to mix both alphabets in one file remain a follow-up (would need either two helper modules or a serde_with path discriminator).

What changed

File Change
src/type_mapping.rs New ByteStrategy::Base64UrlUnpadded variant; map_byte routes both Base64 variants through the same base64_serde codec name + TypeFeature::Base64.
src/generator.rs Helper-emission block reads self.config.types.byte and substitutes the engine identifier inside the inlined codec; single ENGINE binding replaces three literal STANDARD references.
src/lib.rs Re-exports ByteStrategy so external consumers can build custom configs.
tests/typed_scalars_test.rs Two integration tests: byte_url_unpadded_emits_url_safe_no_pad_engine (new variant emits URL_SAFE_NO_PAD, no STANDARD) and byte_default_emits_standard_engine (locks the historical default).
src/type_mapping.rs (tests) Two unit tests: codec-path reuse for the new variant and TOML parse of base64_url_unpadded.

Consumer usage

[generator.types]
byte = "base64_url_unpadded"

All format: byte fields in the spec then round-trip via URL-safe unpadded base64.

Test plan

  • cargo build --lib clean
  • cargo test — 51 binaries, 257 passed, 0 failed, 6 ignored
  • cargo clippy --lib clean (pre-existing -D warnings failures in tests/oneof_untagged_tests.rs are unrelated)
  • TOML key base64_url_unpadded round-trips through serde
  • Default Base64 path still emits STANDARD (no regression)
  • Downstream smoke: regenerate a portal spec with byte = \"base64_url_unpadded\" and confirm cargo check on the generated crate

Closes beads issue `openapi-generator-76h`.

🤖 Generated with Claude Code

lightsofapollo and others added 2 commits May 16, 2026 12:29
Adds a third `[generator.types] byte` variant that swaps the inlined
`base64_serde` helper's engine from `STANDARD` to `URL_SAFE_NO_PAD`.
Per-field `#[serde(with = "base64_serde")]` attributes are unchanged
— the alphabet is picked once at codec-emit time from the config.

Driven by gpu-cli portal-schema work (JWK thumbprints, DPoP, sealing
pubkeys) where the standard padded alphabet doesn't round-trip JOSE
fields. Spec-global, not per-field; specs that mix alphabets remain
a follow-up.

Closes beads openapi-generator-76h.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <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