| 1 | //! Validators for `contentMediaType` and `contentEncoding` keywords. |
| 2 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::{ |
| 3 | compilerrust-analyzer cargo jsonschema 0.37.4 compiler/, |
| 4 | content_encodingrust-analyzer cargo jsonschema 0.37.4 content_encoding/::{ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#}, |
| 5 | content_media_typerust-analyzer cargo jsonschema 0.37.4 content_media_type/::ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, |
| 6 | errorrust-analyzer cargo jsonschema 0.37.4 error/::ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#, |
| 7 | keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#, |
| 8 | 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#}, |
| 9 | typesrust-analyzer cargo jsonschema 0.37.4 types/::JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#, |
| 10 | validatorrust-analyzer cargo jsonschema 0.37.4 validator/::{Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#, ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#}, |
| 11 | }; |
| 12 | 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#}; |
| 13 | |
| 14 | /// Validator for `contentMediaType` keyword. |
| 15 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct ContentMediaTypeValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator# { |
| 16 | media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#media_type.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 17 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#func.: ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, |
| 18 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 19 | } |
| 20 | |
| 21 | impl ContentMediaTypeValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator# { |
| 22 | #[inline] |
| 23 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeValidator]compile().( |
| 24 | media_type: &str, |
| 25 | func: ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, |
| 26 | location: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 27 | ) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'_> { |
| 28 | 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().(ContentMediaTypeValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator# { |
| 29 | media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#media_type.: media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 30 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#func., |
| 31 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#location., |
| 32 | })) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /// Validator delegates validation to the stored function. |
| 37 | impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for ContentMediaTypeValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator# { |
| 38 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeValidator][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 { |
| 39 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 40 | (self.funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#func.)(item) |
| 41 | } else { |
| 42 | true |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeValidator][Validate]validate().<'i>( |
| 47 | &self, |
| 48 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 49 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 50 | ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 51 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> { |
| 52 | if self.is_validrust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeValidator][Validate]is_valid().(instance, ctx) { |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 54 | } else if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(_) = instance { |
| 55 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::content_media_typerust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]content_media_type().( |
| 56 | self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#location..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(), |
| 57 | location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 58 | instance, |
| 59 | &self.media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#media_type., |
| 60 | )) |
| 61 | } else { |
| 62 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /// Validator for `contentEncoding` keyword. |
| 68 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct ContentEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator# { |
| 69 | encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#encoding.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 70 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#func.: ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, |
| 71 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 72 | } |
| 73 | |
| 74 | impl ContentEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator# { |
| 75 | #[inline] |
| 76 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentEncodingValidator]compile().( |
| 77 | encoding: &str, |
| 78 | func: ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, |
| 79 | location: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 80 | ) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'_> { |
| 81 | 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().(ContentEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator# { |
| 82 | encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#encoding.: encoding.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 83 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#func., |
| 84 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#location., |
| 85 | })) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for ContentEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator# { |
| 90 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentEncodingValidator][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 { |
| 91 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 92 | (self.funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#func.)(item) |
| 93 | } else { |
| 94 | true |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentEncodingValidator][Validate]validate().<'i>( |
| 99 | &self, |
| 100 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 101 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 102 | ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 103 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> { |
| 104 | if self.is_validrust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentEncodingValidator][Validate]is_valid().(instance, ctx) { |
| 105 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 106 | } else if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(_) = instance { |
| 107 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::content_encodingrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]content_encoding().( |
| 108 | self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#location..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(), |
| 109 | location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 110 | instance, |
| 111 | &self.encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#encoding., |
| 112 | )) |
| 113 | } else { |
| 114 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /// Combined validator for both `contentEncoding` and `contentMediaType` keywords. |
| 120 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct ContentMediaTypeAndEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator# { |
| 121 | media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#media_type.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 122 | encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#encoding.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 123 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#func.: ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, |
| 124 | converterrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#converter.: ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#, |
| 125 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 126 | } |
| 127 | |
| 128 | impl ContentMediaTypeAndEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator# { |
| 129 | #[inline] |
| 130 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeAndEncodingValidator]compile().<'a>( |
| 131 | media_type: &'a str, |
| 132 | encoding: &'a str, |
| 133 | func: ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, |
| 134 | converter: ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#, |
| 135 | location: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 136 | ) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a> { |
| 137 | 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().(ContentMediaTypeAndEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator# { |
| 138 | media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#media_type.: media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 139 | encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#encoding.: encoding.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 140 | funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#func., |
| 141 | converterrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#converter., |
| 142 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#location., |
| 143 | })) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /// Decode the input value & check media type |
| 148 | impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for ContentMediaTypeAndEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator# { |
| 149 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeAndEncodingValidator][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 { |
| 150 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 151 | match (self.converterrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#converter.)(item) { |
| 152 | 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#) | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => false, |
| 153 | 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#(converted)) => (self.funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#func.)(&converted), |
| 154 | } |
| 155 | } else { |
| 156 | true |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeAndEncodingValidator][Validate]validate().<'i>( |
| 161 | &self, |
| 162 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 163 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 164 | _ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 165 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> { |
| 166 | if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 167 | match (self.converterrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#converter.)(item) { |
| 168 | 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#) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::content_encodingrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]content_encoding().( |
| 169 | self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#location..joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("contentEncoding"), |
| 170 | location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 171 | instance, |
| 172 | &self.encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#encoding., |
| 173 | )), |
| 174 | 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#(converted)) => { |
| 175 | if (self.funcrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#func.)(&converted) { |
| 176 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 177 | } else { |
| 178 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::content_media_typerust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]content_media_type().( |
| 179 | self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#location..joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("contentMediaType"), |
| 180 | location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 181 | instance, |
| 182 | &self.media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#media_type., |
| 183 | )) |
| 184 | } |
| 185 | } |
| 186 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 187 | } |
| 188 | } else { |
| 189 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | #[inline] |
| 195 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_media_typerust-analyzer cargo jsonschema 0.37.4 keywords/content/compile_media_type().<'a>( |
| 196 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 197 | schema: &'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#>, |
| 198 | subschema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 199 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 200 | match subschema { |
| 201 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(media_type) => { |
| 202 | let func = ctx.get_content_media_type_checkrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]get_content_media_type_check().(media_type.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 203 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(content_encoding) = schema.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("contentEncoding") { |
| 204 | match content_encoding { |
| 205 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(content_encoding) => { |
| 206 | let converter = ctx.get_content_encoding_convertrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]get_content_encoding_convert().(content_encoding)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 207 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentMediaTypeAndEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeAndEncodingValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeAndEncodingValidator]compile().( |
| 208 | media_type, |
| 209 | content_encoding, |
| 210 | func, |
| 211 | converter, |
| 212 | 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().(), |
| 213 | )) |
| 214 | } |
| 215 | _ => 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#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().( |
| 216 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |
| 217 | 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().(), |
| 218 | content_encoding, |
| 219 | JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Stringrust-analyzer cargo jsonschema 0.37.4 types/JsonType#String#, |
| 220 | ))), |
| 221 | } |
| 222 | } else { |
| 223 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentMediaTypeValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentMediaTypeValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentMediaTypeValidator]compile().( |
| 224 | media_type, |
| 225 | func, |
| 226 | ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("contentMediaType"), |
| 227 | )) |
| 228 | } |
| 229 | } |
| 230 | _ => 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#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().( |
| 231 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |
| 232 | 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().(), |
| 233 | subschema, |
| 234 | JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Stringrust-analyzer cargo jsonschema 0.37.4 types/JsonType#String#, |
| 235 | ))), |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | #[inline] |
| 240 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compile_content_encodingrust-analyzer cargo jsonschema 0.37.4 keywords/content/compile_content_encoding().<'a>( |
| 241 | ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, |
| 242 | schema: &'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#>, |
| 243 | subschema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 244 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> { |
| 245 | // Performed during media type validation |
| 246 | if schema.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("contentMediaType").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 247 | // TODO. what if media type is not supported? |
| 248 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 249 | } |
| 250 | match subschema { |
| 251 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(content_encoding) => { |
| 252 | let func = ctx.get_content_encoding_checkrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]get_content_encoding_check().(content_encoding)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 253 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentEncodingValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/content/ContentEncodingValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/content/impl#[ContentEncodingValidator]compile().( |
| 254 | content_encoding, |
| 255 | func, |
| 256 | ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("contentEncoding"), |
| 257 | )) |
| 258 | } |
| 259 | _ => 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#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().( |
| 260 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |
| 261 | 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().(), |
| 262 | subschema, |
| 263 | JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Stringrust-analyzer cargo jsonschema 0.37.4 types/JsonType#String#, |
| 264 | ))), |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | #[cfg(test)] |
| 269 | mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/content/tests/ { |
| 270 | use referencingrust-analyzer cargo referencing 0.37.4 crate/::Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#; |
| 271 | 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#}; |
| 272 | use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:; |
| 273 | |
| 274 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"contentEncoding": "base64"}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("asd"), "/contentEncoding")] |
| 275 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"contentMediaType": "application/json"}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("asd"), "/contentMediaType")] |
| 276 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"contentMediaType": "application/json", "contentEncoding": "base64"}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("ezp9Cg=="), "/contentMediaType")] |
| 277 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"contentMediaType": "application/json", "contentEncoding": "base64"}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("{}"), "/contentEncoding")] |
| 278 | fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/content/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) { |
| 279 | let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().() |
| 280 | .with_draftrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_draft().(Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft7rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft7#) |
| 281 | .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(schema) |
| 282 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema"); |
| 283 | let error = validator.validaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]validate().(instance).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 284 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error.schema_pathrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]schema_path().().as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), expected); |
| 285 | } |
| 286 | } |