Skip to content

2-5 steps of the scheam-holds-data proposal - #266

Open
avkonst wants to merge 2 commits into
mainfrom
andrey/schema-holds-data
Open

avkonst wants to merge 2 commits into
mainfrom
andrey/schema-holds-data

Conversation

@avkonst

@avkonst avkonst commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Steps 2 to 5 of the schema holds data, reflectapi holds meaning. reflectapi-schema keeps only the data that describes an API; what that data means moves back into reflectapi, split by who needs it. Step 1, diff as reflectapi::diff, follows once #256 is rebased onto this.

Changes

wire back in reflectapi, split in two

#263 moved wire into reflectapi-schema so diff could reach it. This moves it back, and splits it along the line its users already follow:

Module What it says Built with
reflectapi::wire: shape, key, layout, headers how serde lays out a type: newtype or struct, the keys a field writes, what #[serde(flatten)] adds, the headers a headers type reads builder or codegen (and diff)
reflectapi::contract: presence, nullability, format what a client may send and must accept: whether a key may be absent, whether null is allowed, what a primitive's string is codegen (and diff)
  • One direction: contract builds on wire, and nothing in wire uses contract.
  • The builder keeps its dependency on wire. The server reads a route's headers with wire::headers, so it reads exactly the headers clients send.
  • A server's build no longer carries the client rules: contract isn't compiled without codegen.
  • Visibility: wire stays #[doc(hidden)] pub. With builder alone, the parts of layout only codegen uses would otherwise warn as unused. contract is pub(crate).
  • Diagram: the architecture page gains a dependency diagram showing which feature turns on what.

Breaking: Primitive::format removed

A primitive's format always followed from its name, since uuid::Uuid is a UUID. The generators already fell back to a table keyed by name, which is now the only source.

  • Gone: Primitive::format, Primitive::with_format, and the formats the uuid, chrono, url and rust_decimal impls set.
  • Schema JSON stays at format 1. A 0.26 schema's format keys are ignored, and a 0.26 reader derives formats from names, as it did for a schema without them. SCHEMA_FORMAT_VERSION's doc records the exception. A test reads a 0.26 primitive with "format": "uuid".
  • Generated clients and OpenAPI are unchanged. Schema snapshots only lose their "format" keys.
  • A user's own primitive maps its format in the tool instead, for example with a TypeScript type override (TypeScript: type overrides chosen by the client #262).

contract::format answers per serialization format

wire_form(name, SerializationMode) returns String { format } or Bytes { length }. A uuid::Uuid is a uuid string in JSON and 16 bytes in MessagePack, because its Serialize checks is_human_readable(). string_format is the JSON shortcut that OpenAPI and TypeScript use.

No tool asks for the MessagePack form yet. Compatibility is still judged on types, whatever the format.

On the Wire gains a note for servers that accept MessagePack: uuid's Deserialize takes only bytes there, so read such a field with a deserialize_with that takes a string or 16 bytes. The example is a book doctest that checks both forms with rmp-serde.

Const arguments documented

TypeReference::arguments now says a const generic's value is written as the reference's name: [u8; 3] is std::array::Array<u8, "3">. A reader that doesn't know the type follows its fallback.

Book

  • Diagrams: a mermaid block can tag nodes accent, crate or planned. The book's CSS draws them in its palette, the reflectapi orange for the subject and frames, in light and dark themes. Elsewhere the tags are ignored.
  • Fix: clipped labels. Diagram labels were clipped because Mermaid measured text before Geist loaded. The script now loads the font first.

Not in this PR

Checks

  • cargo fmt, and cargo clippy --workspace --all-targets --all-features -D warnings.
  • CI=1 cargo test --workspace --all-features: 526 passed, generated TypeScript and Rust type-checked.
  • reflectapi without default features and with builder, codegen, json, builder,json and builder plus the type features: no warnings.
  • The book builds, and its 37 doctests pass.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

This branch has not been deployed

No deployments
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