pub struct Compiler { /* private fields */ }
Expand description
JsonSchema compiler.
Implementations§
source§impl Compiler
impl Compiler
pub fn new() -> Self
sourcepub fn set_default_draft(&mut self, d: Draft)
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.
sourcepub fn enable_format_assertions(&mut self)
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
sourcepub fn enable_content_assertions(&mut self)
pub fn enable_content_assertions(&mut self)
Always enable content assertions.
content assertions include keywords:
- contentEncoding
- contentMediaType
- contentSchema
Default Behavior is always disabled.
sourcepub fn register_url_loader(
&mut self,
scheme: &'static str,
url_loader: Box<dyn UrlLoader>
)
pub fn register_url_loader( &mut self, scheme: &'static str, url_loader: Box<dyn UrlLoader> )
sourcepub fn register_format(&mut self, format: Format)
pub fn register_format(&mut self, format: Format)
Registers custom format
Note
regex
format cannot be overridden- format assertions are disabled for draft >= 2019-09.
see
Compiler::enable_format_assertions
sourcepub fn register_content_encoding(&mut self, decoder: Decoder)
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
sourcepub fn register_content_media_type(&mut self, media_type: MediaType)
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
sourcepub fn add_resource(
&mut self,
url: &str,
json: Value
) -> Result<bool, CompileError>
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
sourcepub fn compile(
&mut self,
loc: &str,
target: &mut Schemas
) -> Result<SchemaIndex, CompileError>
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