@@ -767,22 +767,32 @@ def _finditem(self, schema, key):
767
767
yield each
768
768
values .extendleft (each .values ())
769
769
770
- def resolve (self , ref ):
771
- """
772
- Resolve the given reference.
773
- """
774
- url = self ._urljoin_cache (self .resolution_scope , ref ).rstrip ("/" )
770
+ @lru_cache ()
771
+ def _find_subschemas (self ):
772
+ return list (self ._finditem (self .referrer , "$id" ))
775
773
774
+ @lru_cache ()
775
+ def _find_in_subschemas (self , url ):
776
776
uri , fragment = urldefrag (url )
777
-
778
- for subschema in self ._finditem (self .referrer , "$id" ):
777
+ for subschema in self ._find_subschemas ():
779
778
target_uri = self ._urljoin_cache (
780
779
self .resolution_scope , subschema ["$id" ],
781
780
)
782
781
if target_uri .rstrip ("/" ) == uri .rstrip ("/" ):
783
782
if fragment :
784
783
subschema = self .resolve_fragment (subschema , fragment )
785
784
return url , subschema
785
+ return None
786
+
787
+ def resolve (self , ref ):
788
+ """
789
+ Resolve the given reference.
790
+ """
791
+ url = self ._urljoin_cache (self .resolution_scope , ref ).rstrip ("/" )
792
+
793
+ match = self ._find_in_subschemas (url )
794
+ if match is not None :
795
+ return match
786
796
787
797
return url , self ._remote_cache (url )
788
798
0 commit comments