| 1 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::{ |
| 2 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/, keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#, pathsrust-analyzer cargo jsonschema 0.37.4 paths/::Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, typesrust-analyzer cargo jsonschema 0.37.4 types/::JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#, validatorrust-analyzer cargo jsonschema 0.37.4 validator/::Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#, |
| 3 | ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#, |
| 4 | }; |
| 5 | 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#}; |
| 6 | |
| 7 | fn compile_reference_validatorrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_reference_validator().<'a>( |
| 8 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 9 | reference: &str, |
| 10 | keyword: &str, |
| 11 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 12 | let current_location = match ctx.absolute_location_urirust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]absolute_location_uri().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().) { |
| 13 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(uri) => uri, |
| 14 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error)), |
| 15 | }; |
| 16 | let alias = match ctx |
| 17 | .resolve_reference_urirust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]resolve_reference_uri().(reference) |
| 18 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().) |
| 19 | { |
| 20 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(uri) => uri, |
| 21 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error)), |
| 22 | }; |
| 23 | |
| 24 | if alias rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`PartialEq<Self>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`PartialEq<Self>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`PartialEq<Self>`]eq().current_location |
| 25 | || (reference.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() && alias.strip_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]strip_fragment().() rust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][`PartialEq<Uri<U>>`]eq().==rust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][`PartialEq<Uri<U>>`]eq(). rust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][`PartialEq<Uri<U>>`]eq().current_location.strip_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]strip_fragment().()) |
| 26 | { |
| 27 | // Direct self-reference would recurse indefinitely, treat it as an annotation-only schema. |
| 28 | // Empty string $ref ("") is a same-document reference per RFC 3986, equivalent to "#" |
| 29 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 30 | } |
| 31 | |
| 32 | match ctx.lookup_maybe_recursiverust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]lookup_maybe_recursive().(reference) { |
| 33 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(validator)) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(validator)), |
| 34 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {} |
| 35 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error)), |
| 36 | } |
| 37 | |
| 38 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = ctx.mark_seenrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]mark_seen().(reference) { |
| 39 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().(error))); |
| 40 | } |
| 41 | |
| 42 | let (contents, resolver, draft) = match ctx.lookuprust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]lookup().(reference) { |
| 43 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(resolved) => resolved.into_innerrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]into_inner().(), |
| 44 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().(error))), |
| 45 | }; |
| 46 | let vocabularies = ctx.registryrust-analyzer cargo jsonschema 0.37.4 compiler/Context#registry..find_vocabulariesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]find_vocabularies().(draft, contents); |
| 47 | let resource_ref = draft.create_resource_refrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource_ref().(contents); |
| 48 | let ctx = ctx.with_resolver_and_draftrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]with_resolver_and_draft().( |
| 49 | resolver, |
| 50 | resource_ref.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[`ResourceRef<'a>`]draft().(), |
| 51 | vocabularies, |
| 52 | ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(keyword), |
| 53 | ); |
| 54 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#( |
| 55 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::compile_with_aliasrust-analyzer cargo jsonschema 0.37.4 compiler/compile_with_alias().(&ctx, resource_ref, alias) |
| 56 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|node| { |
| 57 | 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().(node.clone_with_locationrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode]clone_with_location().(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().(), ctx.base_urirust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]base_uri().())) |
| 58 | as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#> |
| 59 | }) |
| 60 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::to_ownedrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]to_owned().), |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | fn compile_recursive_validatorrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_recursive_validator().<'a>( |
| 65 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 66 | reference: &str, |
| 67 | ) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a> { |
| 68 | // Check if this is a circular reference first |
| 69 | match ctx.lookup_maybe_recursiverust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]lookup_maybe_recursive().(reference) { |
| 70 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(validator)) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(validator), |
| 71 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {} |
| 72 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error), |
| 73 | } |
| 74 | |
| 75 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = ctx.mark_seenrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]mark_seen().(reference) { |
| 76 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().(error)); |
| 77 | } |
| 78 | |
| 79 | let alias = ctx |
| 80 | .resolve_reference_urirust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]resolve_reference_uri().(reference) |
| 81 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 82 | let resolved = ctx |
| 83 | .lookup_recursive_referencerust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]lookup_recursive_reference().() |
| 84 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::fromrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'_>`][`From<referencing::Error>`]from().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 85 | let (contents, resolver, draft) = resolved.into_innerrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]into_inner().(); |
| 86 | let vocabularies = ctx.registryrust-analyzer cargo jsonschema 0.37.4 compiler/Context#registry..find_vocabulariesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]find_vocabularies().(draft, contents); |
| 87 | let resource_ref = draft.create_resource_refrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource_ref().(contents); |
| 88 | let ctx = ctx.with_resolver_and_draftrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]with_resolver_and_draft().( |
| 89 | resolver, |
| 90 | resource_ref.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[`ResourceRef<'a>`]draft().(), |
| 91 | vocabularies, |
| 92 | ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("$recursiveRef"), |
| 93 | ); |
| 94 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::compile_with_aliasrust-analyzer cargo jsonschema 0.37.4 compiler/compile_with_alias().(&ctx, resource_ref, alias) |
| 95 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|node| { |
| 96 | 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().(node.clone_with_locationrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode]clone_with_location().(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().(), ctx.base_urirust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]base_uri().())) |
| 97 | as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#> |
| 98 | }) |
| 99 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::to_ownedrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]to_owned().) |
| 100 | } |
| 101 | |
| 102 | fn invalid_referencerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/invalid_reference().<'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#) -> ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a> { |
| 103 | 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().( |
| 104 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |
| 105 | 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().(), |
| 106 | schema, |
| 107 | JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Stringrust-analyzer cargo jsonschema 0.37.4 types/JsonType#String#, |
| 108 | ) |
| 109 | } |
| 110 | |
| 111 | #[inline] |
| 112 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_implrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_impl().<'a>( |
| 113 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 114 | _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#>, |
| 115 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 116 | keyword: &str, |
| 117 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 118 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reference) = schema.as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().() { |
| 119 | compile_reference_validatorrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_reference_validator().(ctx, reference, keyword) |
| 120 | } else { |
| 121 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(invalid_referencerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/invalid_reference().(ctx, schema))) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #[inline] |
| 126 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_dynamic_refrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_dynamic_ref().<'a>( |
| 127 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 128 | 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#>, |
| 129 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 130 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 131 | compile_implrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_impl().(ctx, parent, schema, "$dynamicRef") |
| 132 | } |
| 133 | |
| 134 | #[inline] |
| 135 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_refrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_ref().<'a>( |
| 136 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 137 | 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#>, |
| 138 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 139 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 140 | compile_implrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_impl().(ctx, parent, schema, "$ref") |
| 141 | } |
| 142 | |
| 143 | #[inline] |
| 144 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_recursive_refrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_recursive_ref().<'a>( |
| 145 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 146 | _: &'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#>, |
| 147 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 148 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 149 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#( |
| 150 | schema |
| 151 | .as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().() |
| 152 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| invalid_referencerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/invalid_reference().(ctx, schema)) |
| 153 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|reference| compile_recursive_validatorrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/compile_recursive_validator().(ctx, reference)), |
| 154 | ) |
| 155 | } |
| 156 | |
| 157 | #[cfg(test)] |
| 158 | mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/ { |
| 159 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/; |
| 160 | use ahashrust-analyzer cargo ahash 0.8.12 crate/::HashMaprust-analyzer cargo ahash 0.8.12 HashMap#; |
| 161 | use referencingrust-analyzer cargo referencing 0.37.4 crate/::{Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#}; |
| 162 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{jsonrust-analyzer cargo serde_json 1.0.145 macros/json!, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#}; |
| 163 | use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:; |
| 164 | |
| 165 | struct MyRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/MyRetrieve#; |
| 166 | |
| 167 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for MyRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/MyRetrieve# { |
| 168 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[MyRetrieve][Retrieve]retrieve().( |
| 169 | &self, |
| 170 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 171 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 172 | match uri.pathrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]path().().as_strrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]as_str().() { |
| 173 | "/indirection" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 174 | "$id": "/indirection", |
| 175 | "baz": { |
| 176 | "$ref": "/types#/foo" |
| 177 | } |
| 178 | })), |
| 179 | "/types" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 180 | "$id": "/types", |
| 181 | "foo": { |
| 182 | "$id": "#/foo", |
| 183 | "$ref": "#/bar" |
| 184 | }, |
| 185 | "bar": { |
| 186 | "type": "integer" |
| 187 | } |
| 188 | })), |
| 189 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Not found"), |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 195 | fn custom_retrieve_can_load_remoterust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/custom_retrieve_can_load_remote().() { |
| 196 | let retriever = MyRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/MyRetrieve#; |
| 197 | let uri = Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#::try_fromrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`][`TryFrom<String>`]try_from().("https://example.com/types".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("valid uri"); |
| 198 | let value: Valuerust-analyzer cargo serde_json 1.0.145 value/Value# = retriever |
| 199 | .retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[MyRetrieve][Retrieve]retrieve().(&uri) |
| 200 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("should load the remote document"); |
| 201 | let bar = value |
| 202 | .getrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]get().("bar") |
| 203 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|schema| schema.getrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]get().("type")) |
| 204 | .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().(); |
| 205 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bar, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("integer"))); |
| 206 | } |
| 207 | |
| 208 | struct TestRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve# { |
| 209 | storagerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve#storage.: HashMaprust-analyzer cargo ahash 0.8.12 HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>, |
| 210 | } |
| 211 | |
| 212 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for TestRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve# { |
| 213 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[TestRetrieve][Retrieve]retrieve().( |
| 214 | &self, |
| 215 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 216 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 217 | self.storagerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve#storage. |
| 218 | .getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(uri.pathrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]path().().as_strrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]as_str().()) |
| 219 | .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() |
| 220 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Document not found".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | struct NestedRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/NestedRetrieve#; |
| 225 | |
| 226 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for NestedRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/NestedRetrieve# { |
| 227 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[NestedRetrieve][Retrieve]retrieve().( |
| 228 | &self, |
| 229 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 230 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 231 | match uri.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().() { |
| 232 | "foo://schema_2.json" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 233 | "$id": "foo://schema_2.json", |
| 234 | "type": "string" |
| 235 | })), |
| 236 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected URI: {}", uri.pathrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]path().()), |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | struct FragmentRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/FragmentRetrieve#; |
| 242 | |
| 243 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for FragmentRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/FragmentRetrieve# { |
| 244 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[FragmentRetrieve][Retrieve]retrieve().( |
| 245 | &self, |
| 246 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 247 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 248 | match uri.pathrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]path().().as_strrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]as_str().() { |
| 249 | "/tmp/schemas/one.json" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 250 | "$defs": { |
| 251 | "obj": { |
| 252 | "$ref": "other.json#/$defs/obj" |
| 253 | } |
| 254 | } |
| 255 | })), |
| 256 | "/tmp/schemas/other.json" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 257 | "$defs": { |
| 258 | "obj": { |
| 259 | "type": "number" |
| 260 | } |
| 261 | } |
| 262 | })), |
| 263 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected URI: {}", uri.pathrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]path().()), |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 269 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 270 | "properties": { |
| 271 | "foo": {"$ref": "#/definitions/foo"} |
| 272 | }, |
| 273 | "definitions": { |
| 274 | "foo": {"type": "string"} |
| 275 | } |
| 276 | }), |
| 277 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": 42}), |
| 278 | "/properties/foo/$ref/type" |
| 279 | )] |
| 280 | fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/location().(schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, expected: &str) { |
| 281 | tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_schema_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_schema_location().(schema, instance, expected); |
| 282 | } |
| 283 | |
| 284 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 285 | fn multiple_errors_locationsrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/multiple_errors_locations().() { |
| 286 | let instance = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 287 | "things": [ |
| 288 | { "code": "CC" }, |
| 289 | { "code": "CC" }, |
| 290 | ] |
| 291 | }); |
| 292 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 293 | "type": "object", |
| 294 | "properties": { |
| 295 | "things": { |
| 296 | "type": "array", |
| 297 | "items": { |
| 298 | "type": "object", |
| 299 | "properties": { |
| 300 | "code": { |
| 301 | "type": "string", |
| 302 | "$ref": "#/$defs/codes" |
| 303 | } |
| 304 | }, |
| 305 | "required": ["code"] |
| 306 | } |
| 307 | } |
| 308 | }, |
| 309 | "required": ["things"], |
| 310 | "$defs": { "codes": { "enum": ["AA", "BB"] } } |
| 311 | }); |
| 312 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 313 | let mut iter = validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&instance); |
| 314 | let expected = "/properties/things/items/properties/code/$ref/enum"; |
| 315 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 316 | iter.nextrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ErrorIterator<'a>`][Iterator]next().() |
| 317 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should be present") |
| 318 | .schema_pathrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]schema_path().() |
| 319 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 320 | expected |
| 321 | ); |
| 322 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 323 | iter.nextrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ErrorIterator<'a>`][Iterator]next().() |
| 324 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should be present") |
| 325 | .schema_pathrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]schema_path().() |
| 326 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 327 | expected |
| 328 | ); |
| 329 | } |
| 330 | |
| 331 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 332 | fn test_relative_base_urirust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_relative_base_uri().() { |
| 333 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 334 | "$id": "/root", |
| 335 | "$ref": "#/foo", |
| 336 | "foo": { |
| 337 | "$id": "#/foo", |
| 338 | "$ref": "#/bar" |
| 339 | }, |
| 340 | "bar": { |
| 341 | "$id": "#/bar", |
| 342 | "type": "integer" |
| 343 | }, |
| 344 | }); |
| 345 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 346 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2))); |
| 347 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("a"))); |
| 348 | } |
| 349 | |
| 350 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 351 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 352 | "$id": "https://example.com/schema.json", |
| 353 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 354 | "type": "object", |
| 355 | "properties": { |
| 356 | "foo": { |
| 357 | "type": "array", |
| 358 | "items": { "$ref": "#/$defs/item" } |
| 359 | } |
| 360 | }, |
| 361 | "$defs": { |
| 362 | "item": { |
| 363 | "type": "object", |
| 364 | "required": ["name", "value"], |
| 365 | "properties": { |
| 366 | "name": { "type": "string" }, |
| 367 | "value": { "type": "boolean" } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | }), |
| 372 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 373 | "foo": [{"name": "item1", "value": true}] |
| 374 | }), |
| 375 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 376 | ("", "/properties"), |
| 377 | ("/foo", "/properties/foo/items"), |
| 378 | ("/foo/0", "/properties/foo/items/$ref/properties"), |
| 379 | ] |
| 380 | ; "standard $ref")] |
| 381 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 382 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 383 | "$id": "https://example.com/schema.json", |
| 384 | "$schema": "https://json-schema.org/draft/2019-09/schema", |
| 385 | "$recursiveAnchor": true, |
| 386 | "type": "object", |
| 387 | "properties": { |
| 388 | "name": { "type": "string" }, |
| 389 | "child": { "$recursiveRef": "#" } |
| 390 | } |
| 391 | }), |
| 392 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 393 | "name": "parent", |
| 394 | "child": { |
| 395 | "name": "child", |
| 396 | "child": { "name": "grandchild" } |
| 397 | } |
| 398 | }), |
| 399 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 400 | ("", "/properties"), |
| 401 | ("/child", "/properties/child/$recursiveRef/properties"), |
| 402 | ("/child/child", "/properties/child/$recursiveRef/properties"), |
| 403 | ] |
| 404 | ; "$recursiveRef")] |
| 405 | fn keyword_locationsrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/keyword_locations().(schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, expected: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(&str, &str)>) { |
| 406 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 407 | for (pointer, keyword_location) in expected { |
| 408 | tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_keyword_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_keyword_location().(&validator, instance, pointer, keyword_location); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 413 | fn test_resolving_finds_references_in_referenced_resourcesrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_resolving_finds_references_in_referenced_resources().() { |
| 414 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/indirection#/baz"}); |
| 415 | |
| 416 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 417 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(MyRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/MyRetrieve#) |
| 418 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 419 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator"); |
| 420 | |
| 421 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2))); |
| 422 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(""))); |
| 423 | } |
| 424 | |
| 425 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 426 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/doc#/definitions/foo"}), |
| 427 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 428 | "$id": "/doc", |
| 429 | "definitions": { |
| 430 | "foo": {"type": "integer"} |
| 431 | } |
| 432 | }), |
| 433 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 434 | ; "basic_fragment" |
| 435 | )] |
| 436 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 437 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/doc1#/definitions/foo"}), |
| 438 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 439 | "$id": "/doc1", |
| 440 | "definitions": { |
| 441 | "foo": {"$ref": "#/definitions/bar"}, |
| 442 | "bar": {"type": "integer"} |
| 443 | } |
| 444 | }), |
| 445 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 446 | ; "intermediate_reference" |
| 447 | )] |
| 448 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 449 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/doc2#/refs/first"}), |
| 450 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 451 | "$id": "/doc2", |
| 452 | "refs": { |
| 453 | "first": {"$ref": "/doc3#/refs/second"} |
| 454 | } |
| 455 | }), |
| 456 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 457 | "/doc3": { |
| 458 | "$id": "/doc3", |
| 459 | "refs": { |
| 460 | "second": {"type": "integer"} |
| 461 | } |
| 462 | } |
| 463 | })) |
| 464 | ; "multiple_documents" |
| 465 | )] |
| 466 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 467 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/doc4#/defs/foo"}), |
| 468 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 469 | "$id": "/doc4", |
| 470 | "defs": { |
| 471 | "foo": { |
| 472 | "$id": "#/defs/foo", |
| 473 | "$ref": "#/defs/bar" |
| 474 | }, |
| 475 | "bar": {"type": "integer"} |
| 476 | } |
| 477 | }), |
| 478 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 479 | ; "id_and_fragment" |
| 480 | )] |
| 481 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 482 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/doc5#/outer"}), |
| 483 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 484 | "$id": "/doc5", |
| 485 | "outer": { |
| 486 | "$ref": "#/middle", |
| 487 | }, |
| 488 | "middle": { |
| 489 | "$id": "#/middle", |
| 490 | "$ref": "#/inner" |
| 491 | }, |
| 492 | "inner": {"type": "integer"} |
| 493 | }), |
| 494 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 495 | ; "nested_references" |
| 496 | )] |
| 497 | fn test_fragment_resolutionrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_fragment_resolution().(schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, root: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, extra: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>) { |
| 498 | let mut storage = HashMaprust-analyzer cargo ahash 0.8.12 HashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().(); |
| 499 | |
| 500 | let doc_path = schema[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()."$ref"]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 501 | .as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().() |
| 502 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| r.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('#').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().()) |
| 503 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Invalid $ref"); |
| 504 | |
| 505 | storage.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(doc_path.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), root.clonerust-analyzer cargo serde_json 1.0.145 value/impl#[Value][Clone]clone().()); |
| 506 | |
| 507 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(extra) = extra { |
| 508 | for (path, document) in extra.as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() { |
| 509 | storage.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(path.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), document.clonerust-analyzer cargo serde_json 1.0.145 value/impl#[Value][Clone]clone().()); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | let retriever = TestRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve# { storagerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/TestRetrieve#storage. }; |
| 514 | |
| 515 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 516 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(retriever) |
| 517 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(schema) |
| 518 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 519 | |
| 520 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42))); |
| 521 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("string"))); |
| 522 | } |
| 523 | |
| 524 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 525 | fn test_infinite_looprust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_infinite_loop().() { |
| 526 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "#"})).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 527 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42))); |
| 528 | } |
| 529 | |
| 530 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 531 | fn test_nested_external_referencerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_nested_external_reference().() { |
| 532 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 533 | "$id": "foo://schema_1.json", |
| 534 | "$ref": "#/$defs/a/b", |
| 535 | "$defs": { |
| 536 | "a": { |
| 537 | "b": { |
| 538 | "description": "nested schema with external ref", |
| 539 | "$ref": "foo://schema_2.json" |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | }); |
| 544 | |
| 545 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 546 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(NestedRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/NestedRetrieve#) |
| 547 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 548 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator"); |
| 549 | |
| 550 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("test"))); |
| 551 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42))); |
| 552 | } |
| 553 | |
| 554 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 555 | fn test_relative_reference_with_fragmentrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_relative_reference_with_fragment().() { |
| 556 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 557 | "$id": "file:///tmp/schemas/root.json", |
| 558 | "$ref": "one.json#/$defs/obj" |
| 559 | }); |
| 560 | |
| 561 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 562 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(FragmentRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/FragmentRetrieve#) |
| 563 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 564 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator"); |
| 565 | |
| 566 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42))); |
| 567 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("string"))); |
| 568 | } |
| 569 | |
| 570 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 571 | fn test_missing_filerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_missing_file().() { |
| 572 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "./virtualNetwork.json"}); |
| 573 | let error = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 574 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 575 | error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 576 | "Resource './virtualNetwork.json' is not present in a registry and retrieving it failed: No base URI is available" |
| 577 | ); |
| 578 | } |
| 579 | |
| 580 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 581 | fn test_empty_ref_no_stack_overflowrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_empty_ref_no_stack_overflow().() { |
| 582 | // Empty string is a same-document reference per RFC 3986, should behave like $ref: "#" |
| 583 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": ""}); |
| 584 | let instance = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1); |
| 585 | |
| 586 | // Should compile without error and validate without stack overflow |
| 587 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 588 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&instance)); |
| 589 | } |
| 590 | |
| 591 | struct IndirectExternalRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/IndirectExternalRetrieve#; |
| 592 | |
| 593 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for IndirectExternalRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/IndirectExternalRetrieve# { |
| 594 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[IndirectExternalRetrieve][Retrieve]retrieve().( |
| 595 | &self, |
| 596 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 597 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 598 | match uri.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().() { |
| 599 | "file:///ext.yaml" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 600 | "components": { |
| 601 | "schemas": { |
| 602 | "c3": { |
| 603 | "type": "integer" |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | })), |
| 608 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unexpected URI: {uri}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 614 | fn test_indirect_local_refs_to_external_resourcerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_indirect_local_refs_to_external_resource().() { |
| 615 | // GH-892: Chained local $refs where the final ref points to an external resource |
| 616 | // should properly discover and retrieve the external resource. |
| 617 | // |
| 618 | // The chain is: |
| 619 | // root $ref -> #/components/schemas/c1 |
| 620 | // c1 $ref -> #/components/schemas/c2 |
| 621 | // c2 $ref -> ext.yaml#/components/schemas/c3 (EXTERNAL) |
| 622 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 623 | "$id": "file:///tmp", |
| 624 | "$ref": "#/components/schemas/c1", |
| 625 | "components": { |
| 626 | "schemas": { |
| 627 | "c1": { |
| 628 | "$ref": "#/components/schemas/c2" |
| 629 | }, |
| 630 | "c2": { |
| 631 | "$ref": "ext.yaml#/components/schemas/c3" |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | }); |
| 636 | |
| 637 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 638 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(IndirectExternalRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/IndirectExternalRetrieve#) |
| 639 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 640 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator - external resource was not discovered"); |
| 641 | |
| 642 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42))); |
| 643 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("string"))); |
| 644 | } |
| 645 | |
| 646 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 647 | fn test_local_ref_with_nested_external_ref_in_propertiesrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_local_ref_with_nested_external_ref_in_properties().() { |
| 648 | // GH-892 follow-up: Local $ref points to a schema that has an external $ref |
| 649 | // nested within properties (not a direct $ref chain). |
| 650 | // |
| 651 | // The structure is: |
| 652 | // root $ref -> #/components/schemas/c1 |
| 653 | // c1 is a full schema with type/properties |
| 654 | // c1.properties.p contains an external $ref |
| 655 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 656 | "$id": "file:///tmp", |
| 657 | "$ref": "#/components/schemas/c1", |
| 658 | "components": { |
| 659 | "schemas": { |
| 660 | "c1": { |
| 661 | "type": "object", |
| 662 | "properties": { |
| 663 | "p": { |
| 664 | "$ref": "ext.yaml#/components/schemas/c3" |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | }); |
| 671 | |
| 672 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 673 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(IndirectExternalRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/IndirectExternalRetrieve#) |
| 674 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 675 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator - external resource was not discovered"); |
| 676 | |
| 677 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"p": 42}))); |
| 678 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"p": "string"}))); |
| 679 | } |
| 680 | |
| 681 | struct CrossFileRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/CrossFileRetrieve#; |
| 682 | |
| 683 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for CrossFileRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/CrossFileRetrieve# { |
| 684 | fn retrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/impl#[CrossFileRetrieve][Retrieve]retrieve().( |
| 685 | &self, |
| 686 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 687 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 688 | match uri.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().() { |
| 689 | "file:///tmp/json" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 690 | "components": { |
| 691 | "schemas": { |
| 692 | "c1": { |
| 693 | "type": "array", |
| 694 | "items": { |
| 695 | "$ref": "#/components/schemas/c2" |
| 696 | } |
| 697 | }, |
| 698 | "c2": { |
| 699 | "$ref": "ext.json#/components/schemas/c3" |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | })), |
| 704 | "file:///tmp/ext.json" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 705 | "components": { |
| 706 | "schemas": { |
| 707 | "c3": { |
| 708 | "type": "integer" |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | })), |
| 713 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unexpected URI: {uri}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 719 | fn test_cross_file_local_ref_resolutionrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_cross_file_local_ref_resolution().() { |
| 720 | // GH-892: External ref with fragment pointing to a schema that has local refs. |
| 721 | // The local refs within the external file need to resolve against that file's |
| 722 | // document root, not the original schema's root. |
| 723 | // |
| 724 | // Structure: |
| 725 | // root $ref -> file:///tmp/json#/components/schemas/c1 |
| 726 | // /tmp/json has: |
| 727 | // c1.items.$ref -> #/components/schemas/c2 (local ref within /tmp/json) |
| 728 | // c2.$ref -> ext.json#/components/schemas/c3 (external ref) |
| 729 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 730 | "$ref": "file:///tmp/json#/components/schemas/c1" |
| 731 | }); |
| 732 | |
| 733 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 734 | .with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(CrossFileRetrieverust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/CrossFileRetrieve#) |
| 735 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema) |
| 736 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to build validator - external resource was not discovered"); |
| 737 | |
| 738 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([1, 2, 3]))); |
| 739 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(["a", "b"]))); |
| 740 | } |
| 741 | |
| 742 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 743 | fn test_circular_local_refs_compilerust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_circular_local_refs_compile().() { |
| 744 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 745 | "$defs": { |
| 746 | "a": {"$ref": "#/$defs/b"}, |
| 747 | "b": {"$ref": "#/$defs/a"} |
| 748 | }, |
| 749 | "$ref": "#/$defs/a" |
| 750 | }); |
| 751 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 752 | |
| 753 | // A pure $ref cycle is equivalent to `true` schema |
| 754 | for instance in [ |
| 755 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(42), |
| 756 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("string"), |
| 757 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(null), |
| 758 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"nested": [1, 2, 3]}), |
| 759 | ] { |
| 760 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&instance)); |
| 761 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&instance).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 762 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&instance).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 763 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.evaluaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]evaluate().(&instance).flagrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Evaluation]flag().().validrust-analyzer cargo jsonschema 0.37.4 evaluation/FlagOutput#valid.); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 768 | fn test_circular_refs_with_constraintsrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_circular_refs_with_constraints().() { |
| 769 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 770 | "$defs": { |
| 771 | "node": { |
| 772 | "type": "object", |
| 773 | "properties": { |
| 774 | "value": {"type": "integer"}, |
| 775 | "next": {"$ref": "#/$defs/node"} |
| 776 | } |
| 777 | } |
| 778 | }, |
| 779 | "$ref": "#/$defs/node" |
| 780 | }); |
| 781 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 782 | |
| 783 | let valid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"value": 1, "next": {"value": 2, "next": {"value": 3}}}); |
| 784 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&valid)); |
| 785 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&valid).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 786 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&valid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 787 | |
| 788 | let invalid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"value": "not an int"}); |
| 789 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&invalid)); |
| 790 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&invalid).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 791 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&invalid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 792 | |
| 793 | let invalid_nested = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"value": 1, "next": {"value": "bad"}}); |
| 794 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&invalid_nested)); |
| 795 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&invalid_nested).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 796 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&invalid_nested).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 797 | } |
| 798 | |
| 799 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 800 | fn test_longer_circular_chainrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_longer_circular_chain().() { |
| 801 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 802 | "$defs": { |
| 803 | "a": {"$ref": "#/$defs/b"}, |
| 804 | "b": {"$ref": "#/$defs/c"}, |
| 805 | "c": {"$ref": "#/$defs/a"} |
| 806 | }, |
| 807 | "$ref": "#/$defs/a" |
| 808 | }); |
| 809 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 810 | |
| 811 | let instance = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"any": "value"}); |
| 812 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&instance)); |
| 813 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&instance).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 814 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&instance).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 815 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.evaluaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]evaluate().(&instance).flagrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Evaluation]flag().().validrust-analyzer cargo jsonschema 0.37.4 evaluation/FlagOutput#valid.); |
| 816 | } |
| 817 | |
| 818 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 819 | fn test_dependencies_with_array_formrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_dependencies_with_array_form().() { |
| 820 | // Tests NodeValidators::Array branch via dependencies with array form |
| 821 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 822 | "dependencies": { |
| 823 | "foo": ["bar", "baz"] |
| 824 | } |
| 825 | }); |
| 826 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 827 | |
| 828 | let valid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": 1, "bar": 2, "baz": 3}); |
| 829 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&valid)); |
| 830 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&valid).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 831 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&valid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 832 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.evaluaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]evaluate().(&valid).flagrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Evaluation]flag().().validrust-analyzer cargo jsonschema 0.37.4 evaluation/FlagOutput#valid.); |
| 833 | |
| 834 | let invalid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": 1}); |
| 835 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&invalid)); |
| 836 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&invalid).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 837 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&invalid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 838 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.evaluaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]evaluate().(&invalid).flagrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Evaluation]flag().().validrust-analyzer cargo jsonschema 0.37.4 evaluation/FlagOutput#valid.); |
| 839 | } |
| 840 | |
| 841 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 842 | fn test_dependent_required_array_formrust-analyzer cargo jsonschema 0.37.4 keywords/ref_/tests/test_dependent_required_array_form().() { |
| 843 | // Tests NodeValidators::Array branch via dependentRequired (Draft 2019-09+) |
| 844 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 845 | "$schema": "https://json-schema.org/draft/2019-09/schema", |
| 846 | "dependentRequired": { |
| 847 | "foo": ["bar"] |
| 848 | } |
| 849 | }); |
| 850 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should compile"); |
| 851 | |
| 852 | let valid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": 1, "bar": 2}); |
| 853 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&valid)); |
| 854 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&valid).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 855 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&valid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 856 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.evaluaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]evaluate().(&valid).flagrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Evaluation]flag().().validrust-analyzer cargo jsonschema 0.37.4 evaluation/FlagOutput#valid.); |
| 857 | |
| 858 | let invalid = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"foo": 1}); |
| 859 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&invalid)); |
| 860 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(&invalid).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 861 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.iter_errorsrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]iter_errors().(&invalid).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 862 | } |
| 863 | } |