Struct jsonschema::CompilationOptions [−][src]
pub struct CompilationOptions { /* fields omitted */ }
Full configuration to guide the JSONSchema
compilation.
Using a CompilationOptions
instance you can configure the supported draft,
content media types and more (check the exposed methods)
Implementations
impl CompilationOptions
[src]
impl CompilationOptions
[src]pub fn compile<'a>(
&self,
schema: &'a Value
) -> Result<JSONSchema<'a>, CompilationError>
[src]
&self,
schema: &'a Value
) -> Result<JSONSchema<'a>, CompilationError>
Compile schema
into JSONSchema
using the currently defined options.
pub fn with_draft(&mut self, draft: Draft) -> &mut Self
[src]
Ensure that the schema is going to be compiled using the defined Draft.
options.with_draft(Draft::Draft4);
pub fn with_content_media_type(
&mut self,
media_type: &'static str,
media_type_check: fn(_: &str) -> bool
) -> &mut Self
[src]
&mut self,
media_type: &'static str,
media_type_check: fn(_: &str) -> bool
) -> &mut Self
Ensure that compiled schema is going to support the provided content media type.
Arguments:
media_type
: Name of the content media type to support (ie. “application/json”)media_type_check
: Method checking the validity of the input string according to the media type. The method should returntrue
if the input is valid,false
otherwise.
Example:
fn check_custom_media_type(instance_string: &str) -> bool { // In reality the check might be a bit more different ;) instance_string != "not good" } // Add support for application/jsonschema-test options.with_content_media_type("application/jsonschema-test", check_custom_media_type);
pub fn without_content_media_type_support(
&mut self,
media_type: &'static str
) -> &mut Self
[src]
&mut self,
media_type: &'static str
) -> &mut Self
Ensure that compiled schema is not supporting the provided content media type.
// Disable support for application/json (which is supported by jsonschema crate) options.without_content_media_type_support("application/json");
pub fn with_content_encoding(
&mut self,
content_encoding: &'static str,
content_encoding_check: fn(_: &str) -> bool,
content_encoding_converter: fn(_: &str) -> Result<Option<String>, ValidationError<'static>>
) -> &mut Self
[src]
&mut self,
content_encoding: &'static str,
content_encoding_check: fn(_: &str) -> bool,
content_encoding_converter: fn(_: &str) -> Result<Option<String>, ValidationError<'static>>
) -> &mut Self
Ensure that compiled schema is going to support the provided content encoding.
Arguments:
content_encoding
: Name of the content encoding to support (ie. “base64”)content_encoding_check
: Method checking the validity of the input string according to content encoding. The method should returntrue
if the input is valid,false
otherwise.content_encoding_converter
: Method converting the input string into a string representation (generally output of the decoding of the content encoding). The method should return:Err(ValidationError instance)
: in case of ajsonschema
crate supported error (obtained via?
orFrom::from
APIs)Ok(None)
: if the input string is not valid according to the content encodingOk(Some(content))
: if the input string is valid according to the content encoding,content
will contain the string representation of the decoded input
Example:
// The instance_string contains a number (representing the length of the string) // a space and then the string (whose length should match the expectation). // Example: "3 The" or "4 123" fn check_custom_encoding(instance_string: &str) -> bool { if let Some(first_space_index) = instance_string.find(' ') { if let Ok(value) = instance_string[..first_space_index].parse::<u64>() { return instance_string[first_space_index + 1..].chars().count() == value as usize; } } false } fn converter_custom_encoding(instance_string: &str) -> Result<Option<String>, ValidationError<'static>> { if let Some(first_space_index) = instance_string.find(' ') { if let Ok(value) = instance_string[..first_space_index].parse::<u64>() { if instance_string[first_space_index + 1..].chars().count() == value as usize { return Ok(Some(instance_string[first_space_index + 1..].to_string())); } } } Ok(None) } // Add support for prefix-length-string options.with_content_encoding("prefix-length-string", check_custom_encoding, converter_custom_encoding);
pub fn without_content_encoding_support(
&mut self,
content_encoding: &'static str
) -> &mut Self
[src]
&mut self,
content_encoding: &'static str
) -> &mut Self
Ensure that compiled schema is not supporting the provided content encoding.
// Disable support for base64 (which is supported by jsonschema crate) options.without_content_encoding_support("base64");
pub fn with_meta_schemas(&mut self) -> &mut Self
[src]
Add meta schemas for supported JSON Schema drafts. It is helpful if your schema has references to JSON Schema meta-schemas:
{
"schema": {
"multipleOf": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf"
},
"maximum": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/maximum"
}
}
}
The example above is taken from the Swagger 2.0 JSON schema.
pub fn with_document(&mut self, id: String, document: Value) -> &mut Self
[src]
Add a new document to the store. It works as a cache to avoid making additional network
calls to remote schemas via the $ref
keyword.
Trait Implementations
impl Clone for CompilationOptions
[src]
impl Clone for CompilationOptions
[src]fn clone(&self) -> CompilationOptions
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for CompilationOptions
[src]
impl Default for CompilationOptions
[src]fn default() -> CompilationOptions
[src]
Auto Trait Implementations
impl RefUnwindSafe for CompilationOptions
impl RefUnwindSafe for CompilationOptions
impl Send for CompilationOptions
impl Send for CompilationOptions
impl Sync for CompilationOptions
impl Sync for CompilationOptions
impl Unpin for CompilationOptions
impl Unpin for CompilationOptions
impl UnwindSafe for CompilationOptions
impl UnwindSafe for CompilationOptions
Blanket Implementations
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,