| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#, VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#}, |
| 3 | numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::NonZeroUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroUsize#, |
| 4 | pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#, |
| 5 | 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#, LazyLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/lazy_lock/LazyLock#}, |
| 6 | }; |
| 7 | |
| 8 | use ahashrust-analyzer cargo ahash 0.8.12 crate/::{AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#, AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#}; |
| 9 | use fluent_urirust-analyzer cargo fluent-uri 0.4.1 crate/::{pct_encrust-analyzer cargo fluent-uri 0.4.1 pct_enc/::EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#}; |
| 10 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Valuerust-analyzer cargo serde_json 1.0.145 value/Value#; |
| 11 | |
| 12 | use craterust-analyzer cargo referencing 0.37.4 crate/::{ |
| 13 | anchorsrust-analyzer cargo referencing 0.37.4 anchors/::{AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#}, |
| 14 | cacherust-analyzer cargo referencing 0.37.4 cache/::{SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#, UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#}, |
| 15 | metarust-analyzer cargo referencing 0.37.4 meta/::{selfrust-analyzer cargo referencing 0.37.4 meta/, metas_for_draftrust-analyzer cargo referencing 0.37.4 meta/metas_for_draft().}, |
| 16 | resourcerust-analyzer cargo referencing 0.37.4 resource/::{unescape_segmentrust-analyzer cargo referencing 0.37.4 resource/unescape_segment()., InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, JsonSchemaResourcerust-analyzer cargo referencing 0.37.4 resource/JsonSchemaResource#}, |
| 17 | urirust-analyzer cargo referencing 0.37.4 uri/, |
| 18 | vocabulariesrust-analyzer cargo referencing 0.37.4 vocabularies/::{selfrust-analyzer cargo referencing 0.37.4 vocabularies/, VocabularySetrust-analyzer cargo referencing 0.37.4 vocabularies/VocabularySet#}, |
| 19 | Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#, DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#, Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, ResourceRefrust-analyzer cargo referencing 0.37.4 resource/ResourceRef#, Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, |
| 20 | }; |
| 21 | |
| 22 | /// An owned-or-refstatic wrapper for JSON `Value`. |
| 23 | #[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:)] |
| 24 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) enum ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper# { |
| 25 | Ownedrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#Owned#(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#), |
| 26 | StaticRefrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#StaticRef#(&'static Valuerust-analyzer cargo serde_json 1.0.145 value/Value#), |
| 27 | } |
| 28 | |
| 29 | impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#> for ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper# { |
| 30 | fn as_refrust-analyzer cargo referencing 0.37.4 registry/impl#[ValueWrapper][`AsRef<Value>`]as_ref().(&self) -> &Valuerust-analyzer cargo serde_json 1.0.145 value/Value# { |
| 31 | match self { |
| 32 | ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#::Ownedrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#Owned#(value) => value, |
| 33 | ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#::StaticRefrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#StaticRef#(value) => value, |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // SAFETY: `Pin` guarantees stable memory locations for resource pointers, |
| 39 | // while `Arc` enables cheap sharing between multiple registries |
| 40 | type DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore# = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#>>>; |
| 41 | type ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap# = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#>; |
| 42 | |
| 43 | /// Pre-loaded registry containing all JSON Schema meta-schemas and their vocabularies |
| 44 | pub static SPECIFICATIONSrust-analyzer cargo referencing 0.37.4 registry/SPECIFICATIONS.: LazyLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/lazy_lock/LazyLock#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#> = |
| 45 | LazyLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/lazy_lock/LazyLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/lazy_lock/impl#[`LazyLock<T, F>`]new().(|| Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::build_from_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]build_from_meta_schemas().(metarust-analyzer cargo referencing 0.37.4 meta/::META_SCHEMAS_ALLrust-analyzer cargo referencing 0.37.4 meta/META_SCHEMAS_ALL..as_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]as_slice().())); |
| 46 | |
| 47 | /// A registry of JSON Schema resources, each identified by their canonical URIs. |
| 48 | /// |
| 49 | /// Registries store a collection of in-memory resources and their anchors. |
| 50 | /// They eagerly process all added resources, including their subresources and anchors. |
| 51 | /// This means that subresources contained within any added resources are immediately |
| 52 | /// discoverable and retrievable via their own IDs. |
| 53 | /// |
| 54 | /// # Resource Retrieval |
| 55 | /// |
| 56 | /// Registry supports both blocking and non-blocking retrieval of external resources. |
| 57 | /// |
| 58 | /// ## Blocking Retrieval |
| 59 | /// |
| 60 | /// ```rust |
| 61 | /// use referencing::{Registry, Resource, Retrieve, Uri}; |
| 62 | /// use serde_json::{json, Value}; |
| 63 | /// |
| 64 | /// struct ExampleRetriever; |
| 65 | /// |
| 66 | /// impl Retrieve for ExampleRetriever { |
| 67 | /// fn retrieve( |
| 68 | /// &self, |
| 69 | /// uri: &Uri<String> |
| 70 | /// ) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> { |
| 71 | /// // Always return the same value for brevity |
| 72 | /// Ok(json!({"type": "string"})) |
| 73 | /// } |
| 74 | /// } |
| 75 | /// |
| 76 | /// # fn example() -> Result<(), Box<dyn std::error::Error>> { |
| 77 | /// let registry = Registry::options() |
| 78 | /// .retriever(ExampleRetriever) |
| 79 | /// .build([ |
| 80 | /// // Initial schema that might reference external schemas |
| 81 | /// ( |
| 82 | /// "https://example.com/user.json", |
| 83 | /// Resource::from_contents(json!({ |
| 84 | /// "type": "object", |
| 85 | /// "properties": { |
| 86 | /// // Should be retrieved by `ExampleRetriever` |
| 87 | /// "role": {"$ref": "https://example.com/role.json"} |
| 88 | /// } |
| 89 | /// })) |
| 90 | /// ) |
| 91 | /// ])?; |
| 92 | /// # Ok(()) |
| 93 | /// # } |
| 94 | /// ``` |
| 95 | /// |
| 96 | /// ## Non-blocking Retrieval |
| 97 | /// |
| 98 | /// ```rust |
| 99 | /// # #[cfg(feature = "retrieve-async")] |
| 100 | /// # mod example { |
| 101 | /// use referencing::{Registry, Resource, AsyncRetrieve, Uri}; |
| 102 | /// use serde_json::{json, Value}; |
| 103 | /// |
| 104 | /// struct ExampleRetriever; |
| 105 | /// |
| 106 | /// #[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] |
| 107 | /// #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] |
| 108 | /// impl AsyncRetrieve for ExampleRetriever { |
| 109 | /// async fn retrieve( |
| 110 | /// &self, |
| 111 | /// uri: &Uri<String> |
| 112 | /// ) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> { |
| 113 | /// // Always return the same value for brevity |
| 114 | /// Ok(json!({"type": "string"})) |
| 115 | /// } |
| 116 | /// } |
| 117 | /// |
| 118 | /// # async fn example() -> Result<(), Box<dyn std::error::Error>> { |
| 119 | /// let registry = Registry::options() |
| 120 | /// .async_retriever(ExampleRetriever) |
| 121 | /// .build([ |
| 122 | /// ( |
| 123 | /// "https://example.com/user.json", |
| 124 | /// Resource::from_contents(json!({ |
| 125 | /// // Should be retrieved by `ExampleRetriever` |
| 126 | /// "$ref": "https://example.com/common/user.json" |
| 127 | /// })) |
| 128 | /// ) |
| 129 | /// ]) |
| 130 | /// .await?; |
| 131 | /// # Ok(()) |
| 132 | /// # } |
| 133 | /// # } |
| 134 | /// ``` |
| 135 | /// |
| 136 | /// The registry will automatically: |
| 137 | /// |
| 138 | /// - Resolve external references |
| 139 | /// - Cache retrieved schemas |
| 140 | /// - Handle nested references |
| 141 | /// - Process JSON Schema anchors |
| 142 | /// |
| 143 | #[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:)] |
| 144 | pub struct Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 145 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents.: DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 146 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources.: ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 147 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 148 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#, |
| 149 | } |
| 150 | |
| 151 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 152 | fn clonerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone]clone().(&self) -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone] { |
| 153 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone] { |
| 154 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents.: self.documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents..clonerust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`][Clone]clone().(), |
| 155 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources.: self.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources..clonerust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`][Clone]clone().(), |
| 156 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors.: self.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors..clonerust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`][Clone]clone().(), |
| 157 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: self.resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache..clonerust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache][Clone]clone().(), |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /// Configuration options for creating a [`Registry`]. |
| 163 | pub struct RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<R> { |
| 164 | retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#retriever.: R, |
| 165 | draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft.: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 166 | } |
| 167 | |
| 168 | impl<R> RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<R> { |
| 169 | /// Set specification version under which the resources should be interpreted under. |
| 170 | #[must_use] |
| 171 | pub fn draftrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<R>`]draft().(mut self, draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#) -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<R>`] { |
| 172 | self.draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft. = draft; |
| 173 | self |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | impl RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> { |
| 178 | /// Create a new [`RegistryOptions`] with default settings. |
| 179 | #[must_use] |
| 180 | pub fn newrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]new().() -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`] { |
| 181 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`] { |
| 182 | retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#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 referencing 0.37.4 retriever/DefaultRetriever#), |
| 183 | draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft.: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().(), |
| 184 | } |
| 185 | } |
| 186 | /// Set a custom retriever for the [`Registry`]. |
| 187 | #[must_use] |
| 188 | pub fn retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]retriever().(mut self, retriever: impl IntoRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever#) -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`] { |
| 189 | self.retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#retriever. = retriever.into_retrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever#into_retriever().(); |
| 190 | self |
| 191 | } |
| 192 | /// Set a custom async retriever for the [`Registry`]. |
| 193 | #[cfg(feature = "retrieve-async")] |
| 194 | #[must_use] |
| 195 | pub fn async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().( |
| 196 | self, |
| 197 | retriever: impl IntoAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever#, |
| 198 | ) -> RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>> { |
| 199 | RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions# { |
| 200 | retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#retriever.: retriever.into_retrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever#into_retriever().(), |
| 201 | draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft.: self.draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft., |
| 202 | } |
| 203 | } |
| 204 | /// Create a [`Registry`] from multiple resources using these options. |
| 205 | /// |
| 206 | /// # Errors |
| 207 | /// |
| 208 | /// Returns an error if: |
| 209 | /// - Any URI is invalid |
| 210 | /// - Any referenced resources cannot be retrieved |
| 211 | pub fn buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]build().( |
| 212 | self, |
| 213 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 214 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 215 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resources_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_impl().(pairs, &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().self.retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#retriever., self.draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft.) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | #[cfg(feature = "retrieve-async")] |
| 220 | impl RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>> { |
| 221 | /// Create a [`Registry`] from multiple resources using these options with async retrieval. |
| 222 | /// |
| 223 | /// # Errors |
| 224 | /// |
| 225 | /// Returns an error if: |
| 226 | /// - Any URI is invalid |
| 227 | /// - Any referenced resources cannot be retrieved |
| 228 | pub async fn buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().( |
| 229 | self, |
| 230 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 231 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 232 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resources_async_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_async_impl().(pairs, &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().self.retrieverrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#retriever., self.draftrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#draft.).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(). |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | pub trait IntoRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever# { |
| 237 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever#into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>; |
| 238 | } |
| 239 | |
| 240 | impl<T: Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# + 'static> IntoRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever# for T { |
| 241 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[T][IntoRetriever]into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#> { |
| 242 | 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().(self) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | impl IntoRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoRetriever# for Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#> { |
| 247 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`Arc<dyn Retrieve + 'static>`][IntoRetriever]into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#> { |
| 248 | self |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | #[cfg(feature = "retrieve-async")] |
| 253 | pub trait IntoAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever# { |
| 254 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever#into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#>; |
| 255 | } |
| 256 | |
| 257 | #[cfg(feature = "retrieve-async")] |
| 258 | impl<T: craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve# + 'static> IntoAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever# for T { |
| 259 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[T][IntoAsyncRetriever]into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#> { |
| 260 | 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().(self) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | #[cfg(feature = "retrieve-async")] |
| 265 | impl IntoAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/IntoAsyncRetriever# for Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#> { |
| 266 | fn into_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`Arc<dyn AsyncRetrieve + 'static>`][IntoAsyncRetriever]into_retriever().(self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#> { |
| 267 | self |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> { |
| 272 | fn defaultrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`][Default]default().() -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`][Default] { |
| 273 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`][Default]::newrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]new().() |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | impl Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 278 | /// Get [`RegistryOptions`] for configuring a new [`Registry`]. |
| 279 | #[must_use] |
| 280 | pub fn optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() -> RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#>> { |
| 281 | RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#::newrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]new().() |
| 282 | } |
| 283 | /// Create a new [`Registry`] with a single resource. |
| 284 | /// |
| 285 | /// # Arguments |
| 286 | /// |
| 287 | /// * `uri` - The URI of the resource. |
| 288 | /// * `resource` - The resource to add. |
| 289 | /// |
| 290 | /// # Errors |
| 291 | /// |
| 292 | /// Returns an error if the URI is invalid or if there's an issue processing the resource. |
| 293 | pub fn try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().(uri: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, resource: Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry], Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 294 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]::try_new_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new_impl().(uri, resource, &DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().()) |
| 295 | } |
| 296 | /// Create a new [`Registry`] from an iterator of (URI, Resource) pairs. |
| 297 | /// |
| 298 | /// # Arguments |
| 299 | /// |
| 300 | /// * `pairs` - An iterator of (URI, Resource) pairs. |
| 301 | /// |
| 302 | /// # Errors |
| 303 | /// |
| 304 | /// Returns an error if any URI is invalid or if there's an issue processing the resources. |
| 305 | pub fn try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().( |
| 306 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 307 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry], Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 308 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]::try_from_resources_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_impl().(pairs, &DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().()) |
| 309 | } |
| 310 | fn try_new_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new_impl().( |
| 311 | uri: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 312 | resource: Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, |
| 313 | retriever: &dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, |
| 314 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 315 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry], Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 316 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]::try_from_resources_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_impl().([(uri, resource)], retriever, draft) |
| 317 | } |
| 318 | fn try_from_resources_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_impl().( |
| 319 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 320 | retriever: &dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, |
| 321 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 322 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry], Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 323 | let mut documents = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 324 | let mut resources = ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 325 | let mut anchors = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 326 | let mut resolution_cache = UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#::newrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]new().(); |
| 327 | let custom_metaschemas = process_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_resources().( |
| 328 | pairs, |
| 329 | retriever, |
| 330 | &mut documents, |
| 331 | &mut resources, |
| 332 | &mut anchors, |
| 333 | &mut resolution_cache, |
| 334 | draft, |
| 335 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 336 | |
| 337 | // Validate that all custom $schema references are registered |
| 338 | validate_custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/validate_custom_metaschemas().(&custom_metaschemas, &resources)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 339 | |
| 340 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 341 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents., |
| 342 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources., |
| 343 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors., |
| 344 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: resolution_cache.into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(), |
| 345 | }) |
| 346 | } |
| 347 | /// Create a new [`Registry`] from an iterator of (URI, Resource) pairs using an async retriever. |
| 348 | /// |
| 349 | /// # Arguments |
| 350 | /// |
| 351 | /// * `pairs` - An iterator of (URI, Resource) pairs. |
| 352 | /// |
| 353 | /// # Errors |
| 354 | /// |
| 355 | /// Returns an error if any URI is invalid or if there's an issue processing the resources. |
| 356 | #[cfg(feature = "retrieve-async")] |
| 357 | async fn try_from_resources_async_implrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources_async_impl().( |
| 358 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 359 | retriever: &dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#, |
| 360 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 361 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry], Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 362 | let mut documents = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 363 | let mut resources = ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 364 | let mut anchors = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::newrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]new().(); |
| 365 | let mut resolution_cache = UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#::newrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]new().(); |
| 366 | |
| 367 | let custom_metaschemas = process_resources_asyncrust-analyzer cargo referencing 0.37.4 registry/process_resources_async().( |
| 368 | pairs, |
| 369 | retriever, |
| 370 | &mut documents, |
| 371 | &mut resources, |
| 372 | &mut anchors, |
| 373 | &mut resolution_cache, |
| 374 | draft, |
| 375 | ) |
| 376 | .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().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 377 | |
| 378 | // Validate that all custom $schema references are registered |
| 379 | validate_custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/validate_custom_metaschemas().(&custom_metaschemas, &resources)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 380 | |
| 381 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 382 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents., |
| 383 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources., |
| 384 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors., |
| 385 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: resolution_cache.into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(), |
| 386 | }) |
| 387 | } |
| 388 | /// Create a new registry with a new resource. |
| 389 | /// |
| 390 | /// # Errors |
| 391 | /// |
| 392 | /// Returns an error if the URI is invalid or if there's an issue processing the resource. |
| 393 | pub fn try_with_resourcerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resource().( |
| 394 | self, |
| 395 | uri: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 396 | resource: Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, |
| 397 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 398 | let draft = resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]draft().(); |
| 399 | self.try_with_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources().([(uri, resource)], draft) |
| 400 | } |
| 401 | /// Create a new registry with new resources. |
| 402 | /// |
| 403 | /// # Errors |
| 404 | /// |
| 405 | /// Returns an error if any URI is invalid or if there's an issue processing the resources. |
| 406 | pub fn try_with_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources().( |
| 407 | self, |
| 408 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 409 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 410 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 411 | self.try_with_resources_and_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources_and_retriever().(pairs, &DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#, draft) |
| 412 | } |
| 413 | /// Create a new registry with new resources and using the given retriever. |
| 414 | /// |
| 415 | /// # Errors |
| 416 | /// |
| 417 | /// Returns an error if any URI is invalid or if there's an issue processing the resources. |
| 418 | pub fn try_with_resources_and_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources_and_retriever().( |
| 419 | self, |
| 420 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 421 | retriever: &dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, |
| 422 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 423 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 424 | let mut documents = self.documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents.; |
| 425 | let mut resources = self.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources.; |
| 426 | let mut anchors = self.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors.; |
| 427 | let mut resolution_cache = self.resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache..into_localrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache]into_local().(); |
| 428 | let custom_metaschemas = process_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_resources().( |
| 429 | pairs, |
| 430 | retriever, |
| 431 | &mut documents, |
| 432 | &mut resources, |
| 433 | &mut anchors, |
| 434 | &mut resolution_cache, |
| 435 | draft, |
| 436 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 437 | validate_custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/validate_custom_metaschemas().(&custom_metaschemas, &resources)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 438 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 439 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents., |
| 440 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources., |
| 441 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors., |
| 442 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: resolution_cache.into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(), |
| 443 | }) |
| 444 | } |
| 445 | /// Create a new registry with new resources and using the given non-blocking retriever. |
| 446 | /// |
| 447 | /// # Errors |
| 448 | /// |
| 449 | /// Returns an error if any URI is invalid or if there's an issue processing the resources. |
| 450 | #[cfg(feature = "retrieve-async")] |
| 451 | pub async fn try_with_resources_and_retriever_asyncrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources_and_retriever_async().( |
| 452 | self, |
| 453 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 454 | retriever: &dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#, |
| 455 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 456 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 457 | let mut documents = self.documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents.; |
| 458 | let mut resources = self.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources.; |
| 459 | let mut anchors = self.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors.; |
| 460 | let mut resolution_cache = self.resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache..into_localrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache]into_local().(); |
| 461 | let custom_metaschemas = process_resources_asyncrust-analyzer cargo referencing 0.37.4 registry/process_resources_async().( |
| 462 | pairs, |
| 463 | retriever, |
| 464 | &mut documents, |
| 465 | &mut resources, |
| 466 | &mut anchors, |
| 467 | &mut resolution_cache, |
| 468 | draft, |
| 469 | ) |
| 470 | .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().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 471 | validate_custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/validate_custom_metaschemas().(&custom_metaschemas, &resources)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 472 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Registryrust-analyzer cargo referencing 0.37.4 registry/Registry# { |
| 473 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents., |
| 474 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources., |
| 475 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors., |
| 476 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: resolution_cache.into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(), |
| 477 | }) |
| 478 | } |
| 479 | /// Create a new [`Resolver`] for this registry with the given base URI. |
| 480 | /// |
| 481 | /// # Errors |
| 482 | /// |
| 483 | /// Returns an error if the base URI is invalid. |
| 484 | pub fn try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().(&self, base_uri: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#<'_>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 485 | let base = urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(base_uri)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 486 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]resolver().(base)) |
| 487 | } |
| 488 | /// Create a new [`Resolver`] for this registry with a known valid base URI. |
| 489 | #[must_use] |
| 490 | pub fn resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]resolver().(&self, base_uri: Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#<'_> { |
| 491 | Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#::newrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]new().(self, 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().(base_uri)) |
| 492 | } |
| 493 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn anchorrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]anchor().<'a>(&self, uri: &'a Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, name: &'a str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 494 | let key = AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#::newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]new().(uri, name); |
| 495 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(key.borrow_dynrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]borrow_dyn().()) { |
| 496 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value); |
| 497 | } |
| 498 | let resource = &self.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources.[rust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`][`Index<&Q>`]index().uri]rust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`][`Index<&Q>`]index().; |
| 499 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = resource.idrust-analyzer cargo referencing 0.37.4 resource/JsonSchemaResource#id().() { |
| 500 | let uri = urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(id)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 501 | let key = AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#::newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]new().(&uri, name); |
| 502 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(key.borrow_dynrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]borrow_dyn().()) { |
| 503 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value); |
| 504 | } |
| 505 | } |
| 506 | if name.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('/') { |
| 507 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::invalid_anchorrust-analyzer cargo referencing 0.37.4 error/impl#[Error]invalid_anchor().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 508 | } else { |
| 509 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::no_such_anchorrust-analyzer cargo referencing 0.37.4 error/impl#[Error]no_such_anchor().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 510 | } |
| 511 | } |
| 512 | /// Resolves a reference URI against a base URI using registry's cache. |
| 513 | /// |
| 514 | /// # Errors |
| 515 | /// |
| 516 | /// Returns an error if base has not schema or there is a fragment. |
| 517 | pub fn resolve_againstrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]resolve_against().(&self, base: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<&str>, uri: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 518 | self.resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache..resolve_againstrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache]resolve_against().(base, uri) |
| 519 | } |
| 520 | /// Returns vocabulary set configured for given draft and contents. |
| 521 | /// |
| 522 | /// For custom meta-schemas (`Draft::Unknown`), looks up the meta-schema in the registry |
| 523 | /// and extracts its `$vocabulary` declaration. If the meta-schema is not registered, |
| 524 | /// returns the default Draft 2020-12 vocabularies. |
| 525 | #[must_use] |
| 526 | pub fn find_vocabulariesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]find_vocabularies().(&self, draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> VocabularySetrust-analyzer cargo referencing 0.37.4 vocabularies/VocabularySet# { |
| 527 | match draft.detectrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]detect().(contents) { |
| 528 | Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Unknownrust-analyzer cargo referencing 0.37.4 specification/Draft#Unknown# => { |
| 529 | // Custom/unknown meta-schema - try to look it up in the registry |
| 530 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(specification) = contents |
| 531 | .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() |
| 532 | .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")) |
| 533 | .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().()) |
| 534 | { |
| 535 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mut uri) = urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(specification) { |
| 536 | // Remove fragment for lookup (e.g., "http://example.com/schema#" -> "http://example.com/schema") |
| 537 | // Resources are stored without fragments, so we must strip it to find the meta-schema |
| 538 | uri.set_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]set_fragment().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 539 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(resource) = self.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(&uri) { |
| 540 | // Found the custom meta-schema - extract vocabularies |
| 541 | if let 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#(vocabularies)) = vocabulariesrust-analyzer cargo referencing 0.37.4 vocabularies/::findrust-analyzer cargo referencing 0.37.4 vocabularies/find().(resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().()) |
| 542 | { |
| 543 | return vocabularies; |
| 544 | } |
| 545 | } |
| 546 | // Meta-schema not registered - this will be caught during compilation |
| 547 | // For now, return default vocabularies to allow resource creation |
| 548 | } |
| 549 | } |
| 550 | // Default to Draft 2020-12 vocabularies for unknown meta-schemas |
| 551 | Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Unknownrust-analyzer cargo referencing 0.37.4 specification/Draft#Unknown#.default_vocabulariesrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]default_vocabularies().() |
| 552 | } |
| 553 | draft => draft.default_vocabulariesrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]default_vocabularies().(), |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /// Build a registry with all the given meta-schemas from specs. |
| 558 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn build_from_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]build_from_meta_schemas().(schemas: &[(&'static str, &'static Valuerust-analyzer cargo serde_json 1.0.145 value/Value#)]) -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry] { |
| 559 | let schemas_count = schemas.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 560 | let pairs = schemas |
| 561 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 562 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(uri, schema)| (uri, ResourceRefrust-analyzer cargo referencing 0.37.4 resource/ResourceRef#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[`ResourceRef<'a>`]from_contents().(schema))); |
| 563 | |
| 564 | let mut documents = DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#::with_capacityrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]with_capacity().(schemas_count); |
| 565 | let mut resources = ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#::with_capacityrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]with_capacity().(schemas_count); |
| 566 | |
| 567 | // The actual number of anchors and cache-entries varies across |
| 568 | // drafts. We overshoot here to avoid reallocations, using the sum |
| 569 | // over all specifications. |
| 570 | let mut anchors = AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::with_capacityrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`]with_capacity().(8); |
| 571 | let mut resolution_cache = UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#::with_capacityrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]with_capacity().(35); |
| 572 | |
| 573 | process_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/process_meta_schemas().( |
| 574 | pairs, |
| 575 | &mut documents, |
| 576 | &mut resources, |
| 577 | &mut anchors, |
| 578 | &mut resolution_cache, |
| 579 | ) |
| 580 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to process meta schemas"); |
| 581 | |
| 582 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry] { |
| 583 | documentsrust-analyzer cargo referencing 0.37.4 registry/Registry#documents., |
| 584 | resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources., |
| 585 | anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors., |
| 586 | resolution_cacherust-analyzer cargo referencing 0.37.4 registry/Registry#resolution_cache.: resolution_cache.into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(), |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | fn process_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/process_meta_schemas().( |
| 592 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, ResourceRefrust-analyzer cargo referencing 0.37.4 resource/ResourceRef#<'static>)>, |
| 593 | documents: &mut DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 594 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 595 | anchors: &mut AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 596 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 597 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 598 | let mut queue = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]with_capacity().(32); |
| 599 | |
| 600 | for (uri, resource) in pairs { |
| 601 | let uri = urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(uri.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().('#'))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 602 | let key = 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().(uri); |
| 603 | let contents: &'static Valuerust-analyzer cargo serde_json 1.0.145 value/Value# = resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[`ResourceRef<'a>`]contents().(); |
| 604 | let wrapped_value = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]pin().(ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#::StaticRefrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#StaticRef#(contents)); |
| 605 | let resource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][Deref]deref().wrapped_value).as_refrust-analyzer cargo referencing 0.37.4 registry/impl#[ValueWrapper][`AsRef<Value>`]as_ref().(), resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[`ResourceRef<'a>`]draft().()); |
| 606 | documents.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), wrapped_value); |
| 607 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 608 | queue.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((key, resource)); |
| 609 | } |
| 610 | |
| 611 | // Process current queue and collect references to external resources |
| 612 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((mut base, resource)) = queue.pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() { |
| 613 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = resource.idrust-analyzer cargo referencing 0.37.4 resource/JsonSchemaResource#id().() { |
| 614 | base = resolution_cache.resolve_againstrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]resolve_against().(&base.borrowrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]borrow().(), id)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 615 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 616 | } |
| 617 | |
| 618 | // Look for anchors |
| 619 | for anchor in resource.anchorsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]anchors().() { |
| 620 | anchors.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#::newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey]new().(base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), anchor.namerust-analyzer cargo referencing 0.37.4 anchors/impl#[Anchor]name().()), anchor); |
| 621 | } |
| 622 | |
| 623 | // Process subresources |
| 624 | for contents in resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().().subresources_ofrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]subresources_of().(resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().()) { |
| 625 | let subresource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().()); |
| 626 | queue.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), subresource)); |
| 627 | } |
| 628 | } |
| 629 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 630 | } |
| 631 | |
| 632 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 633 | struct ReferenceKeyrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey# { |
| 634 | base_ptrrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#base_ptr.: NonZeroUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroUsize#, |
| 635 | referencerust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#reference.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 636 | } |
| 637 | |
| 638 | impl ReferenceKeyrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey# { |
| 639 | fn newrust-analyzer cargo referencing 0.37.4 registry/impl#[ReferenceKey]new().(base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, reference: &str) -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[ReferenceKey] { |
| 640 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[ReferenceKey] { |
| 641 | base_ptrrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#base_ptr.: NonZeroUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::as_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`]as_ptr().(base) as usize) |
| 642 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Arc pointer should never be null"), |
| 643 | referencerust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#reference.: reference.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | type ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker# = AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<ReferenceKeyrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#>; |
| 649 | |
| 650 | #[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:, 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:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 651 | enum ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind# { |
| 652 | Refrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#Ref#, |
| 653 | Schemarust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#Schema#, |
| 654 | } |
| 655 | |
| 656 | /// An entry in the processing queue. |
| 657 | /// The optional third element is the document root URI, used when the resource |
| 658 | /// was extracted from a fragment of a larger document. Local `$ref`s need to be |
| 659 | /// resolved against the document root, not just the fragment content. |
| 660 | type QueueEntryrust-analyzer cargo referencing 0.37.4 registry/QueueEntry# = (Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, 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#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>); |
| 661 | |
| 662 | struct ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState# { |
| 663 | queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<QueueEntryrust-analyzer cargo referencing 0.37.4 registry/QueueEntry#>, |
| 664 | seenrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#seen.: ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker#, |
| 665 | externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external.: AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#)>, |
| 666 | scratchrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#scratch.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 667 | refers_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#refers_metaschemas.: bool, |
| 668 | custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, |
| 669 | /// Tracks schema pointers we've visited during recursive external resource collection. |
| 670 | /// This prevents infinite recursion when schemas reference each other. |
| 671 | visited_schemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#visited_schemas.: AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<usize>, |
| 672 | } |
| 673 | |
| 674 | impl ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState# { |
| 675 | fn newrust-analyzer cargo referencing 0.37.4 registry/impl#[ProcessingState]new().() -> Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[ProcessingState] { |
| 676 | Selfrust-analyzer cargo referencing 0.37.4 registry/impl#[ProcessingState] { |
| 677 | queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]with_capacity().(32), |
| 678 | seenrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#seen.: ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker#::newrust-analyzer cargo ahash 0.8.12 hash_set/impl#[`AHashSet<T>`]new().(), |
| 679 | externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external.: AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#::newrust-analyzer cargo ahash 0.8.12 hash_set/impl#[`AHashSet<T>`]new().(), |
| 680 | scratchrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#scratch.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |
| 681 | refers_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#refers_metaschemas.: false, |
| 682 | custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 683 | visited_schemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#visited_schemas.: AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#::newrust-analyzer cargo ahash 0.8.12 hash_set/impl#[`AHashSet<T>`]new().(), |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | fn process_input_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_input_resources().( |
| 689 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 690 | documents: &mut DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 691 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 692 | state: &mut ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState#, |
| 693 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 694 | for (uri, resource) in pairs { |
| 695 | let uri = urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(uri.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().('#'))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 696 | let key = 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().(uri); |
| 697 | match documents.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key)) { |
| 698 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Occupiedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Occupied#(_) => {} |
| 699 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Vacantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Vacant#(entry) => { |
| 700 | let (draft, contents) = resource.into_innerrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]into_inner().(); |
| 701 | let wrapped_value = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]pin().(ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#::Ownedrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#Owned#(contents)); |
| 702 | let resource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][Deref]deref().wrapped_value).as_refrust-analyzer cargo referencing 0.37.4 registry/impl#[ValueWrapper][`AsRef<Value>`]as_ref().(), draft); |
| 703 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 704 | |
| 705 | // Track resources with custom meta-schemas for later validation |
| 706 | if draft 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# { |
| 707 | state.custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key)); |
| 708 | } |
| 709 | |
| 710 | state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((key, resource, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 711 | entry.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`VacantEntry<'a, K, V, A>`]insert().(wrapped_value); |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 716 | } |
| 717 | |
| 718 | fn process_queuerust-analyzer cargo referencing 0.37.4 registry/process_queue().( |
| 719 | state: &mut ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState#, |
| 720 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 721 | anchors: &mut AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 722 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 723 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 724 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((mut base, resource, document_root_uri)) = state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() { |
| 725 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = resource.idrust-analyzer cargo referencing 0.37.4 resource/JsonSchemaResource#id().() { |
| 726 | base = resolve_idrust-analyzer cargo referencing 0.37.4 registry/resolve_id().(&base, id, resolution_cache)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 727 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 728 | } |
| 729 | |
| 730 | for anchor in resource.anchorsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]anchors().() { |
| 731 | anchors.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#::newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey]new().(base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), anchor.namerust-analyzer cargo referencing 0.37.4 anchors/impl#[Anchor]name().()), anchor); |
| 732 | } |
| 733 | |
| 734 | // Determine the document root for resolving local $refs. |
| 735 | // If document_root_uri is set (e.g., for fragment-extracted resources), |
| 736 | // look up the full document. Otherwise, this resource IS the document root. |
| 737 | let root = document_root_uri |
| 738 | .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 739 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|uri| resources.getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(uri)) |
| 740 | .map_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or_else().(|| resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().(), InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().); |
| 741 | |
| 742 | // Skip if already visited during local $ref resolution |
| 743 | let contents_ptr = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::from_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/from_ref().::<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>(resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().()) as usize; |
| 744 | if state.visited_schemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#visited_schemas..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(contents_ptr) { |
| 745 | collect_external_resourcesrust-analyzer cargo referencing 0.37.4 registry/collect_external_resources().( |
| 746 | &base, |
| 747 | root, |
| 748 | resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().(), |
| 749 | &mut state.externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external., |
| 750 | &mut state.seenrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#seen., |
| 751 | resolution_cache, |
| 752 | &mut state.scratchrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#scratch., |
| 753 | &mut state.refers_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#refers_metaschemas., |
| 754 | resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().(), |
| 755 | &mut state.visited_schemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#visited_schemas., |
| 756 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 757 | } |
| 758 | |
| 759 | // Subresources inherit the document root URI, or use the current base if none set |
| 760 | let subresource_root_uri = document_root_uri.or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().())); |
| 761 | for contents in resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().().subresources_ofrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]subresources_of().(resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().()) { |
| 762 | let subresource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().()); |
| 763 | state |
| 764 | .queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue. |
| 765 | .push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), subresource, subresource_root_uri.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().())); |
| 766 | } |
| 767 | } |
| 768 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 769 | } |
| 770 | |
| 771 | fn handle_fragmentrust-analyzer cargo referencing 0.37.4 registry/handle_fragment().( |
| 772 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 773 | resource: &InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, |
| 774 | key: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 775 | default_draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 776 | queue: &mut VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<QueueEntryrust-analyzer cargo referencing 0.37.4 registry/QueueEntry#>, |
| 777 | document_root_uri: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 778 | ) { |
| 779 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fragment) = uri.fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]fragment().() { |
| 780 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(resolved) = pointerrust-analyzer cargo referencing 0.37.4 registry/pointer().(resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().(), fragment.as_strrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]as_str().()) { |
| 781 | let draft = default_draft.detectrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]detect().(resolved); |
| 782 | let contents = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::addr_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/addr_of!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().resolved); |
| 783 | let resource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft); |
| 784 | queue.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(key), resource, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(document_root_uri))); |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | fn handle_metaschemasrust-analyzer cargo referencing 0.37.4 registry/handle_metaschemas().( |
| 790 | refers_metaschemas: bool, |
| 791 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 792 | anchors: &mut AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 793 | draft_version: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 794 | ) { |
| 795 | if refers_metaschemas { |
| 796 | let schemas = metas_for_draftrust-analyzer cargo referencing 0.37.4 meta/metas_for_draft().(draft_version); |
| 797 | let draft_registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::build_from_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]build_from_meta_schemas().(schemas); |
| 798 | resources.reserverust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]reserve().(draft_registry.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()); |
| 799 | for (key, resource) in draft_registry.resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources. { |
| 800 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(key, resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 801 | } |
| 802 | anchors.reserverust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]reserve().(draft_registry.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()); |
| 803 | for (key, anchor) in draft_registry.anchorsrust-analyzer cargo referencing 0.37.4 registry/Registry#anchors. { |
| 804 | anchors.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(key, anchor); |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | fn create_resourcerust-analyzer cargo referencing 0.37.4 registry/create_resource().( |
| 810 | retrieved: Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 811 | fragmentless: Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 812 | default_draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 813 | documents: &mut DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 814 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 815 | custom_metaschemas: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, |
| 816 | ) -> (Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#) { |
| 817 | let draft = default_draft.detectrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]detect().(&retrieved); |
| 818 | let wrapped_value = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]pin().(ValueWrapperrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#::Ownedrust-analyzer cargo referencing 0.37.4 registry/ValueWrapper#Owned#(retrieved)); |
| 819 | let resource = InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][Deref]deref().wrapped_value).as_refrust-analyzer cargo referencing 0.37.4 registry/impl#[ValueWrapper][`AsRef<Value>`]as_ref().(), draft); |
| 820 | let key = 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().(fragmentless); |
| 821 | documents.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), wrapped_value); |
| 822 | resources.insertrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]insert().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr][Clone]clone().()); |
| 823 | |
| 824 | // Track resources with custom meta-schemas for later validation |
| 825 | if draft 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# { |
| 826 | custom_metaschemas.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key)); |
| 827 | } |
| 828 | |
| 829 | (key, resource) |
| 830 | } |
| 831 | |
| 832 | fn process_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_resources().( |
| 833 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 834 | retriever: &dyn Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#, |
| 835 | documents: &mut DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 836 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 837 | anchors: &mut AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 838 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 839 | default_draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 840 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 841 | let mut state = ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState#::newrust-analyzer cargo referencing 0.37.4 registry/impl#[ProcessingState]new().(); |
| 842 | process_input_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_input_resources().(pairs, documents, resources, &mut state)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 843 | |
| 844 | loop { |
| 845 | if state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]is_empty().() && state.externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() { |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | process_queuerust-analyzer cargo referencing 0.37.4 registry/process_queue().(&mut state, resources, anchors, resolution_cache)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 850 | |
| 851 | // Retrieve external resources |
| 852 | for (original, uri, kind) in state.externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external..drainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]drain().() { |
| 853 | let mut fragmentless = uri.clonerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][Clone]clone().(); |
| 854 | fragmentless.set_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]set_fragment().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 855 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().resources.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&fragmentless) { |
| 856 | let retrieved = match retriever.retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#retrieve().(&fragmentless) { |
| 857 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(retrieved) => retrieved, |
| 858 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => { |
| 859 | handle_retrieve_errorrust-analyzer cargo referencing 0.37.4 registry/handle_retrieve_error().(&uri, &original, &fragmentless, error, kind)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 860 | continue; |
| 861 | } |
| 862 | }; |
| 863 | |
| 864 | let (key, resource) = create_resourcerust-analyzer cargo referencing 0.37.4 registry/create_resource().( |
| 865 | retrieved, |
| 866 | fragmentless, |
| 867 | default_draft, |
| 868 | documents, |
| 869 | resources, |
| 870 | &mut state.custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas., |
| 871 | ); |
| 872 | handle_fragmentrust-analyzer cargo referencing 0.37.4 registry/handle_fragment().( |
| 873 | &uri, |
| 874 | &resource, |
| 875 | &key, |
| 876 | default_draft, |
| 877 | &mut state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue., |
| 878 | Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), |
| 879 | ); |
| 880 | state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((key, resource, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | handle_metaschemasrust-analyzer cargo referencing 0.37.4 registry/handle_metaschemas().(state.refers_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#refers_metaschemas., resources, anchors, default_draft); |
| 886 | |
| 887 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(state.custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas.) |
| 888 | } |
| 889 | |
| 890 | #[cfg(feature = "retrieve-async")] |
| 891 | async fn process_resources_asyncrust-analyzer cargo referencing 0.37.4 registry/process_resources_async().( |
| 892 | pairs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#)>, |
| 893 | retriever: &dyn craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#, |
| 894 | documents: &mut DocumentStorerust-analyzer cargo referencing 0.37.4 registry/DocumentStore#, |
| 895 | resources: &mut ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 896 | anchors: &mut AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#>, |
| 897 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 898 | default_draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 899 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 900 | let mut state = ProcessingStaterust-analyzer cargo referencing 0.37.4 registry/ProcessingState#::newrust-analyzer cargo referencing 0.37.4 registry/impl#[ProcessingState]new().(); |
| 901 | process_input_resourcesrust-analyzer cargo referencing 0.37.4 registry/process_input_resources().(pairs, documents, resources, &mut state)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 902 | |
| 903 | loop { |
| 904 | if state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]is_empty().() && state.externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() { |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | process_queuerust-analyzer cargo referencing 0.37.4 registry/process_queue().(&mut state, resources, anchors, resolution_cache)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 909 | |
| 910 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().state.externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() { |
| 911 | let data = state |
| 912 | .externalrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#external. |
| 913 | .drainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]drain().() |
| 914 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(original, uri, kind)| { |
| 915 | let mut fragmentless = uri.clonerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][Clone]clone().(); |
| 916 | fragmentless.set_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]set_fragment().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 917 | if resources.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&fragmentless) { |
| 918 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 919 | } else { |
| 920 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((original, uri, kind, fragmentless)) |
| 921 | } |
| 922 | }) |
| 923 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 924 | |
| 925 | let results = { |
| 926 | let futures = data |
| 927 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 928 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_, _, _, fragmentless)| retriever.retrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve#retrieve().(fragmentless)); |
| 929 | futuresrust-analyzer cargo futures 0.3.31 crate/::futurerust-analyzer cargo futures-util 0.3.31 future/::join_allrust-analyzer cargo futures-util 0.3.31 future/join_all/join_all().(futures).rust-analyzer cargo futures-util 0.3.31 future/join_all/impl#[`JoinAll<F>`][Future]poll().awaitrust-analyzer cargo futures-util 0.3.31 future/join_all/impl#[`JoinAll<F>`][Future]poll(). |
| 930 | }; |
| 931 | |
| 932 | for ((original, uri, kind, fragmentless), result) in data.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(results) { |
| 933 | let retrieved = match result { |
| 934 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(retrieved) => retrieved, |
| 935 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => { |
| 936 | handle_retrieve_errorrust-analyzer cargo referencing 0.37.4 registry/handle_retrieve_error().(uri, original, fragmentless, error, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().kind)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 937 | continue; |
| 938 | } |
| 939 | }; |
| 940 | |
| 941 | let (key, resource) = create_resourcerust-analyzer cargo referencing 0.37.4 registry/create_resource().( |
| 942 | retrieved, |
| 943 | fragmentless.clonerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][Clone]clone().(), |
| 944 | default_draft, |
| 945 | documents, |
| 946 | resources, |
| 947 | &mut state.custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas., |
| 948 | ); |
| 949 | handle_fragmentrust-analyzer cargo referencing 0.37.4 registry/handle_fragment().( |
| 950 | uri, |
| 951 | &resource, |
| 952 | &key, |
| 953 | default_draft, |
| 954 | &mut state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue., |
| 955 | Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&key), |
| 956 | ); |
| 957 | state.queuerust-analyzer cargo referencing 0.37.4 registry/ProcessingState#queue..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((key, resource, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | handle_metaschemasrust-analyzer cargo referencing 0.37.4 registry/handle_metaschemas().(state.refers_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#refers_metaschemas., resources, anchors, default_draft); |
| 963 | |
| 964 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(state.custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/ProcessingState#custom_metaschemas.) |
| 965 | } |
| 966 | |
| 967 | fn handle_retrieve_errorrust-analyzer cargo referencing 0.37.4 registry/handle_retrieve_error().( |
| 968 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 969 | original: &str, |
| 970 | fragmentless: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 971 | error: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>, |
| 972 | kind: ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#, |
| 973 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 974 | match kind { |
| 975 | ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#::Schemarust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#Schema# => { |
| 976 | // $schema fetch failures are non-fatal during resource processing |
| 977 | // Unregistered custom meta-schemas will be caught in validate_custom_metaschemas() |
| 978 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 979 | } |
| 980 | ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#::Refrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#Ref# => { |
| 981 | // $ref fetch failures are fatal - they're required for validation |
| 982 | if uri.schemerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]scheme().().as_strrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."json-schema" { |
| 983 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::unretrievablerust-analyzer cargo referencing 0.37.4 error/impl#[Error]unretrievable().( |
| 984 | original, |
| 985 | "No base URI is available".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 986 | )) |
| 987 | } else { |
| 988 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::unretrievablerust-analyzer cargo referencing 0.37.4 error/impl#[Error]unretrievable().(fragmentless.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().(), error)) |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | fn validate_custom_metaschemasrust-analyzer cargo referencing 0.37.4 registry/validate_custom_metaschemas().( |
| 995 | custom_metaschemas: &[Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>], |
| 996 | resources: &ResourceMaprust-analyzer cargo referencing 0.37.4 registry/ResourceMap#, |
| 997 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 998 | // Only validate resources with Draft::Unknown |
| 999 | for uri in custom_metaschemas { |
| 1000 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(resource) = resources.getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(uri) { |
| 1001 | // Extract the $schema value from this resource |
| 1002 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(schema_uri) = resource |
| 1003 | .contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().() |
| 1004 | .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() |
| 1005 | .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")) |
| 1006 | .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().()) |
| 1007 | { |
| 1008 | // Check if this meta-schema is registered |
| 1009 | match urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().(schema_uri) { |
| 1010 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mut meta_uri) => { |
| 1011 | // Remove fragment for lookup (e.g., "http://example.com/schema#" -> "http://example.com/schema") |
| 1012 | meta_uri.set_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]set_fragment().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 1013 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().resources.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&meta_uri) { |
| 1014 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::unknown_specificationrust-analyzer cargo referencing 0.37.4 error/impl#[Error]unknown_specification().(schema_uri)); |
| 1015 | } |
| 1016 | } |
| 1017 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 1018 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::unknown_specificationrust-analyzer cargo referencing 0.37.4 error/impl#[Error]unknown_specification().(schema_uri)); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1025 | } |
| 1026 | |
| 1027 | fn collect_external_resourcesrust-analyzer cargo referencing 0.37.4 registry/collect_external_resources().( |
| 1028 | base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 1029 | root: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 1030 | contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 1031 | collected: &mut AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#)>, |
| 1032 | seen: &mut ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker#, |
| 1033 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 1034 | scratch: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1035 | refers_metaschemas: &mut bool, |
| 1036 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 1037 | visited: &mut AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<usize>, |
| 1038 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 1039 | // URN schemes are not supported for external resolution |
| 1040 | if base.schemerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]scheme().().as_strrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."urn" { |
| 1041 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 1042 | } |
| 1043 | |
| 1044 | macro_rules! on_referencerust-analyzer cargo referencing 0.37.4 registry/on_reference! { |
| 1045 | ($reference:expr, $key:literal) => { |
| 1046 | // Skip well-known schema references |
| 1047 | if $reference.starts_with("https://json-schema.org/draft/") |
| 1048 | || $reference.starts_with("http://json-schema.org/draft-") |
| 1049 | || base.as_str().starts_with("https://json-schema.org/draft/") |
| 1050 | { |
| 1051 | if $key == "$ref" { |
| 1052 | *refers_metaschemas = true; |
| 1053 | } |
| 1054 | } else if $reference != "#" { |
| 1055 | if mark_reference(seen, base, $reference) { |
| 1056 | // Handle local references separately as they may have nested references to external resources |
| 1057 | if $reference.starts_with('#') { |
| 1058 | // Use the root document for pointer resolution since local refs are always |
| 1059 | // relative to the document root, not the current subschema. |
| 1060 | // Also track $id changes along the path to get the correct base URI. |
| 1061 | if let Some((referenced, resolved_base)) = pointer_with_base( |
| 1062 | root, |
| 1063 | $reference.trim_start_matches('#'), |
| 1064 | base, |
| 1065 | resolution_cache, |
| 1066 | draft, |
| 1067 | )? { |
| 1068 | // Recursively collect from the referenced schema and all its subresources |
| 1069 | collect_external_resources_recursive( |
| 1070 | &resolved_base, |
| 1071 | root, |
| 1072 | referenced, |
| 1073 | collected, |
| 1074 | seen, |
| 1075 | resolution_cache, |
| 1076 | scratch, |
| 1077 | refers_metaschemas, |
| 1078 | draft, |
| 1079 | visited, |
| 1080 | )?; |
| 1081 | } |
| 1082 | } else { |
| 1083 | let resolved = if base.has_fragment() { |
| 1084 | let mut base_without_fragment = base.as_ref().clone(); |
| 1085 | base_without_fragment.set_fragment(None); |
| 1086 | |
| 1087 | let (path, fragment) = match $reference.split_once('#') { |
| 1088 | Some((path, fragment)) => (path, Some(fragment)), |
| 1089 | None => ($reference, None), |
| 1090 | }; |
| 1091 | |
| 1092 | let mut resolved = (*resolution_cache |
| 1093 | .resolve_against(&base_without_fragment.borrow(), path)?) |
| 1094 | .clone(); |
| 1095 | // Add the fragment back if present |
| 1096 | if let Some(fragment) = fragment { |
| 1097 | // It is cheaper to check if it is properly encoded than allocate given that |
| 1098 | // the majority of inputs do not need to be additionally encoded |
| 1099 | if let Some(encoded) = uri::EncodedString::new(fragment) { |
| 1100 | resolved = resolved.with_fragment(Some(encoded)); |
| 1101 | } else { |
| 1102 | uri::encode_to(fragment, scratch); |
| 1103 | resolved = resolved.with_fragment(Some( |
| 1104 | uri::EncodedString::new_or_panic(scratch), |
| 1105 | )); |
| 1106 | scratch.clear(); |
| 1107 | } |
| 1108 | } |
| 1109 | resolved |
| 1110 | } else { |
| 1111 | (*resolution_cache |
| 1112 | .resolve_against(&base.borrow(), $reference)?) |
| 1113 | .clone() |
| 1114 | }; |
| 1115 | |
| 1116 | let kind = if $key == "$schema" { |
| 1117 | ReferenceKind::Schema |
| 1118 | } else { |
| 1119 | ReferenceKind::Ref |
| 1120 | }; |
| 1121 | collected.insert(($reference.to_string(), resolved, kind)); |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | }; |
| 1126 | } |
| 1127 | |
| 1128 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(object) = contents.as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() { |
| 1129 | if object.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().3 { |
| 1130 | for (key, value) in object { |
| 1131 | if key rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."$ref" { |
| 1132 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reference) = value.as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().() { |
| 1133 | on_referencerust-analyzer cargo referencing 0.37.4 registry/on_reference!!(reference, "$ref"); |
| 1134 | } |
| 1135 | } else if key rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."$schema" { |
| 1136 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reference) = value.as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().() { |
| 1137 | on_referencerust-analyzer cargo referencing 0.37.4 registry/on_reference!!(reference, "$schema"); |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | } else { |
| 1142 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reference) = object.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$ref").and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) { |
| 1143 | on_referencerust-analyzer cargo referencing 0.37.4 registry/on_reference!!(reference, "$ref"); |
| 1144 | } |
| 1145 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reference) = object.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$schema").and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) { |
| 1146 | on_referencerust-analyzer cargo referencing 0.37.4 registry/on_reference!!(reference, "$schema"); |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1151 | } |
| 1152 | |
| 1153 | /// Recursively collect external resources from a schema and all its subresources. |
| 1154 | /// |
| 1155 | /// The `visited` set tracks schema pointers we've already processed to avoid infinite |
| 1156 | /// recursion when schemas reference each other (directly or through subresources). |
| 1157 | fn collect_external_resources_recursiverust-analyzer cargo referencing 0.37.4 registry/collect_external_resources_recursive().( |
| 1158 | base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 1159 | root: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 1160 | contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 1161 | collected: &mut AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, ReferenceKindrust-analyzer cargo referencing 0.37.4 registry/ReferenceKind#)>, |
| 1162 | seen: &mut ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker#, |
| 1163 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 1164 | scratch: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1165 | refers_metaschemas: &mut bool, |
| 1166 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 1167 | visited: &mut AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#<usize>, |
| 1168 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 1169 | // Track by pointer address to avoid processing the same schema twice |
| 1170 | let ptr = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::from_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/from_ref().::<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>(contents) as usize; |
| 1171 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().visited.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(ptr) { |
| 1172 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 1173 | } |
| 1174 | |
| 1175 | let current_base = match draft.id_ofrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]id_of().(contents) { |
| 1176 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) => resolve_idrust-analyzer cargo referencing 0.37.4 registry/resolve_id().(base, id, resolution_cache)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 1177 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(base), |
| 1178 | }; |
| 1179 | |
| 1180 | // First, collect from the current schema |
| 1181 | collect_external_resourcesrust-analyzer cargo referencing 0.37.4 registry/collect_external_resources().( |
| 1182 | ¤t_base, |
| 1183 | root, |
| 1184 | contents, |
| 1185 | collected, |
| 1186 | seen, |
| 1187 | resolution_cache, |
| 1188 | scratch, |
| 1189 | refers_metaschemas, |
| 1190 | draft, |
| 1191 | visited, |
| 1192 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1193 | |
| 1194 | // Then recursively process all subresources |
| 1195 | for subresource in draft.subresources_ofrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]subresources_of().(contents) { |
| 1196 | collect_external_resources_recursiverust-analyzer cargo referencing 0.37.4 registry/collect_external_resources_recursive().( |
| 1197 | ¤t_base, |
| 1198 | root, |
| 1199 | subresource, |
| 1200 | collected, |
| 1201 | seen, |
| 1202 | resolution_cache, |
| 1203 | scratch, |
| 1204 | refers_metaschemas, |
| 1205 | draft, |
| 1206 | visited, |
| 1207 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1208 | } |
| 1209 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1210 | } |
| 1211 | |
| 1212 | fn mark_referencerust-analyzer cargo referencing 0.37.4 registry/mark_reference().(seen: &mut ReferenceTrackerrust-analyzer cargo referencing 0.37.4 registry/ReferenceTracker#, base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, reference: &str) -> bool { |
| 1213 | seen.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(ReferenceKeyrust-analyzer cargo referencing 0.37.4 registry/ReferenceKey#::newrust-analyzer cargo referencing 0.37.4 registry/impl#[ReferenceKey]new().(base, reference)) |
| 1214 | } |
| 1215 | |
| 1216 | /// Resolve an `$id` against a base URI, handling anchor-style IDs and empty fragments. |
| 1217 | /// |
| 1218 | /// Anchor-style `$id` values (starting with `#`) don't change the base URI. |
| 1219 | /// Empty fragments are stripped from the resolved URI. |
| 1220 | fn resolve_idrust-analyzer cargo referencing 0.37.4 registry/resolve_id().( |
| 1221 | base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 1222 | id: &str, |
| 1223 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 1224 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 1225 | if id.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') { |
| 1226 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(base)); |
| 1227 | } |
| 1228 | let mut resolved = (*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().resolution_cache.resolve_againstrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]resolve_against().(&base.borrowrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]borrow().(), id)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().).clonerust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`][Clone]clone().(); |
| 1229 | if resolved.fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]fragment().().is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::is_emptyrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]is_empty().) { |
| 1230 | resolved.set_fragmentrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<String>`]set_fragment().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 1231 | } |
| 1232 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(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().(resolved)) |
| 1233 | } |
| 1234 | |
| 1235 | /// Look up a value by a JSON Pointer. |
| 1236 | /// |
| 1237 | /// **NOTE**: A slightly faster version of pointer resolution based on `Value::pointer` from `serde_json`. |
| 1238 | pub fn pointerrust-analyzer cargo referencing 0.37.4 registry/pointer().<'a>(document: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, pointer: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#> { |
| 1239 | if pointer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 1240 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(document); |
| 1241 | } |
| 1242 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pointer.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('/') { |
| 1243 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 1244 | } |
| 1245 | pointer.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('/').skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(unescape_segmentrust-analyzer cargo referencing 0.37.4 resource/unescape_segment().).try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]try_fold().( |
| 1246 | document, |
| 1247 | |target, token| match target { |
| 1248 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(map) => map.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().token), |
| 1249 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(list) => parse_indexrust-analyzer cargo referencing 0.37.4 registry/parse_index().(&token).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|x| list.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(x)), |
| 1250 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 1251 | }, |
| 1252 | ) |
| 1253 | } |
| 1254 | |
| 1255 | /// Look up a value by a JSON Pointer, tracking `$id` changes along the path. |
| 1256 | /// |
| 1257 | /// Returns both the resolved value and the accumulated base URI after processing |
| 1258 | /// any `$id` declarations encountered along the path. Note that anchor-style `$id` |
| 1259 | /// values (starting with `#`) don't change the base URI. |
| 1260 | #[allow(clippy::type_complexity)] |
| 1261 | fn pointer_with_baserust-analyzer cargo referencing 0.37.4 registry/pointer_with_base().<'a>( |
| 1262 | document: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 1263 | pointer: &str, |
| 1264 | base: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 1265 | resolution_cache: &mut UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache#, |
| 1266 | draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, |
| 1267 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>)>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 1268 | if pointer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 1269 | return 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#((document, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(base)))); |
| 1270 | } |
| 1271 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pointer.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('/') { |
| 1272 | return 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#); |
| 1273 | } |
| 1274 | |
| 1275 | let mut current = document; |
| 1276 | let mut current_base = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(base); |
| 1277 | |
| 1278 | for token in pointer.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('/').skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(unescape_segmentrust-analyzer cargo referencing 0.37.4 resource/unescape_segment().) { |
| 1279 | // Check for $id in the current value before traversing deeper |
| 1280 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = draft.id_ofrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]id_of().(current) { |
| 1281 | current_base = resolve_idrust-analyzer cargo referencing 0.37.4 registry/resolve_id().(¤t_base, id, resolution_cache)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1282 | } |
| 1283 | |
| 1284 | current = match current { |
| 1285 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(map) => match map.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().token) { |
| 1286 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 1287 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return 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#), |
| 1288 | }, |
| 1289 | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(list) => match parse_indexrust-analyzer cargo referencing 0.37.4 registry/parse_index().(&token).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|x| list.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(x)) { |
| 1290 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 1291 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return 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#), |
| 1292 | }, |
| 1293 | _ => return 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#), |
| 1294 | }; |
| 1295 | } |
| 1296 | |
| 1297 | // Note: We don't check $id in the final value here because |
| 1298 | // `collect_external_resources_recursive` will handle it |
| 1299 | 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#((current, current_base))) |
| 1300 | } |
| 1301 | |
| 1302 | // Taken from `serde_json`. |
| 1303 | #[must_use] |
| 1304 | pub fn parse_indexrust-analyzer cargo referencing 0.37.4 registry/parse_index().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 1305 | if s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('+') || (s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('0') && s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1) { |
| 1306 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 1307 | } |
| 1308 | s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 1309 | } |
| 1310 | |
| 1311 | #[cfg(test)] |
| 1312 | mod testsrust-analyzer cargo referencing 0.37.4 registry/tests/ { |
| 1313 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# as _; |
| 1314 | |
| 1315 | use ahashrust-analyzer cargo ahash 0.8.12 crate/::AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#; |
| 1316 | use fluent_urirust-analyzer cargo fluent-uri 0.4.1 crate/::Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#; |
| 1317 | 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#}; |
| 1318 | use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:; |
| 1319 | |
| 1320 | use craterust-analyzer cargo referencing 0.37.4 crate/::{urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str()., Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve#}; |
| 1321 | |
| 1322 | use superrust-analyzer cargo referencing 0.37.4 registry/::{pointerrust-analyzer cargo referencing 0.37.4 registry/pointer()., RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#, SPECIFICATIONSrust-analyzer cargo referencing 0.37.4 registry/SPECIFICATIONS.}; |
| 1323 | |
| 1324 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1325 | fn test_empty_pointerrust-analyzer cargo referencing 0.37.4 registry/tests/test_empty_pointer().() { |
| 1326 | let document = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({}); |
| 1327 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pointerrust-analyzer cargo referencing 0.37.4 registry/pointer().(&document, ""), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&document)); |
| 1328 | } |
| 1329 | |
| 1330 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1331 | fn test_invalid_uri_on_registry_creationrust-analyzer cargo referencing 0.37.4 registry/tests/test_invalid_uri_on_registry_creation().() { |
| 1332 | let schema = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({})); |
| 1333 | let result = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().(":/example.com", schema); |
| 1334 | let error = result.expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 1335 | |
| 1336 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1337 | error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 1338 | "Invalid URI reference ':/example.com': unexpected character at index 0" |
| 1339 | ); |
| 1340 | let source_error = error.sourcerust-analyzer cargo referencing 0.37.4 error/impl#[Error][Error]source().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have a source"); |
| 1341 | let inner_source = source_error.sourcerust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#source().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have a source"); |
| 1342 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(inner_source.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "unexpected character at index 0"); |
| 1343 | } |
| 1344 | |
| 1345 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1346 | fn test_lookup_unresolvable_urlrust-analyzer cargo referencing 0.37.4 registry/tests/test_lookup_unresolvable_url().() { |
| 1347 | // Create a registry with a single resource |
| 1348 | let schema = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1349 | "type": "object", |
| 1350 | "properties": { |
| 1351 | "foo": { "type": "string" } |
| 1352 | } |
| 1353 | })); |
| 1354 | let registry = |
| 1355 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com/schema1", schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 1356 | |
| 1357 | // Attempt to create a resolver for a URL not in the registry |
| 1358 | let resolver = registry |
| 1359 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com/non_existent_schema") |
| 1360 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1361 | |
| 1362 | let result = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().(""); |
| 1363 | |
| 1364 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1365 | result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 1366 | "Resource 'http://example.com/non_existent_schema' is not present in a registry and retrieving it failed: Retrieving external resources is not supported once the registry is populated" |
| 1367 | ); |
| 1368 | } |
| 1369 | |
| 1370 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1371 | fn test_relative_uri_without_baserust-analyzer cargo referencing 0.37.4 registry/tests/test_relative_uri_without_base().() { |
| 1372 | let schema = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "./virtualNetwork.json"})); |
| 1373 | let error = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("json-schema:///", schema).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 1374 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "Resource './virtualNetwork.json' is not present in a registry and retrieving it failed: No base URI is available"); |
| 1375 | } |
| 1376 | |
| 1377 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1378 | fn test_try_with_resources_requires_registered_custom_meta_schemarust-analyzer cargo referencing 0.37.4 registry/tests/test_try_with_resources_requires_registered_custom_meta_schema().() { |
| 1379 | let base_registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().( |
| 1380 | "http://example.com/root", |
| 1381 | 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": "object"})), |
| 1382 | ) |
| 1383 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Base registry should be created"); |
| 1384 | |
| 1385 | let custom_schema = 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!!({ |
| 1386 | "$id": "http://example.com/custom", |
| 1387 | "$schema": "http://example.com/meta/custom", |
| 1388 | "type": "string" |
| 1389 | })); |
| 1390 | |
| 1391 | let error = base_registry |
| 1392 | .try_with_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources().( |
| 1393 | [("http://example.com/custom", custom_schema)], |
| 1394 | Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().(), |
| 1395 | ) |
| 1396 | .expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Extending registry must fail when the custom $schema is not registered"); |
| 1397 | |
| 1398 | let error_msg = error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 1399 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1400 | error_msg, |
| 1401 | "Unknown meta-schema: 'http://example.com/meta/custom'. Custom meta-schemas must be registered in the registry before use" |
| 1402 | ); |
| 1403 | } |
| 1404 | |
| 1405 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1406 | fn test_try_with_resources_accepts_registered_custom_meta_schema_fragmentrust-analyzer cargo referencing 0.37.4 registry/tests/test_try_with_resources_accepts_registered_custom_meta_schema_fragment().() { |
| 1407 | let meta_schema = 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!!({ |
| 1408 | "$id": "http://example.com/meta/custom#", |
| 1409 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 1410 | "type": "object" |
| 1411 | })); |
| 1412 | |
| 1413 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com/meta/custom#", meta_schema) |
| 1414 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Meta-schema should be registered successfully"); |
| 1415 | |
| 1416 | let schema = 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!!({ |
| 1417 | "$id": "http://example.com/schemas/my-schema", |
| 1418 | "$schema": "http://example.com/meta/custom#", |
| 1419 | "type": "string" |
| 1420 | })); |
| 1421 | |
| 1422 | registry |
| 1423 | .clonerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone]clone().() |
| 1424 | .try_with_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resources().( |
| 1425 | [("http://example.com/schemas/my-schema", schema)], |
| 1426 | Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().(), |
| 1427 | ) |
| 1428 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Schema should accept registered meta-schema URI with trailing '#'"); |
| 1429 | } |
| 1430 | |
| 1431 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1432 | fn test_chained_custom_meta_schemasrust-analyzer cargo referencing 0.37.4 registry/tests/test_chained_custom_meta_schemas().() { |
| 1433 | // Meta-schema B (uses standard Draft 2020-12) |
| 1434 | let meta_schema_b = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1435 | "$id": "json-schema:///meta/level-b", |
| 1436 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 1437 | "$vocabulary": { |
| 1438 | "https://json-schema.org/draft/2020-12/vocab/core": true, |
| 1439 | "https://json-schema.org/draft/2020-12/vocab/validation": true, |
| 1440 | }, |
| 1441 | "type": "object", |
| 1442 | "properties": { |
| 1443 | "customProperty": {"type": "string"} |
| 1444 | } |
| 1445 | }); |
| 1446 | |
| 1447 | // Meta-schema A (uses Meta-schema B) |
| 1448 | let meta_schema_a = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1449 | "$id": "json-schema:///meta/level-a", |
| 1450 | "$schema": "json-schema:///meta/level-b", |
| 1451 | "customProperty": "level-a-meta", |
| 1452 | "type": "object" |
| 1453 | }); |
| 1454 | |
| 1455 | // Schema (uses Meta-schema A) |
| 1456 | let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1457 | "$id": "json-schema:///schemas/my-schema", |
| 1458 | "$schema": "json-schema:///meta/level-a", |
| 1459 | "customProperty": "my-schema", |
| 1460 | "type": "string" |
| 1461 | }); |
| 1462 | |
| 1463 | // Register all meta-schemas and schema in a chained manner |
| 1464 | // All resources are provided upfront, so no external retrieval should occur |
| 1465 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().([ |
| 1466 | ( |
| 1467 | "json-schema:///meta/level-b", |
| 1468 | Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(meta_schema_b), |
| 1469 | ), |
| 1470 | ( |
| 1471 | "json-schema:///meta/level-a", |
| 1472 | Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(meta_schema_a), |
| 1473 | ), |
| 1474 | ( |
| 1475 | "json-schema:///schemas/my-schema", |
| 1476 | Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(schema), |
| 1477 | ), |
| 1478 | ]) |
| 1479 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Chained custom meta-schemas should be accepted when all are registered"); |
| 1480 | } |
| 1481 | |
| 1482 | struct TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever# { |
| 1483 | schemasrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever#schemas.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>, |
| 1484 | } |
| 1485 | |
| 1486 | impl TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever# { |
| 1487 | fn newrust-analyzer cargo referencing 0.37.4 registry/tests/impl#[TestRetriever]new().(schemas: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>) -> Selfrust-analyzer cargo referencing 0.37.4 registry/tests/impl#[TestRetriever] { |
| 1488 | TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever# { schemasrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever#schemas. } |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | impl Retrieverust-analyzer cargo referencing 0.37.4 retriever/Retrieve# for TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever# { |
| 1493 | fn retrieverust-analyzer cargo referencing 0.37.4 registry/tests/impl#[TestRetriever][Retrieve]retrieve().( |
| 1494 | &self, |
| 1495 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 1496 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 1497 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.schemasrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever#schemas..getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(uri.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().()) { |
| 1498 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value.clonerust-analyzer cargo serde_json 1.0.145 value/impl#[Value][Clone]clone().()) |
| 1499 | } else { |
| 1500 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to find {uri}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | fn create_test_retrieverrust-analyzer cargo referencing 0.37.4 registry/tests/create_test_retriever().(schemas: &[(&str, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#)]) -> TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever# { |
| 1506 | TestRetrieverrust-analyzer cargo referencing 0.37.4 registry/tests/TestRetriever#::newrust-analyzer cargo referencing 0.37.4 registry/tests/impl#[TestRetriever]new().( |
| 1507 | schemas |
| 1508 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1509 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&(k, ref v)| (k.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), v.clonerust-analyzer cargo serde_json 1.0.145 value/impl#[Value][Clone]clone().())) |
| 1510 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 1511 | ) |
| 1512 | } |
| 1513 | |
| 1514 | struct TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1515 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(&'static str, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#)>, |
| 1516 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(&'static str, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#)>, |
| 1517 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>, |
| 1518 | } |
| 1519 | |
| 1520 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1521 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1522 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1523 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema2"})), |
| 1524 | ], |
| 1525 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1526 | ("http://example.com/schema2", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})), |
| 1527 | ], |
| 1528 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://example.com/schema1", "http://example.com/schema2"], |
| 1529 | } |
| 1530 | ;"External ref at top")] |
| 1531 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1532 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1533 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1534 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1535 | "$defs": { |
| 1536 | "subschema": {"type": "string"} |
| 1537 | }, |
| 1538 | "$ref": "#/$defs/subschema" |
| 1539 | })), |
| 1540 | ], |
| 1541 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 1542 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://example.com/schema1"], |
| 1543 | } |
| 1544 | ;"Internal ref at top")] |
| 1545 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1546 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1547 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1548 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema2"})), |
| 1549 | ("http://example.com/schema2", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})), |
| 1550 | ], |
| 1551 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 1552 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://example.com/schema1", "http://example.com/schema2"], |
| 1553 | } |
| 1554 | ;"Ref to later resource")] |
| 1555 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1556 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1557 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1558 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1559 | "type": "object", |
| 1560 | "properties": { |
| 1561 | "prop1": {"$ref": "http://example.com/schema2"} |
| 1562 | } |
| 1563 | })), |
| 1564 | ], |
| 1565 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1566 | ("http://example.com/schema2", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"})), |
| 1567 | ], |
| 1568 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://example.com/schema1", "http://example.com/schema2"], |
| 1569 | } |
| 1570 | ;"External ref in subresource")] |
| 1571 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1572 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1573 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1574 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1575 | "type": "object", |
| 1576 | "properties": { |
| 1577 | "prop1": {"$ref": "#/$defs/subschema"} |
| 1578 | }, |
| 1579 | "$defs": { |
| 1580 | "subschema": {"type": "string"} |
| 1581 | } |
| 1582 | })), |
| 1583 | ], |
| 1584 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 1585 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://example.com/schema1"], |
| 1586 | } |
| 1587 | ;"Internal ref in subresource")] |
| 1588 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1589 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1590 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1591 | ("file:///schemas/main.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "file:///schemas/external.json"})), |
| 1592 | ], |
| 1593 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1594 | ("file:///schemas/external.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})), |
| 1595 | ], |
| 1596 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["file:///schemas/main.json", "file:///schemas/external.json"], |
| 1597 | } |
| 1598 | ;"File scheme: external ref at top")] |
| 1599 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1600 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1601 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1602 | ("file:///schemas/main.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "subfolder/schema.json"})), |
| 1603 | ], |
| 1604 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1605 | ("file:///schemas/subfolder/schema.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"})), |
| 1606 | ], |
| 1607 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["file:///schemas/main.json", "file:///schemas/subfolder/schema.json"], |
| 1608 | } |
| 1609 | ;"File scheme: relative path ref")] |
| 1610 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1611 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1612 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1613 | ("file:///schemas/main.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1614 | "type": "object", |
| 1615 | "properties": { |
| 1616 | "local": {"$ref": "local.json"}, |
| 1617 | "remote": {"$ref": "http://example.com/schema"} |
| 1618 | } |
| 1619 | })), |
| 1620 | ], |
| 1621 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1622 | ("file:///schemas/local.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"})), |
| 1623 | ("http://example.com/schema", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "number"})), |
| 1624 | ], |
| 1625 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1626 | "file:///schemas/main.json", |
| 1627 | "file:///schemas/local.json", |
| 1628 | "http://example.com/schema" |
| 1629 | ], |
| 1630 | } |
| 1631 | ;"File scheme: mixing with http scheme")] |
| 1632 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1633 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1634 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1635 | ("file:///C:/schemas/main.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "/D:/other_schemas/schema.json"})), |
| 1636 | ], |
| 1637 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1638 | ("file:///D:/other_schemas/schema.json", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "boolean"})), |
| 1639 | ], |
| 1640 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1641 | "file:///C:/schemas/main.json", |
| 1642 | "file:///D:/other_schemas/schema.json" |
| 1643 | ], |
| 1644 | } |
| 1645 | ;"File scheme: absolute path in Windows style")] |
| 1646 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1647 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1648 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1649 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema2"})), |
| 1650 | ], |
| 1651 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1652 | ("http://example.com/schema2", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema3"})), |
| 1653 | ("http://example.com/schema3", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema4"})), |
| 1654 | ("http://example.com/schema4", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema5"})), |
| 1655 | ("http://example.com/schema5", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})), |
| 1656 | ], |
| 1657 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1658 | "http://example.com/schema1", |
| 1659 | "http://example.com/schema2", |
| 1660 | "http://example.com/schema3", |
| 1661 | "http://example.com/schema4", |
| 1662 | "http://example.com/schema5", |
| 1663 | ], |
| 1664 | } |
| 1665 | ;"Four levels of external references")] |
| 1666 | #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:( |
| 1667 | TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase# { |
| 1668 | input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1669 | ("http://example.com/schema1", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema2"})), |
| 1670 | ], |
| 1671 | remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1672 | ("http://example.com/schema2", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema3"})), |
| 1673 | ("http://example.com/schema3", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema4"})), |
| 1674 | ("http://example.com/schema4", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema5"})), |
| 1675 | ("http://example.com/schema5", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema6"})), |
| 1676 | ("http://example.com/schema6", jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$ref": "http://example.com/schema1"})), |
| 1677 | ], |
| 1678 | expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1679 | "http://example.com/schema1", |
| 1680 | "http://example.com/schema2", |
| 1681 | "http://example.com/schema3", |
| 1682 | "http://example.com/schema4", |
| 1683 | "http://example.com/schema5", |
| 1684 | "http://example.com/schema6", |
| 1685 | ], |
| 1686 | } |
| 1687 | ;"Five levels of external references with circular reference")] |
| 1688 | fn test_references_processingrust-analyzer cargo referencing 0.37.4 registry/tests/test_references_processing().(test_case: TestCaserust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#) { |
| 1689 | let retriever = create_test_retrieverrust-analyzer cargo referencing 0.37.4 registry/tests/create_test_retriever().(&test_case.remote_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#remote_resources.); |
| 1690 | |
| 1691 | let input_pairs = test_case |
| 1692 | .input_resourcesrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#input_resources. |
| 1693 | .clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().() |
| 1694 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 1695 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(uri, value)| (uri, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#::from_contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]from_contents().(value))); |
| 1696 | |
| 1697 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1698 | .retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]retriever().(retriever) |
| 1699 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]build().(input_pairs) |
| 1700 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 1701 | // Verify that all expected URIs are resolved and present in resources |
| 1702 | for uri in test_case.expected_resolved_urisrust-analyzer cargo referencing 0.37.4 registry/tests/TestCase#expected_resolved_uris. { |
| 1703 | let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1704 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().(uri).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1709 | fn test_default_retriever_with_remote_refsrust-analyzer cargo referencing 0.37.4 registry/tests/test_default_retriever_with_remote_refs().() { |
| 1710 | let result = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().([( |
| 1711 | "http://example.com/schema1", |
| 1712 | 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!!({"$ref": "http://example.com/schema2"})), |
| 1713 | )]); |
| 1714 | let error = result.expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 1715 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "Resource 'http://example.com/schema2' is not present in a registry and retrieving it failed: Default retriever does not fetch resources"); |
| 1716 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error.sourcerust-analyzer cargo referencing 0.37.4 error/impl#[Error][Error]source().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 1717 | } |
| 1718 | |
| 1719 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1720 | fn test_optionsrust-analyzer cargo referencing 0.37.4 registry/tests/test_options().() { |
| 1721 | let _registry = RegistryOptionsrust-analyzer cargo referencing 0.37.4 registry/RegistryOptions#::defaultrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`][Default]default().() |
| 1722 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]build().([("", 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!!({})))]) |
| 1723 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 1724 | } |
| 1725 | |
| 1726 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1727 | fn test_registry_with_duplicate_input_urisrust-analyzer cargo referencing 0.37.4 registry/tests/test_registry_with_duplicate_input_uris().() { |
| 1728 | let input_resources = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1729 | ( |
| 1730 | "http://example.com/schema", |
| 1731 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1732 | "type": "object", |
| 1733 | "properties": { |
| 1734 | "foo": { "type": "string" } |
| 1735 | } |
| 1736 | }), |
| 1737 | ), |
| 1738 | ( |
| 1739 | "http://example.com/schema", |
| 1740 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1741 | "type": "object", |
| 1742 | "properties": { |
| 1743 | "bar": { "type": "number" } |
| 1744 | } |
| 1745 | }), |
| 1746 | ), |
| 1747 | ]; |
| 1748 | |
| 1749 | let result = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().( |
| 1750 | input_resources |
| 1751 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 1752 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(uri, value)| (uri, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(value))), |
| 1753 | ); |
| 1754 | |
| 1755 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1756 | result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 1757 | "Failed to create registry with duplicate input URIs" |
| 1758 | ); |
| 1759 | let registry = result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1760 | |
| 1761 | let resource = registry |
| 1762 | .resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources. |
| 1763 | .getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(&from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().("http://example.com/schema").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid URI")) |
| 1764 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1765 | let properties = resource |
| 1766 | .contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().() |
| 1767 | .getrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]get().("properties") |
| 1768 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|v| v.as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().()) |
| 1769 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1770 | |
| 1771 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1772 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().properties.contains_keyrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]contains_key().("bar"), |
| 1773 | "Registry should contain the earliest added schema" |
| 1774 | ); |
| 1775 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1776 | properties.contains_keyrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]contains_key().("foo"), |
| 1777 | "Registry should contain the overwritten schema" |
| 1778 | ); |
| 1779 | } |
| 1780 | |
| 1781 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1782 | fn test_resolver_debugrust-analyzer cargo referencing 0.37.4 registry/tests/test_resolver_debug().() { |
| 1783 | let registry = SPECIFICATIONSrust-analyzer cargo referencing 0.37.4 registry/SPECIFICATIONS. |
| 1784 | .clonerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone]clone().() |
| 1785 | .try_with_resourcerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resource().("http://example.com", 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!!({}))) |
| 1786 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resource"); |
| 1787 | let resolver = registry |
| 1788 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://127.0.0.1/schema") |
| 1789 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1790 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1791 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{resolver:?}"), |
| 1792 | "Resolver { base_uri: \"http://127.0.0.1/schema\", scopes: \"[]\" }" |
| 1793 | ); |
| 1794 | } |
| 1795 | |
| 1796 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1797 | fn test_try_with_resourcerust-analyzer cargo referencing 0.37.4 registry/tests/test_try_with_resource().() { |
| 1798 | let registry = SPECIFICATIONSrust-analyzer cargo referencing 0.37.4 registry/SPECIFICATIONS. |
| 1799 | .clonerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry][Clone]clone().() |
| 1800 | .try_with_resourcerust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_with_resource().("http://example.com", 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!!({}))) |
| 1801 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resource"); |
| 1802 | let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1803 | let resolved = resolver |
| 1804 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("http://json-schema.org/draft-06/schema#/definitions/schemaArray") |
| 1805 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 1806 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1807 | resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), |
| 1808 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1809 | "type": "array", |
| 1810 | "minItems": 1, |
| 1811 | "items": { "$ref": "#" } |
| 1812 | }) |
| 1813 | ); |
| 1814 | } |
| 1815 | |
| 1816 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1817 | fn test_invalid_referencerust-analyzer cargo referencing 0.37.4 registry/tests/test_invalid_reference().() { |
| 1818 | // Found via fuzzing |
| 1819 | let resource = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$schema": "$##"})); |
| 1820 | let _ = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://#/", resource); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | #[cfg(all(test, feature = "retrieve-async"))] |
| 1825 | mod async_testsrust-analyzer cargo referencing 0.37.4 registry/async_tests/ { |
| 1826 | use craterust-analyzer cargo referencing 0.37.4 crate/::{urirust-analyzer cargo referencing 0.37.4 uri/, DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#, Resourcerust-analyzer cargo referencing 0.37.4 resource/Resource#, Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#}; |
| 1827 | use ahashrust-analyzer cargo ahash 0.8.12 crate/::AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#; |
| 1828 | 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#}; |
| 1829 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 1830 | |
| 1831 | struct TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 1832 | schemasrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#schemas.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>, |
| 1833 | } |
| 1834 | |
| 1835 | impl TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 1836 | fn with_schemarust-analyzer cargo referencing 0.37.4 registry/async_tests/impl#[TestAsyncRetriever]with_schema().(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#>, schema: Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> Selfrust-analyzer cargo referencing 0.37.4 registry/async_tests/impl#[TestAsyncRetriever] { |
| 1837 | TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 1838 | schemasrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#schemas.: { AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::from_iterrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][`FromIterator<(K, V)>`]from_iter().([(uri.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), schema)]) }, |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | #[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] |
| 1844 | #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] |
| 1845 | impl craterust-analyzer cargo referencing 0.37.4 crate/::AsyncRetrieverust-analyzer cargo referencing 0.37.4 retriever/AsyncRetrieve# for TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 1846 | async fn retrieverust-analyzer cargo referencing 0.37.4 registry/async_tests/impl#[TestAsyncRetriever][AsyncRetrieve]retrieve().( |
| 1847 | &self, |
| 1848 | uri: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 1849 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>> { |
| 1850 | selfrust-analyzer cargo referencing 0.37.4 registry/async_tests/.schemasrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#schemas. |
| 1851 | .getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(uri.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().()) |
| 1852 | .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() |
| 1853 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Schema not found".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 1858 | async fn test_default_async_retriever_with_remote_refsrust-analyzer cargo referencing 0.37.4 registry/async_tests/test_default_async_retriever_with_remote_refs().() { |
| 1859 | let result = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1860 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#) |
| 1861 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().([( |
| 1862 | "http://example.com/schema1", |
| 1863 | 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!!({"$ref": "http://example.com/schema2"})), |
| 1864 | )]) |
| 1865 | .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().; |
| 1866 | |
| 1867 | let error = result.expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail"); |
| 1868 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "Resource 'http://example.com/schema2' is not present in a registry and retrieving it failed: Default retriever does not fetch resources"); |
| 1869 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error.sourcerust-analyzer cargo referencing 0.37.4 error/impl#[Error][Error]source().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 1870 | } |
| 1871 | |
| 1872 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 1873 | async fn test_async_optionsrust-analyzer cargo referencing 0.37.4 registry/async_tests/test_async_options().() { |
| 1874 | let _registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1875 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#) |
| 1876 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().([("", Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::defaultrust-analyzer cargo referencing 0.37.4 specification/impl#[Draft][Default]default().().create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({})))]) |
| 1877 | .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(). |
| 1878 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 1879 | } |
| 1880 | |
| 1881 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 1882 | async fn test_async_registry_with_duplicate_input_urisrust-analyzer cargo referencing 0.37.4 registry/async_tests/test_async_registry_with_duplicate_input_uris().() { |
| 1883 | let input_resources = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1884 | ( |
| 1885 | "http://example.com/schema", |
| 1886 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1887 | "type": "object", |
| 1888 | "properties": { |
| 1889 | "foo": { "type": "string" } |
| 1890 | } |
| 1891 | }), |
| 1892 | ), |
| 1893 | ( |
| 1894 | "http://example.com/schema", |
| 1895 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 1896 | "type": "object", |
| 1897 | "properties": { |
| 1898 | "bar": { "type": "number" } |
| 1899 | } |
| 1900 | }), |
| 1901 | ), |
| 1902 | ]; |
| 1903 | |
| 1904 | let result = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1905 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(DefaultRetrieverrust-analyzer cargo referencing 0.37.4 retriever/DefaultRetriever#) |
| 1906 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().( |
| 1907 | input_resources |
| 1908 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 1909 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(uri, value)| (uri, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(value))), |
| 1910 | ) |
| 1911 | .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().; |
| 1912 | |
| 1913 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1914 | result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 1915 | "Failed to create registry with duplicate input URIs" |
| 1916 | ); |
| 1917 | let registry = result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1918 | |
| 1919 | let resource = registry |
| 1920 | .resourcesrust-analyzer cargo referencing 0.37.4 registry/Registry#resources. |
| 1921 | .getrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V, S>`]get().(&urirust-analyzer cargo referencing 0.37.4 uri/::from_strrust-analyzer cargo referencing 0.37.4 uri/from_str().("http://example.com/schema").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid URI")) |
| 1922 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1923 | let properties = resource |
| 1924 | .contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().() |
| 1925 | .getrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]get().("properties") |
| 1926 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|v| v.as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().()) |
| 1927 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1928 | |
| 1929 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1930 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().properties.contains_keyrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]contains_key().("bar"), |
| 1931 | "Registry should contain the earliest added schema" |
| 1932 | ); |
| 1933 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1934 | properties.contains_keyrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]contains_key().("foo"), |
| 1935 | "Registry should contain the overwritten schema" |
| 1936 | ); |
| 1937 | } |
| 1938 | |
| 1939 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 1940 | async fn test_async_try_with_resourcerust-analyzer cargo referencing 0.37.4 registry/async_tests/test_async_try_with_resource().() { |
| 1941 | let retriever = TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#::with_schemarust-analyzer cargo referencing 0.37.4 registry/async_tests/impl#[TestAsyncRetriever]with_schema().( |
| 1942 | "http://example.com/schema2", |
| 1943 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"}), |
| 1944 | ); |
| 1945 | |
| 1946 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1947 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(retriever) |
| 1948 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().([( |
| 1949 | "http://example.com", |
| 1950 | 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!!({"$ref": "http://example.com/schema2"})), |
| 1951 | )]) |
| 1952 | .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(). |
| 1953 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resource"); |
| 1954 | |
| 1955 | let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1956 | let resolved = resolver |
| 1957 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("http://example.com/schema2") |
| 1958 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 1959 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})); |
| 1960 | } |
| 1961 | |
| 1962 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 1963 | async fn test_async_registry_with_multiple_refsrust-analyzer cargo referencing 0.37.4 registry/async_tests/test_async_registry_with_multiple_refs().() { |
| 1964 | let retriever = TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 1965 | schemasrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#schemas.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::from_iterrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][`FromIterator<(K, V)>`]from_iter().([ |
| 1966 | ( |
| 1967 | "http://example.com/schema2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 1968 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"}), |
| 1969 | ), |
| 1970 | ( |
| 1971 | "http://example.com/schema3".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 1972 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"}), |
| 1973 | ), |
| 1974 | ]), |
| 1975 | }; |
| 1976 | |
| 1977 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 1978 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(retriever) |
| 1979 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().([( |
| 1980 | "http://example.com/schema1", |
| 1981 | 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!!({ |
| 1982 | "type": "object", |
| 1983 | "properties": { |
| 1984 | "obj": {"$ref": "http://example.com/schema2"}, |
| 1985 | "str": {"$ref": "http://example.com/schema3"} |
| 1986 | } |
| 1987 | })), |
| 1988 | )]) |
| 1989 | .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(). |
| 1990 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resource"); |
| 1991 | |
| 1992 | let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 1993 | |
| 1994 | // Check both references are resolved correctly |
| 1995 | let resolved2 = resolver |
| 1996 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("http://example.com/schema2") |
| 1997 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 1998 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved2.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "object"})); |
| 1999 | |
| 2000 | let resolved3 = resolver |
| 2001 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("http://example.com/schema3") |
| 2002 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 2003 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved3.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string"})); |
| 2004 | } |
| 2005 | |
| 2006 | #[tokiorust-analyzer cargo tokio 1.48.0 crate/::testrust-analyzer cargo tokio-macros 2.6.0 test_rt:] |
| 2007 | async fn test_async_registry_with_nested_refsrust-analyzer cargo referencing 0.37.4 registry/async_tests/test_async_registry_with_nested_refs().() { |
| 2008 | let retriever = TestAsyncRetrieverrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever# { |
| 2009 | schemasrust-analyzer cargo referencing 0.37.4 registry/async_tests/TestAsyncRetriever#schemas.: AHashMaprust-analyzer cargo ahash 0.8.12 hash_map/AHashMap#::from_iterrust-analyzer cargo ahash 0.8.12 hash_map/impl#[`AHashMap<K, V>`][`FromIterator<(K, V)>`]from_iter().([ |
| 2010 | ( |
| 2011 | "http://example.com/address".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 2012 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 2013 | "type": "object", |
| 2014 | "properties": { |
| 2015 | "street": {"type": "string"}, |
| 2016 | "city": {"$ref": "http://example.com/city"} |
| 2017 | } |
| 2018 | }), |
| 2019 | ), |
| 2020 | ( |
| 2021 | "http://example.com/city".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 2022 | jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 2023 | "type": "string", |
| 2024 | "minLength": 1 |
| 2025 | }), |
| 2026 | ), |
| 2027 | ]), |
| 2028 | }; |
| 2029 | |
| 2030 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::optionsrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]options().() |
| 2031 | .async_retrieverrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn Retrieve + 'static>>`]async_retriever().(retriever) |
| 2032 | .buildrust-analyzer cargo referencing 0.37.4 registry/impl#[`RegistryOptions<Arc<dyn AsyncRetrieve + 'static>>`]build().([( |
| 2033 | "http://example.com/person", |
| 2034 | 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!!({ |
| 2035 | "type": "object", |
| 2036 | "properties": { |
| 2037 | "name": {"type": "string"}, |
| 2038 | "address": {"$ref": "http://example.com/address"} |
| 2039 | } |
| 2040 | })), |
| 2041 | )]) |
| 2042 | .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(). |
| 2043 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resource"); |
| 2044 | |
| 2045 | let resolver = registry.try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 2046 | |
| 2047 | // Verify nested reference resolution |
| 2048 | let resolved = resolver |
| 2049 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("http://example.com/city") |
| 2050 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 2051 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2052 | resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), |
| 2053 | &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"type": "string", "minLength": 1}) |
| 2054 | ); |
| 2055 | } |
| 2056 | } |