Expand description
Snapshot assertions for generated JSON: assert_openapi_snapshot
compares an app’s OpenAPI document with a file committed beside the
tests, so a change to the API shows up in review as a change to that
file.
Both sides are normalized before comparing — parsed, object keys sorted, printed with two-space indentation — so key order and whitespace never count, and a mismatch fails with a line diff of the normalized texts.
With RWS_UPDATE_SNAPSHOTS=1 in the environment (any value but empty,
0 or false) the assertion writes the normalized document to the file
instead — creating it and its directory if needed — and passes:
RWS_UPDATE_SNAPSHOTS=1 cargo test # accept the current documents
git diff tests/snapshots/ # review what changedA missing file fails (with that hint) when the variable isn’t set, so a
CI run never passes by writing its own snapshot. Relative paths are
relative to the working directory, which under cargo test is the
package’s root.
Constants§
- UPDATE_
VARIABLE - The environment variable that makes snapshot assertions write instead of compare.
Traits§
- Open
ApiSource - Something an OpenAPI document can be read from.
Functions§
- assert_
json_ snapshot assert_openapi_snapshotfor any JSON document (a JSON Schema, an MCPtools/listresult, a response body).- assert_
openapi_ snapshot - Compare an OpenAPI document with the snapshot at
path(see the module docs for normalization andRWS_UPDATE_SNAPSHOTS).sourceis the document’s text (app.openapi_spec(&config)), aTestResponseof it, or aTestClientwhose app serves/openapi.json.