A JSON object containing information about an available API version
Source code in optimade/models/baseinfo.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 | class AvailableApiVersion(BaseModel):
"""A JSON object containing information about an available API version"""
url: AnyHttpUrl = StrictField(
...,
description="A string specifying a versioned base URL that MUST adhere to the rules in section Base URL",
pattern=r".+/v[0-1](\.[0-9]+)*/?$",
)
version: SemanticVersion = StrictField(
...,
description="""A string containing the full version number of the API served at that versioned base URL.
The version number string MUST NOT be prefixed by, e.g., 'v'.
Examples: `1.0.0`, `1.0.0-rc.2`.""",
)
@validator("url")
def url_must_be_versioned_base_url(cls, v):
"""The URL must be a valid versioned Base URL"""
if not re.match(r".+/v[0-1](\.[0-9]+)*/?$", v):
raise ValueError(f"url MUST be a versioned base URL. It is: {v}")
return v
@root_validator(pre=False, skip_on_failure=True)
def crosscheck_url_and_version(cls, values):
"""Check that URL version and API version are compatible."""
url_version = (
values["url"]
.split("/")[-2 if values["url"].endswith("/") else -1]
.replace("v", "")
)
# as with version urls, we need to split any release tags or build metadata out of these URLs
url_version = tuple(
int(val) for val in url_version.split("-")[0].split("+")[0].split(".")
)
api_version = tuple(
int(val) for val in values["version"].split("-")[0].split("+")[0].split(".")
)
if any(a != b for a, b in zip(url_version, api_version)):
raise ValueError(
f"API version {api_version} is not compatible with url version {url_version}."
)
return values
|
url: AnyHttpUrl = StrictField(Ellipsis, description='A string specifying a versioned base URL that MUST adhere to the rules in section Base URL', pattern='.+/v[0-1](\\.[0-9]+)*/?$')
class-attribute
version: SemanticVersion = StrictField(Ellipsis, description="A string containing the full version number of the API served at that versioned base URL.\nThe version number string MUST NOT be prefixed by, e.g., 'v'.\nExamples: `1.0.0`, `1.0.0-rc.2`.")
class-attribute
crosscheck_url_and_version(values)
Check that URL version and API version are compatible.
Source code in optimade/models/baseinfo.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 | @root_validator(pre=False, skip_on_failure=True)
def crosscheck_url_and_version(cls, values):
"""Check that URL version and API version are compatible."""
url_version = (
values["url"]
.split("/")[-2 if values["url"].endswith("/") else -1]
.replace("v", "")
)
# as with version urls, we need to split any release tags or build metadata out of these URLs
url_version = tuple(
int(val) for val in url_version.split("-")[0].split("+")[0].split(".")
)
api_version = tuple(
int(val) for val in values["version"].split("-")[0].split("+")[0].split(".")
)
if any(a != b for a, b in zip(url_version, api_version)):
raise ValueError(
f"API version {api_version} is not compatible with url version {url_version}."
)
return values
|
url_must_be_versioned_base_url(v)
The URL must be a valid versioned Base URL
Source code in optimade/models/baseinfo.py
| @validator("url")
def url_must_be_versioned_base_url(cls, v):
"""The URL must be a valid versioned Base URL"""
if not re.match(r".+/v[0-1](\.[0-9]+)*/?$", v):
raise ValueError(f"url MUST be a versioned base URL. It is: {v}")
return v
|