Struct boon::Compiler

source ·
pub struct Compiler { /* private fields */ }
Expand description

JsonSchema compiler.

Implementations§

source§

impl Compiler

source

pub fn new() -> Self

source

pub fn set_default_draft(&mut self, d: Draft)

Overrides the draft used to compile schemas without explicit $schema field.

By default this library uses latest draft supported.

The use of this option is HIGHLY encouraged to ensure continued correct operation of your schema. The current default value will not stay the same over time.

source

pub fn enable_format_assertions(&mut self)

Always enable format assertions.

Default Behavior
  • for draft-07 and earlier: enabled
  • for draft/2019-09: disabled, unless metaschema says format vocabulary is required
  • for draft/2020-12: disabled, unless metaschema says format-assertion vocabulary is required
source

pub fn enable_content_assertions(&mut self)

Always enable content assertions.

content assertions include keywords:

  • contentEncoding
  • contentMediaType
  • contentSchema

Default Behavior is always disabled.

source

pub fn register_url_loader( &mut self, scheme: &'static str, url_loader: Box<dyn UrlLoader> )

Registers UrlLoader for given url scheme

Note
  • loader for file scheme is included by default and
  • all standard meta-schemas from http(s)://json-schema.org are loaded internally without network access
source

pub fn register_format(&mut self, format: Format)

Registers custom format

Note
source

pub fn register_content_encoding(&mut self, decoder: Decoder)

Registers custom contentEncoding

Note that content assertions are disabled by default. see Compiler::enable_content_assertions

source

pub fn register_content_media_type(&mut self, media_type: MediaType)

Registers custom contentMediaType

Note that content assertions are disabled by default. see Compiler::enable_content_assertions

source

pub fn add_resource( &mut self, url: &str, json: Value ) -> Result<bool, CompileError>

Adds schema resource which used later in reference resoltion If you do not know which schema resources required, then use UrlLoader.

The argument loc can be file path or url. any fragment in url is ignored.

If resource with same url already loaded, it returns false.

Errors

returns CompileError if basic validations fail, such as

  • url parsing
  • duplicate anchor or id
  • metaschema resolution etc
source

pub fn compile( &mut self, loc: &str, target: &mut Schemas ) -> Result<SchemaIndex, CompileError>

Compile given loc into target and return an identifier to the compiled schema.

the argument loc can be file path or url with optional fragment. examples: http://example.com/schema.json#/defs/address, samples/schema_file.json#defs/address

if loc is already compiled, it simply returns the same SchemaIndex

Trait Implementations§

source§

impl Default for Compiler

source§

fn default() -> Compiler

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.