pub struct ResolvedDoc {
pub value: Value,
pub ref_errors: Vec<RefError>,
}Expand description
Result of resolving all $ref pointers in a JSON document.
Contains the resolved document alongside any non-fatal ref errors.
§Checking results
is_complete()—truewhen zero errorsinto_value()— strict conversion toResult<Value, _>
§Convenience iterators
Inspect specific error categories without importing RefError:
cycles()— circular$refstringsmissing_refs()— not-found$refstringsexternal_refs()— unsupported external URI stringssibling_keys_ignored()— sibling keys dropped (non-object target)
Fields§
§value: ValueThe document with all resolvable $ref pointers expanded inline.
Unresolvable refs are preserved as raw {"$ref": "..."} objects.
ref_errors: Vec<RefError>Non-fatal ref errors encountered during resolution.
Implementations§
Source§impl ResolvedDoc
impl ResolvedDoc
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true if all $ref pointers were successfully resolved.
Sourcepub fn into_value(self) -> Result<Value, PartialResolveError>
pub fn into_value(self) -> Result<Value, PartialResolveError>
Converts into the resolved Value if no ref errors were encountered.
On failure, the returned PartialResolveError still provides access
to the partially-resolved document via its value field.
§Example
let spec = json!({
"components": { "schemas": { "X": { "type": "string" } } },
"f": { "$ref": "#/components/schemas/X" }
});
let value = resolve(&spec).unwrap().into_value().unwrap();
assert_eq!(value["f"]["type"], "string");Sourcepub fn cycles(&self) -> impl Iterator<Item = &str> + '_
pub fn cycles(&self) -> impl Iterator<Item = &str> + '_
Iterates over $ref strings that form circular references.
§Example
let spec = json!({
"components": { "schemas": {
"Node": { "properties": { "child": { "$ref": "#/components/schemas/Node" } } }
}},
"root": { "$ref": "#/components/schemas/Node" }
});
let doc = resolve(&spec).unwrap();
let cycles: Vec<&str> = doc.cycles().collect();
assert_eq!(cycles, ["#/components/schemas/Node"]);Sourcepub fn external_refs(&self) -> impl Iterator<Item = &str> + '_
pub fn external_refs(&self) -> impl Iterator<Item = &str> + '_
Iterates over external $ref strings (unsupported by this resolver).
§Example
let spec = json!({ "ext": { "$ref": "https://example.com/schema.json" } });
let doc = resolve(&spec).unwrap();
assert_eq!(doc.external_refs().next(), Some("https://example.com/schema.json"));Sourcepub fn sibling_keys_ignored(&self) -> impl Iterator<Item = &str> + '_
pub fn sibling_keys_ignored(&self) -> impl Iterator<Item = &str> + '_
Iterates over $ref strings where sibling keys were dropped because
the resolved target was not a JSON object.
§Example
let spec = json!({
"definitions": { "val": 42 },
"target": { "$ref": "#/definitions/val", "description": "dropped" }
});
let doc = resolve(&spec).unwrap();
assert_eq!(doc.sibling_keys_ignored().next(), Some("#/definitions/val"));Sourcepub fn missing_refs(&self) -> impl Iterator<Item = &str> + '_
pub fn missing_refs(&self) -> impl Iterator<Item = &str> + '_
Iterates over $ref strings whose targets were not found.
§Example
let spec = json!({ "broken": { "$ref": "#/does/not/exist" } });
let doc = resolve(&spec).unwrap();
assert_eq!(doc.missing_refs().next(), Some("#/does/not/exist"));Trait Implementations§
Source§impl Clone for ResolvedDoc
impl Clone for ResolvedDoc
Source§fn clone(&self) -> ResolvedDoc
fn clone(&self) -> ResolvedDoc
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more