-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathservers.py
More file actions
27 lines (19 loc) · 743 Bytes
/
servers.py
File metadata and controls
27 lines (19 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import Any
from typing import Dict
from jsonschema_path import SchemaPath
def is_absolute(url: str) -> bool:
return url.startswith("//") or "://" in url
def get_server_default_variables(server: SchemaPath) -> Dict[str, Any]:
if "variables" not in server:
return {}
defaults = {}
variables = server / "variables"
for name, variable in list(variables.str_items()):
defaults[name] = (variable / "default").read_value()
return defaults
def get_server_url(server: SchemaPath, **variables: Any) -> str:
if not variables:
variables = get_server_default_variables(server)
url = (server / "url").read_value()
assert isinstance(url, str)
return url.format(**variables)