| 1 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::{ |
| 2 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/, |
| 3 | errorrust-analyzer cargo jsonschema 0.37.4 error/::{no_errorrust-analyzer cargo jsonschema 0.37.4 error/no_error()., ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#}, |
| 4 | evaluationrust-analyzer cargo jsonschema 0.37.4 evaluation/::Annotationsrust-analyzer cargo jsonschema 0.37.4 evaluation/Annotations#, |
| 5 | keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#, |
| 6 | noderust-analyzer cargo jsonschema 0.37.4 node/::SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#, |
| 7 | pathsrust-analyzer cargo jsonschema 0.37.4 paths/::{LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#}, |
| 8 | typesrust-analyzer cargo jsonschema 0.37.4 types/::JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#, |
| 9 | validatorrust-analyzer cargo jsonschema 0.37.4 validator/::{EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#, Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#, ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#}, |
| 10 | }; |
| 11 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{Maprust-analyzer cargo serde_json 1.0.145 map/Map#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#}; |
| 12 | |
| 13 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct PropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator# { |
| 14 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#)>, |
| 15 | } |
| 16 | |
| 17 | impl PropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator# { |
| 18 | #[inline] |
| 19 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator]compile().<'a>(ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a> { |
| 20 | match schema { |
| 21 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(map) => { |
| 22 | let ctx = ctx.new_at_locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]new_at_location().("properties"); |
| 23 | let mut properties = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(map.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().()); |
| 24 | for (key, subschema) in map { |
| 25 | let ctx = ctx.new_at_locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]new_at_location().(key.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 26 | properties.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(( |
| 27 | key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 28 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::compilerust-analyzer cargo jsonschema 0.37.4 compiler/compile().(&ctx, ctx.as_resource_refrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]as_resource_ref().(subschema))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 29 | )); |
| 30 | } |
| 31 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(PropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator# { propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties. })) |
| 32 | } |
| 33 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().( |
| 34 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |
| 35 | ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(), |
| 36 | schema, |
| 37 | JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Objectrust-analyzer cargo jsonschema 0.37.4 types/JsonType#Object#, |
| 38 | )), |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for PropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator# { |
| 44 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator][Validate]is_valid().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#) -> bool { |
| 45 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance { |
| 46 | for (name, node) in &self.propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties. { |
| 47 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prop) = item.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(name) { |
| 48 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().node.is_validrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]is_valid().(prop, ctx) { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | true |
| 54 | } else { |
| 55 | true |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator][Validate]validate().<'i>( |
| 60 | &self, |
| 61 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 62 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 63 | ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 64 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> { |
| 65 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance { |
| 66 | for (name, node) in &self.propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties. { |
| 67 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = item.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(name) { |
| 68 | node.validaterust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]validate().(item, &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(name), ctx)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 73 | } |
| 74 | |
| 75 | #[allow(clippy::needless_collect)] |
| 76 | fn iter_errorsrust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator][Validate]iter_errors().<'i>( |
| 77 | &self, |
| 78 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 79 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 80 | ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 81 | ) -> ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#<'i> { |
| 82 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance { |
| 83 | let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 84 | for (name, node) in &self.propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties. { |
| 85 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prop) = item.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(name) { |
| 86 | let instance_path = location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(name.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 87 | errors.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(node.iter_errorsrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]iter_errors().(prop, &instance_path, ctx)); |
| 88 | } |
| 89 | } |
| 90 | ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#::from_iteratorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ErrorIterator<'a>`]from_iterator().(errors.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()) |
| 91 | } else { |
| 92 | no_errorrust-analyzer cargo jsonschema 0.37.4 error/no_error().() |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | fn evaluaterust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator][Validate]evaluate().( |
| 97 | &self, |
| 98 | instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 99 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 100 | ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 101 | ) -> EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult# { |
| 102 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(props) = instance { |
| 103 | let mut matched_props = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(props.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().()); |
| 104 | let mut children = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 105 | for (prop_name, node) in &self.propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#properties. { |
| 106 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prop) = props.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(prop_name) { |
| 107 | let path = location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(prop_name.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 108 | matched_props.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(prop_name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 109 | children.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(node.evaluate_instancerust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode]evaluate_instance().(prop, &path, ctx)); |
| 110 | } |
| 111 | } |
| 112 | let mut application = EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::from_childrenrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]from_children().(children); |
| 113 | application.annotaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]annotate().(Annotationsrust-analyzer cargo jsonschema 0.37.4 evaluation/Annotations#::newrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Annotations]new().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::fromrust-analyzer cargo serde_json 1.0.145 value/from/impl#[Value][`From<Vec<T>>`]from().(matched_props))); |
| 114 | application |
| 115 | } else { |
| 116 | EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::valid_emptyrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]valid_empty().() |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | #[inline] |
| 122 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/properties/compile().<'a>( |
| 123 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 124 | parent: &'a Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>, |
| 125 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 126 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 127 | match parent.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("additionalProperties") { |
| 128 | // This type of `additionalProperties` validator handles `properties` logic |
| 129 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(false) | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(_)) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 130 | _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/properties/PropertiesValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/properties/impl#[PropertiesValidator]compile().(ctx, schema)), |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | #[cfg(test)] |
| 135 | mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/properties/tests/ { |
| 136 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/; |
| 137 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!; |
| 138 | |
| 139 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 140 | fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/properties/tests/location().() { |
| 141 | tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_schema_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_schema_location().( |
| 142 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"properties": {"foo": {"properties": {"bar": {"required": ["spam"]}}}}}), |
| 143 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": {"bar": {}}}), |
| 144 | "/properties/foo/properties/bar/required", |
| 145 | ); |
| 146 | } |
| 147 | } |