Skip to content

Commit 9e3df4e

Browse files
authored
Merge pull request #91 from metno/90-allow-openapi-spec-in-yaml
fixes issue #62
2 parents 1b67d54 + 19998a5 commit 9e3df4e

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

sedr/metoceanprofilecore10.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""metocean-edr-profile core requirements. See <https://github.com/EUMETNET/metocean-edr-profile/>."""
22

33
import json
4+
import re
45

56
import pint
67
import requests
@@ -42,33 +43,55 @@ def requirement7_2(jsondata: dict, timeout: int = 10) -> tuple[bool, str]:
4243
returns status: bool, message
4344
"""
4445
spec_url = f"{spec_base_url}#_openapi"
45-
openapi_type = "application/vnd.oai.openapi+json;version=3.1"
46+
openapi_types = [
47+
"application/openapi+json",
48+
"application/openapi+yaml",
49+
"application/vnd.oai.openapi+json",
50+
"application/vnd.oai.openapi+yaml",
51+
]
4652
servicedoc_type = "text/html"
4753

4854
service_desc_link = ""
4955
service_desc_type = ""
5056
for link in jsondata["links"]:
5157
if link["rel"] == "service-desc":
5258
service_desc_link = link["href"]
53-
service_desc_type = link["type"]
59+
service_desc_type, service_desc_version = (link["type"].split(";", 1) + [None, None])[:2]
5460
break
5561

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

6270
# C - relation type
63-
if openapi_type not in service_desc_type:
71+
if service_desc_type not in openapi_types:
6472
return (
6573
False,
66-
"OpenAPI link service-desc should identify the content as openAPI "
67-
f"and include version. Example <{openapi_type}>. Found: "
74+
"OpenAPI link service-desc must identify the content as openAPI "
75+
f"and should include version. Example <{openapi_types[0]}>. Found: "
6876
f"<{service_desc_type}>. See <{spec_url}> and <{spec_base_url}"
6977
"#_openapi_2> for more info.",
7078
)
7179

80+
if service_desc_version:
81+
m = re.match(r"^version=(\d+\.\d+)$", service_desc_version)
82+
if m:
83+
version = m.groups()[0]
84+
if version != "3.1": # profile should allow later versions FIXME
85+
return (
86+
False,
87+
f"OpenAPI version not 3.1: {version}.",
88+
)
89+
else:
90+
return (
91+
False,
92+
f"OpenAPI version suffix malformed: {service_desc_version}.",
93+
)
94+
7295
# A - described using an OpenAPI document
7396
response = requests.get(service_desc_link, timeout=timeout)
7497
if not response.status_code < 400:

sedr/schemat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
import sys
3+
import warnings
34
from urllib.parse import urljoin
45

5-
import warnings
66
import pytest
77
import requests
88
import schemathesis
@@ -104,6 +104,7 @@ def test_openapi_schema():
104104
else:
105105
warnings.warn(errors)
106106

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

0 commit comments

Comments
 (0)