@@ -258,6 +258,35 @@ def supports(conforms_to: List[str], pattern: Pattern[str]) -> bool:
258
258
return any (pattern .fullmatch (x ) for x in conforms_to )
259
259
260
260
261
+ def is_json_type (maybe_type : Optional [str ]) -> bool :
262
+ return maybe_type is not None and (
263
+ maybe_type == "application/json" or maybe_type .startswith ("application/json;" )
264
+ )
265
+
266
+
267
+ def is_geojson_type (maybe_type : Optional [str ]) -> bool :
268
+ return maybe_type is not None and (
269
+ maybe_type == "application/geo+json"
270
+ or maybe_type .startswith ("application/geo+json;" )
271
+ )
272
+
273
+
274
+ # def is_json_or_geojson_type(maybe_type: Optional[str]) -> bool:
275
+ # return maybe_type and (is_json_type(maybe_type) or is_geojson_type(maybe_type))
276
+
277
+
278
+ def has_content_type (headers : Mapping [str , str ], content_type : str ) -> bool :
279
+ return headers .get ("content-type" , "" ).split (";" )[0 ] == content_type
280
+
281
+
282
+ def has_json_content_type (headers : Mapping [str , str ]) -> bool :
283
+ return is_json_type (headers .get ("content-type" ))
284
+
285
+
286
+ def has_geojson_content_type (headers : Mapping [str , str ]) -> bool :
287
+ return is_geojson_type (headers .get ("content-type" ))
288
+
289
+
261
290
def stac_validate (
262
291
url : str ,
263
292
body : Optional [Dict [str , Any ]],
@@ -450,10 +479,6 @@ def validate_core_landing_page_body(
450
479
return True
451
480
452
481
453
- def has_content_type (headers : Mapping [str , str ], content_type : str ) -> bool :
454
- return headers .get ("content-type" , "" ).split (";" )[0 ] == content_type
455
-
456
-
457
482
def validate_api (
458
483
root_url : str ,
459
484
conformance_classes : List [str ],
@@ -591,14 +616,14 @@ def validate_core(
591
616
if not (root := link_by_rel (links , "root" )):
592
617
errors += "/ : Link[rel=root] must exist"
593
618
else :
594
- if root .get ("type" ) != "application/json" :
595
- errors += "/ : Link[rel=root] type is not application/json"
619
+ if not is_geojson_type ( root .get ("type" )) :
620
+ errors += f "/ : Link[rel=root] type is not application/geo+ json, instead { root . get ( 'type' ) } "
596
621
597
622
if not (_self := link_by_rel (links , "self" )):
598
623
warnings += "/ : Link[rel=self] must exist"
599
624
else :
600
- if _self .get ("type" ) != "application/json" :
601
- errors += "/ : Link[rel=self] type is not application/json"
625
+ if not is_geojson_type ( _self .get ("type" )) :
626
+ errors += f "/ : Link[rel=self] type is not application/geo+ json, instead { _self . get ( 'type' ) } "
602
627
603
628
if not (service_desc := link_by_rel (links , "service-desc" )):
604
629
errors += "/ : Link[rel=service-desc] must exist"
@@ -703,11 +728,7 @@ def validate_collections(
703
728
if not body :
704
729
errors += f"[{ Context .COLLECTIONS } ] /collections body was empty"
705
730
else :
706
- if (
707
- not resp_headers
708
- or resp_headers .get ("content-type" , "" ).split (";" )[0 ]
709
- != "application/json"
710
- ):
731
+ if not resp_headers or not is_json_type (resp_headers .get ("content-type" )):
711
732
errors += f"[{ Context .COLLECTIONS } ] /collections content-type header was not application/json"
712
733
713
734
if not (self_link := link_by_rel (body .get ("links" , []), "self" )):
@@ -910,9 +931,6 @@ def validate_features(
910
931
if not link_by_rel (body .get ("links" , []), "root" ):
911
932
errors += f"[{ Context .FEATURES } ] GET { collection_items_url } does not have root link"
912
933
913
- if not link_by_rel (body .get ("links" , []), "parent" ):
914
- errors += f"[{ Context .FEATURES } ] GET { collection_items_url } does not have parent link"
915
-
916
934
stac_validate (collection_items_url , body , errors , Context .FEATURES )
917
935
918
936
item = next (iter (body .get ("features" , [])), None )
@@ -2115,7 +2133,8 @@ def validate_item_search_ids_does_not_override_all_other_params(
2115
2133
)
2116
2134
else :
2117
2135
warnings += (
2118
- f"[{ Context .ITEM_SEARCH } ] GET Search with no parameters returned 0 results"
2136
+ f"[{ Context .ITEM_SEARCH } ] GET Search within bbox=20,20,21,21 to validate ids does not override "
2137
+ "all other parameters returned 0 results"
2119
2138
)
2120
2139
2121
2140
0 commit comments