pub struct Registry<'a> { /* private fields */ }Expand description
A registry of JSON Schema resources, each identified by their canonical URIs.
Registry is a prepared registry: add resources with Registry::new and
RegistryBuilder::add, then call RegistryBuilder::prepare to build the
reusable registry. To resolve $ref references directly, create a Resolver
from the prepared registry:
use referencing::Registry;
let schema = serde_json::json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/root",
"$defs": { "item": { "type": "string" } },
"items": { "$ref": "#/$defs/item" }
});
let registry = Registry::new()
.add("https://example.com/root", schema)?
.prepare()?;
let resolver = registry.resolver(referencing::uri::from_str("https://example.com/root")?);Implementations§
Source§impl<'a> Registry<'a>
impl<'a> Registry<'a>
pub fn new<'b>() -> RegistryBuilder<'b>
Sourcepub fn add<'b>(
&'b self,
uri: impl AsRef<str>,
resource: impl IntoRegistryResource<'b>,
) -> Result<RegistryBuilder<'b>, Error>where
'a: 'b,
pub fn add<'b>(
&'b self,
uri: impl AsRef<str>,
resource: impl IntoRegistryResource<'b>,
) -> Result<RegistryBuilder<'b>, Error>where
'a: 'b,
Add a resource to a prepared registry, returning a builder that must be prepared again.
§Errors
Returns an error if the URI is invalid.
Sourcepub fn extend<'b, I, U, T>(
&'b self,
pairs: I,
) -> Result<RegistryBuilder<'b>, Error>
pub fn extend<'b, I, U, T>( &'b self, pairs: I, ) -> Result<RegistryBuilder<'b>, Error>
Add multiple resources to a prepared registry, returning a builder that must be prepared again.
§Errors
Returns an error if any URI is invalid.
Sourcepub fn contains_resource(&self, uri: &str) -> bool
pub fn contains_resource(&self, uri: &str) -> bool
Returns true if the registry contains a resource at the given URI.
Returns false if the URI is malformed.
Sourcepub fn resolver(&self, base_uri: Uri<String>) -> Resolver<'_>
pub fn resolver(&self, base_uri: Uri<String>) -> Resolver<'_>
Creates a Resolver rooted at base_uri.
The returned resolver borrows from this registry and cannot outlive it.
Sourcepub fn find_vocabularies(&self, draft: Draft, contents: &Value) -> VocabularySet
pub fn find_vocabularies(&self, draft: Draft, contents: &Value) -> VocabularySet
Returns the vocabulary set draft puts in effect for a schema with the given contents.
A $schema naming a custom meta-schema is the one case where contents decides: its
$vocabulary is read from the registry. Never errors.
Sourcepub fn resolve_uri(
&self,
base: &Uri<&str>,
uri: &str,
) -> Result<Arc<Uri<String>>, Error>
pub fn resolve_uri( &self, base: &Uri<&str>, uri: &str, ) -> Result<Arc<Uri<String>>, Error>
Resolves uri against base and returns the resulting absolute URI.
Results are cached. Returns an error if base has no scheme or if
resolution fails.
§Errors
Returns an error if base has no schema or there is a fragment.