Skip to content

Commit dda0fca

Browse files
committed
docs: normalize API reference version summaries
1 parent b1c627b commit dda0fca

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

scripts/generate_openapi_reference.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,35 @@ 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)
677+
678+
679+
def normalize_versioned_summaries(spec: dict[str, Any]) -> int:
680+
"""Append `(vN)` to versioned platform endpoint summaries when missing."""
681+
count = 0
682+
for ep_path, path_item in spec.get("paths", {}).items():
683+
match = VERSIONED_PLATFORM_PATH_RE.match(ep_path)
684+
if not match:
685+
continue
686+
687+
version_label = match.group(1).lower()
688+
for method in ("get", "post", "put", "patch", "delete", "head", "options"):
689+
op = path_item.get(method)
690+
if not op:
691+
continue
692+
693+
summary = op.get("summary")
694+
if not isinstance(summary, str) or not summary.strip():
695+
continue
696+
if re.search(rf"\({re.escape(version_label)}\)", summary, re.IGNORECASE):
697+
continue
698+
699+
op["summary"] = f"{summary.rstrip()} ({version_label})"
700+
count += 1
701+
702+
return count
703+
704+
676705
STREAMING_ENDPOINTS = {
677706
"/filesystem.Filesystem/WatchDir",
678707
"/process.Process/Start",
@@ -1152,6 +1181,12 @@ def _singularize(word: str) -> str:
11521181
if summary_count:
11531182
fixes.append(f"Added summary to {summary_count} platform endpoints")
11541183

1184+
normalized_summary_count = normalize_versioned_summaries(spec)
1185+
if normalized_summary_count:
1186+
fixes.append(
1187+
f"Normalized version suffix on {normalized_summary_count} versioned endpoint summaries"
1188+
)
1189+
11551190
# 27. Replace nullable: true with OpenAPI 3.1.0 type arrays
11561191
# In 3.1.0, nullable was removed. Use type: ["string", "null"] instead,
11571192
# or oneOf with type: 'null' for $ref properties.

0 commit comments

Comments
 (0)