pub fn redact_value(value: Value) -> ValueRedactionBuilderAvailable on crate feature
redaction only.Expand description
Create a redaction builder for an arbitrary JSON value.
This allows applying the same redaction patterns used for response bodies to any JSON value, such as the full OpenAPI specification.
§Path Syntax
The syntax is auto-detected based on the path prefix:
$...→ JSONPath (RFC 9535) - supports wildcards/...→ JSON Pointer (RFC 6901) - exact path only
§Example
use clawspec_core::redact_value;
use serde_json::json;
let value = json!({
"id": "550e8400-e29b-41d4-a716-446655440000",
"created_at": "2024-12-28T10:30:00Z"
});
let redacted = redact_value(value)
.redact("/id", "ENTITY_ID").unwrap()
.redact("/created_at", "TIMESTAMP").unwrap()
.finish();
assert_eq!(redacted["id"], "ENTITY_ID");
assert_eq!(redacted["created_at"], "TIMESTAMP");§Use Case: Stabilizing OpenAPI Specifications
use clawspec_core::redact_value;
use serde_json::json;
let openapi_json = json!({
"paths": {
"/users": {
"get": {
"responses": {
"200": {
"content": {
"application/json": {
"example": {
"id": "real-uuid",
"created_at": "2024-12-28T10:30:00Z"
}
}
}
}
}
}
}
}
});
// Stabilize all dynamic values in the OpenAPI spec
let stabilized = redact_value(openapi_json)
.redact("$..example.id", "ENTITY_ID").unwrap()
.redact("$..example.created_at", "TIMESTAMP").unwrap()
.finish();