Debian Codegraph @

src/options.rs

raw symbols SCIP
1 use craterust-analyzer cargo jsonschema 0.37.4 crate/::{
2 compilerrust-analyzer cargo jsonschema 0.37.4 compiler/,
3 content_encodingrust-analyzer cargo jsonschema 0.37.4 content_encoding/::{
4 ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#,
5 DEFAULT_CONTENT_ENCODING_CHECKS_AND_CONVERTERSrust-analyzer cargo jsonschema 0.37.4 content_encoding/DEFAULT_CONTENT_ENCODING_CHECKS_AND_CONVERTERS.,
6 },
7 content_media_typerust-analyzer cargo jsonschema 0.37.4 content_media_type/::{ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#, DEFAULT_CONTENT_MEDIA_TYPE_CHECKSrust-analyzer cargo jsonschema 0.37.4 content_media_type/DEFAULT_CONTENT_MEDIA_TYPE_CHECKS.},
8 keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::{customrust-analyzer cargo jsonschema 0.37.4 keywords/custom/::KeywordFactoryrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory#, formatrust-analyzer cargo jsonschema 0.37.4 keywords/format/::Formatrust-analyzer cargo jsonschema 0.37.4 keywords/format/Format#},
9 pathsrust-analyzer cargo jsonschema 0.37.4 paths/::Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
10 retrieverrust-analyzer cargo jsonschema 0.37.4 retriever/::DefaultRetrieverrust-analyzer cargo jsonschema 0.37.4 retriever/DefaultRetriever#,
11 threadrust-analyzer cargo jsonschema 0.37.4 thread/::ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound#,
12 Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#, Validatorrust-analyzer cargo jsonschema 0.37.4 validator/Validator#,
13 };
14 use ahashrust-analyzer cargo ahash 0.8.12 crate/::AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#;
15 use referencingrust-analyzer cargo referencing 0.37.4 crate/::{Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#};
16 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Valuerust-analyzer cargo serde_json 1.0.145 value/Value#;
17 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#};
18
19 /// Configuration options for JSON Schema validation.
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
21 pub struct ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<R = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> {
22 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#>,
23 content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<&'static str, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#>>,
24 content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.:
25 AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<&'static str, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#)>>,
26 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
27 /// Retriever for external resources
28 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever.: R,
29 /// Additional resources that should be addressable during validation.
30 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#>,
31 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<referencingrust-analyzer cargo referencing 0.37.4 crate/::Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#>,
32 formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Formatrust-analyzer cargo jsonschema 0.37.4 keywords/format/Format#>>,
33 validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>,
34 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.: bool,
35 ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.: bool,
36 keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn KeywordFactoryrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory#>>,
37 pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#,
38 }
39
40 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> {
41 fn defaultrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions][Default]default().() -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions][Default] {
42 ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions# {
43 draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
44 content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
45 content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
46 base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
47 retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(DefaultRetrieverrust-analyzer cargo jsonschema 0.37.4 retriever/DefaultRetriever#),
48 resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
49 registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
50 formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
51 validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
52 validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.: true,
53 ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.: true,
54 keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
55 pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::defaultrust-analyzer cargo jsonschema 0.37.4 options/impl#[PatternEngineOptions][Default]default().(),
56 }
57 }
58 }
59
60 #[cfg(feature = "resolve-async")]
61 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn referencingrust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>> {
62 fn defaultrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`][Default]default().() -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`][Default] {
63 ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions# {
64 draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
65 content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
66 content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
67 base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
68 retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(DefaultRetrieverrust-analyzer cargo jsonschema 0.37.4 retriever/DefaultRetriever#),
69 resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
70 registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
71 formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
72 validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
73 validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.: true,
74 ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.: true,
75 keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::defaultrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][Default]default().(),
76 pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::defaultrust-analyzer cargo jsonschema 0.37.4 options/impl#[PatternEngineOptions][Default]default().(),
77 }
78 }
79 }
80
81 impl<R> ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<R> {
82 /// Return the draft version, or the default if not set.
83 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn draftrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]draft().(&self) -> Draftrust-analyzer cargo referencing 0.37.4 specification/Draft# {
84 self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft..unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().()
85 }
86 /// Sets the JSON Schema draft version.
87 ///
88 /// ```rust
89 /// use jsonschema::Draft;
90 ///
91 /// let options = jsonschema::options()
92 /// .with_draft(Draft::Draft4);
93 /// ```
94 ///
95 /// # Panics
96 ///
97 /// Panics if `Draft::Unknown` is provided. `Draft::Unknown` is internal-only
98 /// and represents custom meta-schemas that are resolved automatically from
99 /// the registry.
100 #[inline]
101 #[must_use]
102 pub fn with_draftrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_draft().(mut self, draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
103 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
104 draft != Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Unknownrust-analyzer cargo referencing 0.37.4 specification/Draft#Unknown#,
105 "Draft::Unknown is internal-only and cannot be explicitly set. \
106 Custom meta-schemas are resolved automatically when registered in the Registry."
107 );
108 self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(draft);
109 self
110 }
111
112 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn get_content_media_type_checkrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]get_content_media_type_check().(
113 &self,
114 media_type: &str,
115 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#> {
116 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(media_type) {
117 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value
118 } else {
119 DEFAULT_CONTENT_MEDIA_TYPE_CHECKSrust-analyzer cargo jsonschema 0.37.4 content_media_type/DEFAULT_CONTENT_MEDIA_TYPE_CHECKS..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(media_type).copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
120 }
121 }
122 /// Add support for a custom content media type validation.
123 ///
124 /// # Example
125 ///
126 /// ```rust
127 /// fn check_custom_media_type(instance_string: &str) -> bool {
128 /// instance_string.starts_with("custom:")
129 /// }
130 ///
131 /// let options = jsonschema::options()
132 /// .with_content_media_type("application/custom", check_custom_media_type);
133 /// ```
134 #[must_use]
135 pub fn with_content_media_typerust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_content_media_type().(
136 mut self,
137 media_type: &'static str,
138 media_type_check: ContentMediaTypeCheckTyperust-analyzer cargo jsonschema 0.37.4 content_media_type/ContentMediaTypeCheckType#,
139 ) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
140 self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.
141 .insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(media_type, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(media_type_check));
142 self
143 }
144 /// Remove support for a specific content media type validation.
145 #[must_use]
146 pub fn without_content_media_type_supportrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]without_content_media_type_support().(mut self, media_type: &'static str) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
147 self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks..insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(media_type, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
148 self
149 }
150
151 #[inline]
152 fn content_encoding_check_and_converterrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]content_encoding_check_and_converter().(
153 &self,
154 content_encoding: &str,
155 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#, ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#)> {
156 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self
157 .content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.
158 .getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(content_encoding)
159 {
160 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value
161 } else {
162 DEFAULT_CONTENT_ENCODING_CHECKS_AND_CONVERTERSrust-analyzer cargo jsonschema 0.37.4 content_encoding/DEFAULT_CONTENT_ENCODING_CHECKS_AND_CONVERTERS.
163 .getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(content_encoding)
164 .copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
165 }
166 }
167
168 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn content_encoding_checkrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]content_encoding_check().(
169 &self,
170 content_encoding: &str,
171 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#> {
172 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((check, _)) = self.content_encoding_check_and_converterrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]content_encoding_check_and_converter().(content_encoding) {
173 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(check)
174 } else {
175 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
176 }
177 }
178
179 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn get_content_encoding_convertrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]get_content_encoding_convert().(
180 &self,
181 content_encoding: &str,
182 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#> {
183 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, converter)) = self.content_encoding_check_and_converterrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]content_encoding_check_and_converter().(content_encoding) {
184 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(converter)
185 } else {
186 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
187 }
188 }
189 /// Add support for a custom content encoding.
190 ///
191 /// # Arguments
192 ///
193 /// * `encoding`: Name of the content encoding (e.g., "base64")
194 /// * `check`: Validates the input string (return `true` if valid)
195 /// * `converter`: Converts the input string, returning:
196 /// - `Err(ValidationError)`: For supported errors
197 /// - `Ok(None)`: If input is invalid
198 /// - `Ok(Some(content))`: If valid, with decoded content
199 ///
200 /// # Example
201 ///
202 /// ```rust
203 /// use jsonschema::ValidationError;
204 ///
205 /// fn check(s: &str) -> bool {
206 /// s.starts_with("valid:")
207 /// }
208 ///
209 /// fn convert(s: &str) -> Result<Option<String>, ValidationError<'static>> {
210 /// if s.starts_with("valid:") {
211 /// Ok(Some(s[6..].to_string()))
212 /// } else {
213 /// Ok(None)
214 /// }
215 /// }
216 ///
217 /// let options = jsonschema::options()
218 /// .with_content_encoding("custom", check, convert);
219 /// ```
220 #[must_use]
221 pub fn with_content_encodingrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_content_encoding().(
222 mut self,
223 encoding: &'static str,
224 check: ContentEncodingCheckTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingCheckType#,
225 converter: ContentEncodingConverterTyperust-analyzer cargo jsonschema 0.37.4 content_encoding/ContentEncodingConverterType#,
226 ) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
227 self.content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.
228 .insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(encoding, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((check, converter)));
229 self
230 }
231 /// Remove support for a specific content encoding.
232 ///
233 /// # Example
234 ///
235 /// ```rust
236 /// let options = jsonschema::options()
237 /// .without_content_encoding_support("base64");
238 /// ```
239 #[must_use]
240 pub fn without_content_encoding_supportrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]without_content_encoding_support().(mut self, content_encoding: &'static str) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
241 self.content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.
242 .insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(content_encoding, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
243 self
244 }
245 /// Establish an anchor for resolving relative schema references during validation.
246 ///
247 /// Relative URIs found within the schema will be interpreted against this base.
248 /// This is especially useful when validating schemas loaded from sources without an inherent base URL.
249 ///
250 /// # Example
251 ///
252 /// ```rust
253 /// # use serde_json::json;
254 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
255 ///
256 /// let validator = jsonschema::options()
257 /// // Define a base URI for resolving relative references.
258 /// .with_base_uri("https://example.com/schemas/")
259 /// .build(&json!({
260 /// "$id": "relative-schema.json",
261 /// "type": "object"
262 /// }))?;
263 ///
264 /// // Relative URIs in the schema will now resolve against "https://example.com/schemas/".
265 /// # Ok(())
266 /// # }
267 /// ```
268 #[inline]
269 #[must_use]
270 pub fn with_base_urirust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_base_uri().(mut self, base_uri: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
271 self.base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_uri.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().());
272 self
273 }
274 /// Add a custom schema, allowing it to be referenced by the specified URI during validation.
275 ///
276 /// This enables the use of additional in-memory schemas alongside the main schema being validated.
277 ///
278 /// # Example
279 ///
280 /// ```rust
281 /// # use serde_json::json;
282 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
283 /// use jsonschema::Resource;
284 ///
285 /// let extra = Resource::from_contents(json!({"minimum": 5}));
286 ///
287 /// let validator = jsonschema::options()
288 /// .with_resource("urn:minimum-schema", extra)
289 /// .build(&json!({"$ref": "urn:minimum-schema"}))?;
290 /// assert!(validator.is_valid(&json!(5)));
291 /// assert!(!validator.is_valid(&json!(4)));
292 /// # Ok(())
293 /// # }
294 /// ```
295 #[must_use]
296 pub fn with_resourcerust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_resource().(mut self, uri: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, resource: Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
297 self.resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources..insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(uri.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), resource);
298 self
299 }
300 /// Add custom schemas, allowing them to be referenced by the specified URI during validation.
301 ///
302 /// This enables the use of additional in-memory schemas alongside the main schema being validated.
303 ///
304 /// # Example
305 ///
306 /// ```rust
307 /// # use serde_json::json;
308 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
309 /// use jsonschema::Resource;
310 ///
311 /// let validator = jsonschema::options()
312 /// .with_resources([
313 /// (
314 /// "urn:minimum-schema",
315 /// Resource::from_contents(json!({"minimum": 5})),
316 /// ),
317 /// (
318 /// "urn:maximum-schema",
319 /// Resource::from_contents(json!({"maximum": 10})),
320 /// ),
321 /// ].into_iter())
322 /// .build(&json!({"$ref": "urn:minimum-schema"}))?;
323 /// assert!(validator.is_valid(&json!(5)));
324 /// assert!(!validator.is_valid(&json!(4)));
325 /// # Ok(())
326 /// # }
327 /// ```
328 #[must_use]
329 pub fn with_resourcesrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_resources().(
330 mut self,
331 pairs: impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>,
332 ) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
333 for (uri, resource) in pairs {
334 self.resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources..insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(uri.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), resource);
335 }
336 self
337 }
338 /// Use external schema resources from the registry, making them accessible via references
339 /// during validation.
340 ///
341 /// # Example
342 ///
343 /// ```rust
344 /// # use serde_json::json;
345 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
346 /// use jsonschema::{Registry, Resource};
347 ///
348 /// let registry = Registry::try_new(
349 /// "urn:name-schema",
350 /// Resource::from_contents(json!({"type": "string"}))
351 /// )?;
352 /// let schema = json!({
353 /// "properties": {
354 /// "name": { "$ref": "urn:name-schema" }
355 /// }
356 /// });
357 /// let validator = jsonschema::options()
358 /// .with_registry(registry)
359 /// .build(&schema)?;
360 /// assert!(validator.is_valid(&json!({ "name": "Valid String" })));
361 /// assert!(!validator.is_valid(&json!({ "name": 123 })));
362 /// # Ok(())
363 /// # }
364 /// ```
365 #[must_use]
366 pub fn with_registryrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_registry().(mut self, registry: referencingrust-analyzer cargo referencing 0.37.4 crate/::Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
367 self.registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(registry);
368 self
369 }
370 /// Register a custom format validator.
371 ///
372 /// # Example
373 ///
374 /// ```rust
375 /// # use serde_json::json;
376 /// fn my_format(s: &str) -> bool {
377 /// // Your awesome format check!
378 /// s.ends_with("42!")
379 /// }
380 /// # fn foo() {
381 /// let schema = json!({"type": "string", "format": "custom"});
382 /// let validator = jsonschema::options()
383 /// .with_format("custom", my_format)
384 /// .build(&schema)
385 /// .expect("Valid schema");
386 ///
387 /// assert!(!validator.is_valid(&json!("foo")));
388 /// assert!(validator.is_valid(&json!("foo42!")));
389 /// # }
390 /// ```
391 #[must_use]
392 pub fn with_formatrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_format().<N, F>(mut self, name: N, format: F) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]
393 where
394 N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
395 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&str) -> bool + ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound# + 'static,
396 {
397 self.formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats..insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(format));
398 self
399 }
400 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn get_formatrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]get_format().(&self, format: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Formatrust-analyzer cargo jsonschema 0.37.4 keywords/format/Format#>)> {
401 self.formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats..get_key_valuerust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get_key_value().(format)
402 }
403 /// Disable schema validation during compilation.
404 ///
405 /// Used internally to prevent infinite recursion when validating meta-schemas.
406 /// **Note**: Manually-crafted `ValidationError`s may still occur during compilation.
407 #[inline]
408 #[must_use]
409 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn without_schema_validationrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]without_schema_validation().(mut self) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
410 self.validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema. = false;
411 self
412 }
413 /// Set whether to validate formats.
414 ///
415 /// Default behavior depends on the draft version. This method overrides
416 /// the default, enabling or disabling format validation regardless of draft.
417 #[inline]
418 #[must_use]
419 pub fn should_validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]should_validate_formats().(mut self, yes: bool) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
420 self.validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(yes);
421 self
422 }
423 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]validate_formats().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool> {
424 self.validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.
425 }
426 /// Set whether to ignore unknown formats.
427 ///
428 /// By default, unknown formats are silently ignored. Set to `false` to report
429 /// unrecognized formats as validation errors.
430 #[must_use]
431 pub fn should_ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]should_ignore_unknown_formats().(mut self, yes: bool) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`] {
432 self.ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats. = yes;
433 self
434 }
435
436 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) const fn are_unknown_formats_ignoredrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]are_unknown_formats_ignored().(&self) -> bool {
437 self.ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.
438 }
439 /// Register a custom keyword validator.
440 ///
441 /// ## Example
442 ///
443 /// ```rust
444 /// # use jsonschema::{
445 /// # paths::{LazyLocation, Location},
446 /// # ErrorIterator, Keyword, ValidationError,
447 /// # };
448 /// # use serde_json::{json, Map, Value};
449 /// # use std::iter::once;
450 ///
451 /// struct MyCustomValidator;
452 ///
453 /// impl Keyword for MyCustomValidator {
454 /// fn validate<'i>(
455 /// &self,
456 /// instance: &'i Value,
457 /// location: &LazyLocation,
458 /// ) -> Result<(), ValidationError<'i>> {
459 /// // ... validate instance ...
460 /// if !instance.is_object() {
461 /// return Err(ValidationError::custom(
462 /// Location::new(),
463 /// location.into(),
464 /// instance,
465 /// "Boom!",
466 /// ));
467 /// } else {
468 /// Ok(())
469 /// }
470 /// }
471 /// fn is_valid(&self, instance: &Value) -> bool {
472 /// // ... determine if instance is valid ...
473 /// true
474 /// }
475 /// }
476 ///
477 /// // You can create a factory function, or use a closure to create new validator instances.
478 /// fn custom_validator_factory<'a>(
479 /// parent: &'a Map<String, Value>,
480 /// value: &'a Value,
481 /// path: Location,
482 /// ) -> Result<Box<dyn Keyword>, ValidationError<'a>> {
483 /// Ok(Box::new(MyCustomValidator))
484 /// }
485 ///
486 /// let validator = jsonschema::options()
487 /// .with_keyword("my-type", custom_validator_factory)
488 /// .with_keyword("my-type-with-closure", |_, _, _| Ok(Box::new(MyCustomValidator)))
489 /// .build(&json!({ "my-type": "my-schema"}))
490 /// .expect("A valid schema");
491 ///
492 /// assert!(validator.is_valid(&json!({ "a": "b"})));
493 /// ```
494 #[must_use]
495 pub fn with_keywordrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_keyword().<N, F>(mut self, name: N, factory: F) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]
496 where
497 N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
498 F: for<'a> Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(
499 &'a serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::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#>,
500 &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
501 Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
502 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>>
503 + ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound#
504 + 'static,
505 {
506 self.keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords..insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(factory));
507 self
508 }
509
510 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn get_keyword_factoryrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]get_keyword_factory().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn KeywordFactoryrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory#>> {
511 self.keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(name)
512 }
513 }
514
515 impl ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn referencingrust-analyzer cargo referencing 0.37.4 crate/::Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> {
516 /// Build a JSON Schema validator using the current options.
517 ///
518 /// # Example
519 ///
520 /// ```rust
521 /// use serde_json::json;
522 ///
523 /// let schema = json!({"type": "string"});
524 /// let validator = jsonschema::options()
525 /// .build(&schema)
526 /// .expect("A valid schema");
527 ///
528 /// assert!(validator.is_valid(&json!("Hello")));
529 /// assert!(!validator.is_valid(&json!(42)));
530 /// ```
531 ///
532 /// # Errors
533 ///
534 /// Returns an error if `schema` is invalid for the selected draft or if referenced resources
535 /// cannot be retrieved or resolved.
536 pub fn buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&self, schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Validatorrust-analyzer cargo jsonschema 0.37.4 validator/Validator#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'static>> {
537 compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::build_validatorrust-analyzer cargo jsonschema 0.37.4 compiler/build_validator().(self, schema)
538 }
539 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn draft_forrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]draft_for().(&self, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'static>> {
540 // Preference:
541 // - Explicitly set
542 // - Autodetected (with registry resolution for custom meta-schemas)
543 // - Default
544 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(draft) = self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft. {
545 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(draft)
546 } else {
547 let default = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().();
548 let detected = default.detectrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]detect().(contents);
549
550 // If detected draft is Unknown (custom meta-schema), try to resolve it
551 if detected rust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][`PartialEq<Self>`]eq().==rust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][`PartialEq<Self>`]eq(). rust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][`PartialEq<Self>`]eq().Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Unknownrust-analyzer cargo referencing 0.37.4 specification/Draft#Unknown# {
552 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(registry) = &self.registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry. {
553 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta_schema_uri) = contents
554 .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().()
555 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|obj| obj.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$schema"))
556 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().())
557 {
558 // Walk the meta-schema chain to find the underlying draft
559 return Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]::resolve_draft_from_registryrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]resolve_draft_from_registry().(meta_schema_uri, registry);
560 }
561 }
562 }
563
564 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(detected)
565 }
566 }
567
568 fn resolve_draft_from_registryrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]resolve_draft_from_registry().(
569 uri: &str,
570 registry: &referencingrust-analyzer cargo referencing 0.37.4 crate/::Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#,
571 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'static>> {
572 let uri = uri.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().('#');
573 craterust-analyzer cargo jsonschema 0.37.4 crate/::metarust-analyzer cargo jsonschema 0.37.4 meta/::walk_meta_schema_chainrust-analyzer cargo jsonschema 0.37.4 meta/walk_meta_schema_chain().(uri, |current_uri| {
574 let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().(current_uri)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
575 let resolved = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
576 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().().clonerust-analyzer cargo serde_json 1.0.145 value/impl#[Value][Clone]clone().())
577 })
578 }
579 /// Set a retriever to fetch external resources.
580 #[must_use]
581 pub fn with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_retriever().(mut self, retriever: impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# + 'static) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions] {
582 self.retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever. = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(retriever);
583 self
584 }
585 /// Configure the regular expression engine used during validation for keywords like `pattern`
586 /// or `patternProperties`.
587 ///
588 /// The default engine is [fancy-regex](https://docs.rs/fancy-regex), which supports advanced
589 /// features (e.g., backreferences, look-around). Be aware that using these may lead to exponential
590 /// runtime due to backtracking. For simpler regexes without these features, [regex](https://docs.rs/regex)
591 /// provides linear time performance.
592 ///
593 /// # Example
594 ///
595 /// ```rust
596 /// use serde_json::json;
597 /// use jsonschema::PatternOptions;
598 ///
599 /// let schema = json!({"type": "string"});
600 ///
601 /// // Set backtracking limit to 20000.
602 /// let validator = jsonschema::options()
603 /// .with_pattern_options(
604 /// PatternOptions::fancy_regex()
605 /// .backtrack_limit(20000)
606 /// )
607 /// .build(&schema)
608 /// .expect("A valid schema");
609 /// ```
610 #[must_use]
611 #[allow(clippy::needless_pass_by_value)]
612 pub fn with_pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]with_pattern_options().<E>(mut self, options: PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<E>) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions] {
613 self.pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options. = options.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.;
614 self
615 }
616 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]pattern_options().(&self) -> PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions# {
617 self.pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.
618 }
619 }
620
621 #[cfg(feature = "resolve-async")]
622 impl ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn referencingrust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>> {
623 /// Build a JSON Schema validator using the current async options.
624 ///
625 /// # Errors
626 ///
627 /// Returns an error if `schema` is invalid for the selected draft or if referenced resources
628 /// cannot be retrieved or resolved.
629 pub async fn buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().(&self, schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Validatorrust-analyzer cargo jsonschema 0.37.4 validator/Validator#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'static>> {
630 compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::build_validator_asyncrust-analyzer cargo jsonschema 0.37.4 compiler/build_validator_async().(self, schema).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
631 }
632 #[must_use]
633 pub fn with_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`]with_retriever().(
634 self,
635 retriever: impl referencingrust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve# + 'static,
636 ) -> ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn referencingrust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>> {
637 ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions# {
638 draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.: self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.,
639 retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(retriever),
640 content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.: self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.,
641 content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.: self.content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.,
642 base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
643 resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.: self.resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.,
644 registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.: self.registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.,
645 formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.: self.formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.,
646 validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.: self.validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.,
647 validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.: self.validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.,
648 ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.: self.ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.,
649 keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.: self.keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.,
650 pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.: self.pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.,
651 }
652 }
653 #[allow(clippy::unused_async)]
654 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) async fn draft_forrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`]draft_for().(
655 &self,
656 contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
657 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'static>> {
658 // Preference:
659 // - Explicitly set
660 // - Autodetected
661 // - Default
662 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(draft) = self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft. {
663 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(draft)
664 } else {
665 let default = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().();
666 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(default.detectrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]detect().(contents))
667 }
668 }
669 /// Set a retriever to fetch external resources.
670 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn with_blocking_retrieverrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<Arc<dyn AsyncRetrieve + 'static>>`]with_blocking_retriever().(
671 self,
672 retriever: impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# + 'static,
673 ) -> ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> {
674 ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions# {
675 draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.: self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.,
676 retrieverrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#retriever.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(retriever),
677 content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.: self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks.,
678 content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.: self.content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters.,
679 base_urirust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#base_uri.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
680 resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.: self.resourcesrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#resources.,
681 registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.: self.registryrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#registry.,
682 formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.: self.formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#formats.,
683 validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.: self.validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_formats.,
684 validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.: self.validate_schemarust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#validate_schema.,
685 ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.: self.ignore_unknown_formatsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#ignore_unknown_formats.,
686 keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.: self.keywordsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#keywords.,
687 pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.: self.pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#pattern_options.,
688 }
689 }
690 }
691
692 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ValidationOptionsrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions# {
693 fn fmtrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
694 fmt.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("CompilationConfig")
695 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("draft", &self.draftrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#draft.)
696 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("content_media_type", &self.content_media_type_checksrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_media_type_checks..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().())
697 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().(
698 "content_encoding",
699 &self.content_encoding_checks_and_convertersrust-analyzer cargo jsonschema 0.37.4 options/ValidationOptions#content_encoding_checks_and_converters..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().(),
700 )
701 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
702 }
703 }
704
705 /// Configuration for how regular expressions are handled in schema keywords like `pattern` and `patternProperties`.
706 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
707 pub struct PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<E> {
708 innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#,
709 _markerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<E>,
710 }
711
712 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
713 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) enum PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions# {
714 FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
715 backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#backtrack_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
716 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#size_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
717 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#dfa_size_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
718 },
719 Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# {
720 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#size_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
721 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#dfa_size_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
722 },
723 }
724
725 /// Marker for using the `fancy-regex` engine that includes advanced features like lookarounds.
726 pub struct FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/FancyRegex#;
727 /// Marker for using the `regex` engine, that has fewer features than `fancy-regex` but guarantees
728 /// linear time performance.
729 pub struct Regexrust-analyzer cargo jsonschema 0.37.4 options/Regex#;
730
731 impl PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/FancyRegex#> {
732 /// Create a pattern configuration based on the `fancy-regex` engine.
733 #[must_use]
734 pub fn fancy_regexrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]fancy_regex().() -> PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/FancyRegex#> {
735 PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions# {
736 innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
737 backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#backtrack_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
738 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
739 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#dfa_size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
740 },
741 _markerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
742 }
743 }
744 /// Limit for how many times backtracking should be attempted for fancy regexes (where
745 /// backtracking is used). If this limit is exceeded, execution returns an error.
746 /// This is for preventing a regex with catastrophic backtracking to run for too long.
747 ///
748 /// Default is `1_000_000` (1 million).
749 #[must_use]
750 pub fn backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]backtrack_limit().(mut self, limit: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`] {
751 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
752 ref mut backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#backtrack_limit.,
753 ..
754 } = self.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
755 {
756 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().backtrack_limit = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit);
757 }
758 self
759 }
760 /// Set the approximate size limit, in bytes, of the compiled regex.
761 #[must_use]
762 pub fn size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]size_limit().(mut self, limit: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`] {
763 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
764 ref mut size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#size_limit., ..
765 } = self.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
766 {
767 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().size_limit = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit);
768 }
769 self
770 }
771 /// Set the approximate capacity, in bytes, of the cache of transitions used by the lazy DFA.
772 #[must_use]
773 pub fn dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]dfa_size_limit().(mut self, limit: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`] {
774 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
775 ref mut dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#dfa_size_limit.,
776 ..
777 } = self.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
778 {
779 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dfa_size_limit = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit);
780 }
781 self
782 }
783 }
784
785 impl PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<Regexrust-analyzer cargo jsonschema 0.37.4 options/Regex#> {
786 /// Create a pattern configuration based on the `regex` engine.
787 #[must_use]
788 pub fn regexrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]regex().() -> PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#<Regexrust-analyzer cargo jsonschema 0.37.4 options/Regex#> {
789 PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions# {
790 innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.: PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# {
791 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
792 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#dfa_size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
793 },
794 _markerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
795 }
796 }
797 /// Set the approximate size limit, in bytes, of the compiled regex.
798 #[must_use]
799 pub fn size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]size_limit().(mut self, limit: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`] {
800 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# {
801 ref mut size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#size_limit., ..
802 } = self.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
803 {
804 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().size_limit = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit);
805 }
806 self
807 }
808 /// Set the approximate capacity, in bytes, of the cache of transitions used by the lazy DFA.
809 #[must_use]
810 pub fn dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]dfa_size_limit().(mut self, limit: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`] {
811 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# {
812 ref mut dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#dfa_size_limit.,
813 ..
814 } = self.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
815 {
816 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dfa_size_limit = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit);
817 }
818 self
819 }
820 }
821
822 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions# {
823 fn defaultrust-analyzer cargo jsonschema 0.37.4 options/impl#[PatternEngineOptions][Default]default().() -> Selfrust-analyzer cargo jsonschema 0.37.4 options/impl#[PatternEngineOptions][Default] {
824 PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
825 backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#backtrack_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
826 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
827 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#dfa_size_limit.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
828 }
829 }
830 }
831
832 #[cfg(test)]
833 mod testsrust-analyzer cargo jsonschema 0.37.4 options/tests/ {
834 use superrust-analyzer cargo jsonschema 0.37.4 options/::*;
835 use referencingrust-analyzer cargo referencing 0.37.4 crate/::{Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#};
836 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!;
837
838 fn customrust-analyzer cargo jsonschema 0.37.4 options/tests/custom().(s: &str) -> bool {
839 s.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("42!")
840 }
841
842 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
843 fn custom_formatrust-analyzer cargo jsonschema 0.37.4 options/tests/custom_format().() {
844 let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string", "format": "custom"});
845 let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().()
846 .with_formatrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_format().("custom", customrust-analyzer cargo jsonschema 0.37.4 options/tests/custom().)
847 .should_validate_formatsrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]should_validate_formats().(true)
848 .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema)
849 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Valid schema");
850 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!!("foo")));
851 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!!("foo42!")));
852 }
853
854 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
855 fn with_registryrust-analyzer cargo jsonschema 0.37.4 options/tests/with_registry().() {
856 let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().(
857 "urn:name-schema",
858 Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"})),
859 )
860 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid URI");
861 let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({
862 "properties": {
863 "name": { "$ref": "urn:name-schema" }
864 }
865 });
866 let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().()
867 .with_registryrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_registry().(registry)
868 .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema)
869 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid schema");
870 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!!({ "name": "Valid String" })));
871 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!!({ "name": 123 })));
872 }
873
874 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
875 fn test_fancy_regex_options_builderrust-analyzer cargo jsonschema 0.37.4 options/tests/test_fancy_regex_options_builder().() {
876 let options = PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#::fancy_regexrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]fancy_regex().()
877 .backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]backtrack_limit().(1_000_000)
878 .size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]size_limit().(10_000)
879 .dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<FancyRegex>`]dfa_size_limit().(5000);
880
881 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# {
882 backtrack_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#backtrack_limit.,
883 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#size_limit.,
884 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex#dfa_size_limit.,
885 } = options.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
886 {
887 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(backtrack_limit, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1_000_000));
888 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(size_limit, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(10_000));
889 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(dfa_size_limit, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5000));
890 } else {
891 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected FancyRegex variant");
892 }
893 }
894
895 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
896 #[should_panic(expected = "Draft::Unknown is internal-only and cannot be explicitly set")]
897 fn with_draft_rejects_unknownrust-analyzer cargo jsonschema 0.37.4 options/tests/with_draft_rejects_unknown().() {
898 let _options = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().().with_draftrust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_draft().(Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Unknownrust-analyzer cargo referencing 0.37.4 specification/Draft#Unknown#);
899 }
900
901 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
902 fn custom_meta_schema_allowed_when_draft_overriddenrust-analyzer cargo jsonschema 0.37.4 options/tests/custom_meta_schema_allowed_when_draft_overridden().() {
903 let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({
904 "$schema": "json-schema:///custom/meta",
905 "type": "string"
906 });
907
908 craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().()
909 .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#)
910 .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&schema)
911 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Explicit draft override should bypass custom meta-schema registry checks");
912 }
913
914 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
915 fn test_regex_options_builderrust-analyzer cargo jsonschema 0.37.4 options/tests/test_regex_options_builder().() {
916 let options = PatternOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#::regexrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]regex().()
917 .size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]size_limit().(20_000)
918 .dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/impl#[`PatternOptions<Regex>`]dfa_size_limit().(8000);
919
920 if let PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# {
921 size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#size_limit.,
922 dfa_size_limitrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex#dfa_size_limit.,
923 } = options.innerrust-analyzer cargo jsonschema 0.37.4 options/PatternOptions#inner.
924 {
925 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(size_limit, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(20_000));
926 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(dfa_size_limit, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(8000));
927 } else {
928 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Regex variant");
929 }
930 }
931
932 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
933 fn test_validate_against_definitionrust-analyzer cargo jsonschema 0.37.4 options/tests/test_validate_against_definition().() {
934 // Root schema with multiple definitions
935 let root_schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({
936 "$id": "https://example.com/root",
937 "definitions": {
938 "User": {
939 "type": "object",
940 "properties": {
941 "name": {"type": "string"},
942 "age": {"type": "integer", "minimum": 0}
943 },
944 "required": ["name"]
945 },
946 "Product": {
947 "type": "object",
948 "properties": {
949 "id": {"type": "integer"},
950 "title": {"type": "string"}
951 },
952 "required": ["id", "title"]
953 }
954 }
955 });
956
957 // Create a schema that references the specific definition
958 let user_schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "https://example.com/root#/definitions/User"});
959
960 // Build validator with the root schema registered as a resource
961 let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options().()
962 .with_resourcerust-analyzer cargo jsonschema 0.37.4 options/impl#[`ValidationOptions<R>`]with_resource().(
963 "https://example.com/root",
964 Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(root_schema),
965 )
966 .buildrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]build().(&user_schema)
967 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Valid schema");
968
969 // Valid user
970 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!!({"name": "Alice", "age": 30})));
971 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!!({"name": "Bob"})));
972
973 // Invalid: missing required field
974 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!!({"age": 25})));
975
976 // Invalid: wrong type for age
977 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!!({"name": "Charlie", "age": "thirty"})));
978 }
979 }