Struct jsonschema::output::Output
source · [−]pub struct Output<'a, 'b> { /* private fields */ }
Expand description
The output format resulting from the application of a schema. This can be converted into various representations based on the definitions in https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.12.2
Currently only the “flag” and “basic” output formats are supported
Implementations
sourceimpl<'a, 'b> Output<'a, 'b>
impl<'a, 'b> Output<'a, 'b>
sourcepub fn flag(&self) -> bool
pub fn flag(&self) -> bool
Indicates whether the schema was valid, corresponds to the “flag” output format
sourcepub fn basic(&self) -> BasicOutput<'a>
pub fn basic(&self) -> BasicOutput<'a>
Output a list of errors and annotations for each element in the schema
according to the basic output format. BasicOutput
implements
serde::Serialize
in a manner which conforms to the json core spec so
one way to use this is to serialize the BasicOutput
and examine the
JSON which is produced. However, for rust programs this is not
necessary. Instead you can match on the BasicOutput
and examine the
results. To use this API you’ll need to understand a few things:
Regardless of whether the the schema validation was successful or not
the BasicOutput
is a sequence of OutputUnit
s. An OutputUnit
is
some metadata about where the output is coming from (where in the schema
and where in the instance). The difference between the
BasicOutput::Valid
and BasicOutput::Invalid
cases is the value which
is associated with each OutputUnit
. For Valid
outputs the value is
an annotation, whilst for Invalid
outputs it’s an ErrorDescription
(a String
really).
Examples
let output: BasicOutput = schema.apply(&instance).basic();
match output {
BasicOutput::Valid(annotations) => {
for annotation in annotations {
println!(
"Value: {} at path {}",
annotation.value(),
annotation.instance_location()
)
}
},
BasicOutput::Invalid(errors) => {
for error in errors {
println!(
"Error: {} at path {}",
error.error_description(),
error.instance_location()
)
}
}
}