1 files changed, 13 insertions, 10 deletions
diff --git a/synapse/rest/client/_base.py b/synapse/rest/client/_base.py
index b4cb90cb76..5c1c19e1f3 100644
--- a/synapse/rest/client/_base.py
+++ b/synapse/rest/client/_base.py
@@ -43,19 +43,22 @@ def client_patterns(
Returns:
An iterable of patterns.
"""
- patterns = []
+ versions = []
- if unstable:
- unstable_prefix = CLIENT_API_PREFIX + "/unstable"
- patterns.append(re.compile("^" + unstable_prefix + path_regex))
if v1:
- v1_prefix = CLIENT_API_PREFIX + "/api/v1"
- patterns.append(re.compile("^" + v1_prefix + path_regex))
- for release in releases:
- new_prefix = CLIENT_API_PREFIX + f"/{release}"
- patterns.append(re.compile("^" + new_prefix + path_regex))
+ versions.append("api/v1")
+ versions.extend(releases)
+ if unstable:
+ versions.append("unstable")
+
+ if len(versions) == 1:
+ versions_str = versions[0]
+ elif len(versions) > 1:
+ versions_str = "(" + "|".join(versions) + ")"
+ else:
+ raise RuntimeError("Must have at least one version for a URL")
- return patterns
+ return [re.compile("^" + CLIENT_API_PREFIX + "/" + versions_str + path_regex)]
def set_timeline_upper_limit(filter_json: JsonDict, filter_timeline_limit: int) -> None:
|