pub struct SchemaRegistry { /* private fields */ }Expand description
Offline, reusable schema registry. A URL is an identity, never a field-name hint. Registration needs exclusive access; parsing and validation can run concurrently.
§Examples
use raster_style::{SchemaRegistry, TILE_SCHEMA_URL};
let registry = SchemaRegistry::new()?;
let style = registry.parse_json(r#"{
"version":"3.0", "renderer":{"type":"gray","bidx":[1]},
"extensions":["https://mapseekai.github.io/raster-style/extensions/raster/tile/v1.0.0/schema.json"],
"raster:tile":{"format":"png"}
}"#)?;
assert!(style.validation().complete);
style.require_extension_support(&[TILE_SCHEMA_URL])?;Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create an offline registry containing the core and official extension schemas.
§Errors
Returns E_CONFIG if an embedded resource cannot be initialized.
Sourcepub fn register(&mut self, schema: Value) -> Result<()>
pub fn register(&mut self, schema: Value) -> Result<()>
Register an immutable draft 2020-12 resource. Register referenced resources separately. Previously constructed styles retain their validation report snapshots.
§Errors
Returns a JSON/budget error for invalid input, or E_CONFIG for an invalid
schema identity, draft, resource, duplicate registration or poisoned cache.
Sourcepub fn resolve(
&mut self,
url: &str,
resolver: impl FnOnce(&str) -> Result<Value>,
) -> Result<()>
pub fn resolve( &mut self, url: &str, resolver: impl FnOnce(&str) -> Result<Value>, ) -> Result<()>
Explicit resolution only; callers own network policy, allowlists, budgets and timeouts.
The callback is invoked once and its returned $id must equal url exactly.
§Errors
Propagates callback and registration failures; invalid or mismatched identities return E_CONFIG.
Sourcepub fn parse_json(&self, text: &str) -> Result<Style>
pub fn parse_json(&self, text: &str) -> Result<Style>
Parse and normalize a style without changing the input text.
Unknown declarations are preserved with complete=false; this does not authorize execution.
§Errors
Returns JSON, budget, known-schema or static-semantic errors. A referenced
resource missing from an available schema returns E_SCHEMA_UNRESOLVED.
Sourcepub fn inspect_json(&self, text: &str) -> Result<ValidationReport>
pub fn inspect_json(&self, text: &str) -> Result<ValidationReport>
Parse a style and return an owned snapshot of its validation completeness.
§Errors
Returns the same errors as Self::parse_json; known errors are never preserved as success.
Sourcepub fn validate_json(&self, text: &str) -> Result<()>
pub fn validate_json(&self, text: &str) -> Result<()>
Full validation includes all declared schemas and static cross-field semantics.
Execution support must still be checked with Style::require_extension_support.
§Errors
Returns parsing/validation errors, including E_SCHEMA_UNRESOLVED when any
declared schema or required reference is unavailable.