@@ -411,31 +411,29 @@ def resolve_ref(
411
411
if not base_url :
412
412
base_url = file_uri (os .getcwd ()) + "/"
413
413
414
- sl = SourceLine (None , None )
415
414
# If `ref` is a dict, look for special directives.
416
415
if isinstance (lref , CommentedMap ):
417
416
obj = lref
418
417
if "$import" in obj :
419
- sl = SourceLine (obj , "$import" )
420
418
if len (obj ) == 1 :
421
419
lref = obj ["$import" ]
422
420
obj = None
423
421
else :
424
422
raise ValidationException (
425
- f"'$import' must be the only field in { obj } " , sl
423
+ f"'$import' must be the only field in { obj } " ,
424
+ SourceLine (obj , "$import" ),
426
425
)
427
426
elif "$include" in obj :
428
- sl = SourceLine (obj , "$include" )
429
427
if len (obj ) == 1 :
430
428
lref = obj ["$include" ]
431
429
inc = True
432
430
obj = None
433
431
else :
434
432
raise ValidationException (
435
- f"'$include' must be the only field in { obj } " , sl
433
+ f"'$include' must be the only field in { obj } " ,
434
+ SourceLine (obj , "$include" ),
436
435
)
437
436
elif "$mixin" in obj :
438
- sl = SourceLine (obj , "$mixin" )
439
437
lref = obj ["$mixin" ]
440
438
mixin = obj
441
439
obj = None
@@ -450,7 +448,7 @@ def resolve_ref(
450
448
"Object `{}` does not have identifier field in {}" .format (
451
449
obj , self .identifiers
452
450
),
453
- sl ,
451
+ SourceLine ( obj ) ,
454
452
)
455
453
456
454
if not isinstance (lref , str ):
@@ -514,7 +512,8 @@ def resolve_ref(
514
512
# so if we didn't find the reference earlier then it must not
515
513
# exist.
516
514
raise ValidationException (
517
- f"Reference `#{ frg } ` not found in file `{ doc_url } `." , sl
515
+ f"Reference `#{ frg } ` not found in file `{ doc_url } `." ,
516
+ SourceLine (self .idx [doc_url ]),
518
517
)
519
518
doc = self .fetch (
520
519
doc_url , inject_ids = (not mixin ), content_types = content_types
@@ -592,11 +591,10 @@ def _resolve_idmap(
592
591
)
593
592
v .lc .filename = document .lc .filename
594
593
else :
595
- sl = SourceLine (document , idmapField , str )
596
594
raise ValidationException (
597
595
"mapSubject '{}' value '{}' is not a dict "
598
596
"and does not have a mapPredicate." .format (k , v ),
599
- sl ,
597
+ SourceLine ( document , idmapField ) ,
600
598
)
601
599
else :
602
600
v = val
@@ -852,7 +850,7 @@ def resolve_all(
852
850
else :
853
851
return (document , metadata )
854
852
855
- newctx = None # type : Optional["Loader"]
853
+ newctx : Optional ["Loader" ] = None
856
854
if isinstance (document , CommentedMap ):
857
855
# Handle $base, $profile, $namespaces, $schemas and $graph
858
856
if "$base" in document :
@@ -867,12 +865,26 @@ def resolve_all(
867
865
if "$namespaces" in document :
868
866
if newctx is None :
869
867
newctx = SubLoader (self )
870
- newctx .add_namespaces (document ["$namespaces" ])
868
+ namespaces = document ["$namespaces" ]
869
+ if isinstance (namespaces , dict ):
870
+ newctx .add_namespaces (document ["$namespaces" ])
871
+ else :
872
+ raise ValidationException (
873
+ "$namespaces must be a dictionary" ,
874
+ SourceLine (document , "$namespaces" ),
875
+ )
871
876
872
877
if "$schemas" in document :
873
878
if newctx is None :
874
879
newctx = SubLoader (self )
875
- newctx .add_schemas (document ["$schemas" ], file_base )
880
+ schemas = document ["$schemas" ]
881
+ if isinstance (schemas , (list , str )):
882
+ newctx .add_schemas (schemas , file_base )
883
+ else :
884
+ raise ValidationException (
885
+ "$schemas must be a string or a list of string" ,
886
+ SourceLine (document , "$schemas" ),
887
+ )
876
888
877
889
if newctx is not None :
878
890
loader = newctx
@@ -1118,14 +1130,13 @@ def validate_links(
1118
1130
iterator = enumerate (document )
1119
1131
elif isinstance (document , MutableMapping ):
1120
1132
for d in self .url_fields :
1121
- sl = SourceLine (document , d , str )
1122
1133
try :
1123
1134
if d in document and d not in self .identity_links :
1124
1135
document [d ] = self .validate_link (
1125
1136
d , document [d ], docid , all_doc_ids
1126
1137
)
1127
1138
except SchemaSaladException as v :
1128
- v = v .with_sourceline (sl )
1139
+ v = v .with_sourceline (SourceLine ( document , d , str ) )
1129
1140
if d == "$schemas" or (
1130
1141
d in self .foreign_properties and not strict_foreign_properties
1131
1142
):
0 commit comments