pub struct Context<'r> {
pub root_schema: Option<&'r RootSchema>,
pub current_schema: Option<&'r YamlSchema>,
pub current_path: Vec<String>,
pub stream_started: bool,
pub stream_ended: bool,
pub errors: Rc<RefCell<Vec<ValidationError>>>,
pub fail_fast: bool,
pub resolving_refs: Rc<RefCell<HashSet<(String, usize)>>>,
pub schemas: Rc<RefCell<HashMap<String, Rc<RootSchema>>>>,
pub object_evaluated: Option<ObjectEvaluatedNames>,
pub array_unevaluated: Option<Rc<RefCell<ArrayUnevaluatedAnnotations>>>,
}Expand description
The validation context
Fields§
§root_schema: Option<&'r RootSchema>We use an Option here so tests can be run without a root schema
current_schema: Option<&'r YamlSchema>§current_path: Vec<String>§stream_started: bool§stream_ended: bool§errors: Rc<RefCell<Vec<ValidationError>>>§fail_fast: bool§resolving_refs: Rc<RefCell<HashSet<(String, usize)>>>Tracks ($ref, value_position) pairs currently being resolved to detect circular references.
The value position is the byte offset of the YAML value’s span start, so the same ref
applied to a nested value is allowed (legitimate recursion) while the same ref
on the same value is detected as a cycle.
schemas: Rc<RefCell<HashMap<String, Rc<RootSchema>>>>Cache of externally loaded schemas by absolute URI (without fragment) or $id when valid.
object_evaluated: Option<ObjectEvaluatedNames>Property names successfully evaluated for JSON Schema unevaluatedProperties (same instance).
array_unevaluated: Option<Rc<RefCell<ArrayUnevaluatedAnnotations>>>Array annotation state for JSON Schema unevaluatedItems (same instance).
Implementations§
Source§impl<'r> Context<'r>
impl<'r> Context<'r>
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if there are any errors in the context
pub fn new(fail_fast: bool) -> Context<'r>
pub fn get_sub_context(&self) -> Context<'r>
Sourcepub fn get_sub_context_fresh_eval(&self) -> Context<'r>
pub fn get_sub_context_fresh_eval(&self) -> Context<'r>
Like [get_sub_context], but with fresh unevaluated annotation carriers (for anyOf / oneOf branches).
pub fn with_root_schema( root_schema: &'r RootSchema, fail_fast: bool, ) -> Context<'r>
Sourcepub fn with_root_schema_and_schemas(
root_schema: &'r RootSchema,
fail_fast: bool,
schemas: HashMap<String, Rc<RootSchema>>,
) -> Context<'r>
pub fn with_root_schema_and_schemas( root_schema: &'r RootSchema, fail_fast: bool, schemas: HashMap<String, Rc<RootSchema>>, ) -> Context<'r>
Create a context with root schema and pre-loaded schemas (e.g. for CLI -f multiple).
pub fn add_doc_error<V: Into<String>>(&self, error: V)
Sourcepub fn add_error<V: Into<String>>(&self, marked_yaml: &MarkedYaml<'_>, error: V)
pub fn add_error<V: Into<String>>(&self, marked_yaml: &MarkedYaml<'_>, error: V)
Adds an error message to the current context, with the current path and with location marker
Sourcepub fn extend_errors(&self, errors: Vec<ValidationError>)
pub fn extend_errors(&self, errors: Vec<ValidationError>)
Appends all the errors to the current context
Sourcepub fn append_path<V: Into<String>>(&self, path: V) -> Context<'r>
pub fn append_path<V: Into<String>>(&self, path: V) -> Context<'r>
Append a path to the current path
Sourcepub fn record_evaluated_property(&self, name: &str)
pub fn record_evaluated_property(&self, name: &str)
Record a successfully evaluated object property name (properties / patternProperties / additionalProperties).
pub fn with_object_evaluated( &self, object_evaluated: Option<ObjectEvaluatedNames>, ) -> Context<'r>
pub fn with_array_unevaluated( &self, array_unevaluated: Option<Rc<RefCell<ArrayUnevaluatedAnnotations>>>, ) -> Context<'r>
Sourcepub fn is_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>) -> bool
pub fn is_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>) -> bool
Returns true if the given ref is already being resolved for the given
YAML value (identified by its span start index), indicating a cycle.
Sourcepub fn begin_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
pub fn begin_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
Mark a (ref, value_position) pair as currently being resolved.
Sourcepub fn end_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
pub fn end_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
Remove a (ref, value_position) pair from the resolving set after resolution completes.