Repository navigation
Conversation
akozlev
force-pushed
the
angel/schema-diff
branch
2 times, most recently
from
November 23, 2026 11:26
c50d212 to
b6e777e
Compare
`reflectapi diff OLD NEW` compares two schemas function by function, in both directions: a request breaks when the server stops accepting what an old client sends, a response when an old client can no longer read what the server sends. Types are compared by the JSON they read and write, not by name: generic arguments are substituted, transparent wrappers unwrapped and flattened fields inlined, so renaming or restructuring a type without changing its JSON is compatible. It follows serde where the schema alone would mislead, such as a request leaving out an `Option`, a flattened map being empty, or an internally tagged unit variant gaining fields. Removing a deprecated item is judged by its sunset (`--today`), optionally by how long it has been deprecated (`--min-notice-days`) and by an earlier schema in which it must already be deprecated (`--deprecated-in`), which can't be backdated as `deprecated_since` can. Each change has a stable kind and key, so CI can accept a known break with a `- <key>: <reason>` line in a file passed to `--acknowledged`, and downgrade kinds of break to warnings with `--warn`. The command exits 1 for an unaccepted break and 2 when it can't diff. The same check is `reflectapi_schema::diff`.
akozlev
force-pushed
the
angel/schema-diff
branch
from
November 24, 2026 21:20
b6e777e to
8f5d4d7
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
reflectapi diff OLD NEW, which reports the changes between tworeflectapi.jsonschemas that break existing clients, so CI can catch a breaking API change before it ships.The problem
A committed
reflectapi.jsonshows that the contract changed, but not whether the change breaks clients. Running an OpenAPI diff tool such as oasdiff on the generatedopenapi.jsonworks poorly. The OpenAPI output wraps generics, flattened fields and tagged enums inallOf/oneOf, so a pure restructure reads as removed properties. A description edit can reorder untitledoneOfbranches, and a reflectapi upgrade that changes only the generated OpenAPI reads as a break. Real breaks inside aoneOfare reported only as warnings, or not at all.What it does
Schemas are compared function by function, in both directions:
readonly(so no longer acceptingGET), dropping a serialization format, or switching between a single response and a stream.Types are compared by the JSON they read and write, not by name. Generic arguments are substituted, transparent wrappers unwrapped and flattened fields inlined, so renaming or restructuring a type without changing its JSON is compatible. It also follows serde where the schema alone would mislead:
Optionfield, which serde reads asNone, unless the field has its owndeserialize_with.#[reflectapi(open)]enum, or one with a#[serde(other)]variant, can gain response variants.Removing deprecated items
Removing something clients rely on (a function, a required response field, a request variant, or a field of a request struct with
#[serde(deny_unknown_fields)], which the schema now records) is compatible once it was deprecated and its sunset has come:--today DATE: the date removals are judged on. Defaults to today in UTC.--min-notice-days N: also requiresdeprecated_sinceto be at least N days earlier.--deprecated-in SCHEMA: also requires the item to have been deprecated already in an earlier schema, such as the default branch a week back. Unlikedeprecated_since, that can't be backdated in the same change that removes the item. Fields and variants are matched by the type that declares them, so a route added since can still remove them.For CI
kind(required-field-removed,variant-added, …) and akey,<function> <location> [<kind>]. A type used in several places is reported at each, so a key doesn't move when another use is added.--acknowledged PATH: files, or directories of.mdfiles, of- <key>: <reason>lines that accept known breaks. A malformed line, or one that still holds the placeholder, is an error; an acknowledgement that matches nothing is a warning.--warn KIND: reports a kind of break as a warning, for a pipeline whose policy allows it, such as new response variants.--include-tags/--exclude-tags: choose functions as codegen does, so a diff can match a published spec.--json: every change with its severity, kind, key and deprecation dates.The same check is available as a library,
reflectapi_schema::diff(diff,parse_acknowledgements,acknowledge).Testing
reflectapi-demo/src/tests/diff.rs: real types with the derives and inlineinstasnapshots, covering optional and defaulted fields, nullability, flattened structs, enums and maps, tagged and open enums, generics, newtypes,uuid, numbers and deprecation.reflectapi-schema/tests/diff.rsfor what the derives can't express directly: route changes, bodies and headers, primitive fallbacks and formats, removal rules, acknowledgements, tags and--warn.allOf/oneOfrestructures, description-only edits and codegen-only changes above), and caught real breaks oasdiff missed: a struct replacing a tagged enum, a response field becoming optional, and a request field becoming required inside aoneOf.Caveats
🤖 Generated with Claude Code
https://claude.ai/code/session_01B5dwkNALJW4jaXoLBCzp5A