Skip to main content

ResolvedDoc

Struct ResolvedDoc 

Source
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

§Convenience iterators

Inspect specific error categories without importing RefError:

Fields§

§value: Value

The 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

Source

pub fn is_complete(&self) -> bool

Returns true if all $ref pointers were successfully resolved.

Source

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");
Source

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"]);
Source

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"));
Source

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"));
Source

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

Source§

fn clone(&self) -> ResolvedDoc

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResolvedDoc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.