pub fn resolve(root: &Value) -> Result<ResolvedDoc, ResolveError>Expand description
Resolve all $ref pointers in a JSON document.
Returns Ok(ResolvedDoc) with the expanded document and any
non-fatal ref errors, or Err(ResolveError) on fatal failure
(e.g. depth limit exceeded).
§Behavior
- Internal refs (
#/…) are expanded via JSON Pointer (RFC 6901). - External refs (e.g.
https://…) are reported asRefError::Externaland preserved as raw{"$ref": "…"}objects. - Cycles are detected per resolution path and reported as
RefError::Cycle. $refalongside sibling keys (OpenAPI 3.1): sibling keys are merged into the resolved value. On key conflict, sibling keys override the resolved target. If the resolved target is not a JSON object, sibling keys cannot be merged and are reported asRefError::SiblingKeysIgnored.- Non-string
$ref: if the$refvalue is not a JSON string (e.g.{"$ref": 123}), the object is treated as a regular object and no resolution is attempted.
§Example
use serde_json::json;
use openapi_deref::resolve;
let spec = json!({
"components": { "schemas": {
"User": { "type": "object", "properties": { "name": { "type": "string" } } }
}},
"schema": { "$ref": "#/components/schemas/User" }
});
let doc = resolve(&spec).unwrap();
assert!(doc.is_complete());
assert_eq!(doc.value["schema"]["type"], "object");