Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions sedr/metoceanprofilecore10.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""metocean-edr-profile core requirements. See <https://github.com/EUMETNET/metocean-edr-profile/>."""

import json
import re

import pint
import requests
Expand Down Expand Up @@ -42,33 +43,55 @@ def requirement7_2(jsondata: dict, timeout: int = 10) -> tuple[bool, str]:
returns status: bool, message
"""
spec_url = f"{spec_base_url}#_openapi"
openapi_type = "application/vnd.oai.openapi+json;version=3.1"
openapi_types = [
"application/openapi+json",
"application/openapi+yaml",
"application/vnd.oai.openapi+json",
"application/vnd.oai.openapi+yaml",
]
servicedoc_type = "text/html"

service_desc_link = ""
service_desc_type = ""
for link in jsondata["links"]:
if link["rel"] == "service-desc":
service_desc_link = link["href"]
service_desc_type = link["type"]
service_desc_type, service_desc_version = (link["type"].split(";", 1) + [None, None])[:2]
break

# print(service_desc_type, service_desc_version, file=sys.stderr)
# logging.DEBUG(service_desc_type, service_desc_version)
if not service_desc_link:
return (
False,
f"No service-desc link found. See <{spec_url}> for more info.",
)

# C - relation type
if openapi_type not in service_desc_type:
if service_desc_type not in openapi_types:
return (
False,
"OpenAPI link service-desc should identify the content as openAPI "
f"and include version. Example <{openapi_type}>. Found: "
"OpenAPI link service-desc must identify the content as openAPI "
f"and should include version. Example <{openapi_types[0]}>. Found: "
f"<{service_desc_type}>. See <{spec_url}> and <{spec_base_url}"
"#_openapi_2> for more info.",
)

if service_desc_version:
m = re.match(r"^version=(\d+\.\d+)$", service_desc_version)
if m:
version = m.groups()[0]
if version != "3.1": # profile should allow later versions FIXME
return (
False,
f"OpenAPI version not 3.1: {version}.",
)
else:
return (
False,
f"OpenAPI version suffix malformed: {service_desc_version}.",
)

# A - described using an OpenAPI document
response = requests.get(service_desc_link, timeout=timeout)
if not response.status_code < 400:
Expand Down
3 changes: 2 additions & 1 deletion sedr/schemat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import sys
import warnings
from urllib.parse import urljoin

import warnings
import pytest
import requests
import schemathesis
Expand Down Expand Up @@ -104,6 +104,7 @@ def test_openapi_schema():
else:
warnings.warn(errors)


@schema.parametrize() # parametrize => Create tests for all operations in schema
@settings(max_examples=sedr.util.args.iterations, deadline=None)
def test_openapi(case):
Expand Down