Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver<'a> {
    pub components: BTreeMap<String, Value>,
    pub gaps: Vec<Gap>,
    pub aux_resolved: BTreeSet<String>,
    /* private fields */
}
Expand description

Walks rustdoc JSON, emitting JSON Schema and collecting Gaps.

Resolution may span several documents (see Docs), but components, the component-name registry and the cycle-breaking stack are shared across all of them: one type gets one component wherever it was defined.

Fields§

§components: BTreeMap<String, Value>

Named schemas, emitted as components/schemas in OpenAPI.

§gaps: Vec<Gap>§aux_resolved: BTreeSet<String>

Canonical paths walked out of an auxiliary document. Resolved, so deliberately not gaps — reported only to say where they came from.

Implementations§

Source§

impl<'a> Resolver<'a>

Source

pub fn new( docs: impl Into<Docs<'a>>, table: &'a TypeTable, ) -> Result<Self, String>

Build a resolver over a parsed rustdoc JSON document, or over a primary document plus its workspace-local companions (Docs).

Source

pub fn find_type_id(&self, name: &str) -> Option<Value>

Find a struct or enum by its plain name, for attribute overrides that name a type rather than pointing at a signature.

Source

pub fn find_by_path(&self, canonical: &str) -> Option<&'a Value>

Find an item by its fully-qualified path, e.g. app::routes::create.

#[route] records handler ids as module_path!()::fn_name, which is exactly the path rustdoc reports, so route lookup is a direct match.

Source

pub fn resolve_by_name(&mut self, name: &str, at: &str) -> Option<Value>

Resolve a struct or enum named in an attribute, searching this crate first and then the workspace-local documents.

Source

pub fn is_option(ty: &Value) -> bool

True when a type is Option<..>, which makes a field optional on the wire independently of the schema its inner type produces.

Source

pub fn resolve(&mut self, ty: &Value, subst: &Subst, at: &str) -> Value

Resolve one rustdoc type node into a JSON Schema.

at is a human-readable location (Item.when) used for gap reports.

Auto Trait Implementations§

§

impl<'a> Freeze for Resolver<'a>

§

impl<'a> RefUnwindSafe for Resolver<'a>

§

impl<'a> Send for Resolver<'a>

§

impl<'a> Sync for Resolver<'a>

§

impl<'a> Unpin for Resolver<'a>

§

impl<'a> UnsafeUnpin for Resolver<'a>

§

impl<'a> UnwindSafe for Resolver<'a>

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> 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, 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.