Skip to content

Commit fe47d5c

Browse files
authored
Merge pull request #227 from stac-utils/pv/fix-false-positives
fix several false positives
2 parents 05f2f08 + 8d736c2 commit fe47d5c

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

src/stac_api_validator/validations.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,35 @@ def supports(conforms_to: List[str], pattern: Pattern[str]) -> bool:
258258
return any(pattern.fullmatch(x) for x in conforms_to)
259259

260260

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+
261290
def stac_validate(
262291
url: str,
263292
body: Optional[Dict[str, Any]],
@@ -450,10 +479,6 @@ def validate_core_landing_page_body(
450479
return True
451480

452481

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-
457482
def validate_api(
458483
root_url: str,
459484
conformance_classes: List[str],
@@ -591,14 +616,14 @@ def validate_core(
591616
if not (root := link_by_rel(links, "root")):
592617
errors += "/ : Link[rel=root] must exist"
593618
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')}"
596621

597622
if not (_self := link_by_rel(links, "self")):
598623
warnings += "/ : Link[rel=self] must exist"
599624
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')}"
602627

603628
if not (service_desc := link_by_rel(links, "service-desc")):
604629
errors += "/ : Link[rel=service-desc] must exist"
@@ -703,11 +728,7 @@ def validate_collections(
703728
if not body:
704729
errors += f"[{Context.COLLECTIONS}] /collections body was empty"
705730
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")):
711732
errors += f"[{Context.COLLECTIONS}] /collections content-type header was not application/json"
712733

713734
if not (self_link := link_by_rel(body.get("links", []), "self")):
@@ -910,9 +931,6 @@ def validate_features(
910931
if not link_by_rel(body.get("links", []), "root"):
911932
errors += f"[{Context.FEATURES}] GET {collection_items_url} does not have root link"
912933

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-
916934
stac_validate(collection_items_url, body, errors, Context.FEATURES)
917935

918936
item = next(iter(body.get("features", [])), None)
@@ -2115,7 +2133,8 @@ def validate_item_search_ids_does_not_override_all_other_params(
21152133
)
21162134
else:
21172135
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"
21192138
)
21202139

21212140

0 commit comments

Comments
 (0)