Skip to content

Commit d854800

Browse files
committed
docs: regenerate API reference version summaries
1 parent dda0fca commit d854800

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

scripts/generate_openapi_reference.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,34 @@ def add_operation_ids(spec: dict[str, Any]) -> None:
673673
print(f"==> Added {count} operationIds to envd endpoints")
674674

675675

676-
VERSIONED_PLATFORM_PATH_RE = re.compile(r"^/(v\d+)(?:/|$)", re.IGNORECASE)
676+
VERSIONED_PLATFORM_SEGMENT_RE = re.compile(r"^(v\d+)([A-Za-z][^/]*)?$", re.IGNORECASE)
677+
678+
679+
def extract_leading_version_label(ep_path: str) -> str | None:
680+
"""Return `vN` for a versioned leading path segment like `v2` or `v2templates`."""
681+
first_segment = ep_path.lstrip("/").split("/", 1)[0]
682+
match = VERSIONED_PLATFORM_SEGMENT_RE.match(first_segment)
683+
if not match:
684+
return None
685+
return match.group(1).lower()
686+
687+
688+
def split_leading_version_segment(segment: str) -> tuple[str | None, str | None]:
689+
"""Split `vNfoo` into (`VN`, `foo`) and `vN` into (`VN`, None)."""
690+
match = VERSIONED_PLATFORM_SEGMENT_RE.match(segment)
691+
if not match:
692+
return None, None
693+
return match.group(1).upper(), match.group(2)
677694

678695

679696
def normalize_versioned_summaries(spec: dict[str, Any]) -> int:
680697
"""Append `(vN)` to versioned platform endpoint summaries when missing."""
681698
count = 0
682699
for ep_path, path_item in spec.get("paths", {}).items():
683-
match = VERSIONED_PLATFORM_PATH_RE.match(ep_path)
684-
if not match:
700+
version_label = extract_leading_version_label(ep_path)
701+
if not version_label:
685702
continue
686703

687-
version_label = match.group(1).lower()
688704
for method in ("get", "post", "put", "patch", "delete", "head", "options"):
689705
op = path_item.get(method)
690706
if not op:
@@ -907,6 +923,14 @@ def _singularize(word: str) -> str:
907923
i = 0
908924
while i < len(raw_segments):
909925
seg = raw_segments[i]
926+
if i == 0:
927+
detected_version, remainder = split_leading_version_segment(seg)
928+
if detected_version:
929+
version_suffix = detected_version
930+
if remainder:
931+
parts.append(remainder)
932+
i += 1
933+
continue
910934
if seg in ("v2", "v3"):
911935
version_suffix = seg.upper()
912936
i += 1

0 commit comments

Comments
 (0)