api/docs: sort resources into tree order

This commit is contained in:
Johannes Kirschbauer
2025-07-08 17:20:31 +02:00
parent 4beff2e023
commit da04ab63b2
2 changed files with 43 additions and 15 deletions

View File

@@ -723,21 +723,21 @@ class TestLogFileSorting:
expected_order
):
actual = sorted_files[i]
assert (
actual.op_key == exp_op
), f"Position {i}: expected op_key {exp_op}, got {actual.op_key}"
assert (
actual.date_day == exp_date
), f"Position {i}: expected date {exp_date}, got {actual.date_day}"
assert (
actual.group == exp_group
), f"Position {i}: expected group {exp_group}, got {actual.group}"
assert (
actual.func_name == exp_func
), f"Position {i}: expected func {exp_func}, got {actual.func_name}"
assert (
actual.date_second == exp_time
), f"Position {i}: expected time {exp_time}, got {actual.date_second}"
assert actual.op_key == exp_op, (
f"Position {i}: expected op_key {exp_op}, got {actual.op_key}"
)
assert actual.date_day == exp_date, (
f"Position {i}: expected date {exp_date}, got {actual.date_day}"
)
assert actual.group == exp_group, (
f"Position {i}: expected group {exp_group}, got {actual.group}"
)
assert actual.func_name == exp_func, (
f"Position {i}: expected func {exp_func}, got {actual.func_name}"
)
assert actual.date_second == exp_time, (
f"Position {i}: expected time {exp_time}, got {actual.date_second}"
)
def test_get_log_file_returns_newest_when_multiple_exist(
self, configured_log_manager: LogManager

View File

@@ -118,6 +118,32 @@ def make_schema_name(func_name: str, part: str) -> str:
return f"{func_name}_{part}"
def get_tag_key(tags: list[str]) -> tuple:
"""Convert list of tags to a tuple key for sorting."""
return tuple(tags)
def sort_openapi_paths_by_tag_tree(openapi: dict) -> None:
# Extract (tags, path, method, operation) tuples
operations = []
for path, methods in openapi["paths"].items():
for method, operation in methods.items():
tag_path = operation.get("tags", [])
operations.append((tag_path, path, method, operation))
# Sort by the tag hierarchy
operations.sort(key=lambda x: get_tag_key(x[0]))
# Rebuild sorted openapi["paths"]
sorted_paths: dict = {}
for _tag_path, path, method, operation in operations:
sorted_paths[path] = sorted_paths.get(path, {})
sorted_paths[path][method] = operation
openapi["paths"] = dict(sorted_paths) # Ensure it's a plain dict
def main() -> None:
input_path = Path(os.environ["INPUT_PATH"])
@@ -203,6 +229,8 @@ def main() -> None:
}
}
sort_openapi_paths_by_tag_tree(openapi)
# === Add global definitions from $defs ===
for def_name, def_schema in defs.items():
fixed_schema = fix_nullables(deepcopy(def_schema))