api/docs: sort resources into tree order
This commit is contained in:
@@ -723,21 +723,21 @@ class TestLogFileSorting:
|
|||||||
expected_order
|
expected_order
|
||||||
):
|
):
|
||||||
actual = sorted_files[i]
|
actual = sorted_files[i]
|
||||||
assert (
|
assert actual.op_key == exp_op, (
|
||||||
actual.op_key == exp_op
|
f"Position {i}: expected op_key {exp_op}, got {actual.op_key}"
|
||||||
), f"Position {i}: expected op_key {exp_op}, got {actual.op_key}"
|
)
|
||||||
assert (
|
assert actual.date_day == exp_date, (
|
||||||
actual.date_day == exp_date
|
f"Position {i}: expected date {exp_date}, got {actual.date_day}"
|
||||||
), f"Position {i}: expected date {exp_date}, got {actual.date_day}"
|
)
|
||||||
assert (
|
assert actual.group == exp_group, (
|
||||||
actual.group == exp_group
|
f"Position {i}: expected group {exp_group}, got {actual.group}"
|
||||||
), f"Position {i}: expected group {exp_group}, got {actual.group}"
|
)
|
||||||
assert (
|
assert actual.func_name == exp_func, (
|
||||||
actual.func_name == exp_func
|
f"Position {i}: expected func {exp_func}, got {actual.func_name}"
|
||||||
), f"Position {i}: expected func {exp_func}, got {actual.func_name}"
|
)
|
||||||
assert (
|
assert actual.date_second == exp_time, (
|
||||||
actual.date_second == exp_time
|
f"Position {i}: expected time {exp_time}, got {actual.date_second}"
|
||||||
), f"Position {i}: expected time {exp_time}, got {actual.date_second}"
|
)
|
||||||
|
|
||||||
def test_get_log_file_returns_newest_when_multiple_exist(
|
def test_get_log_file_returns_newest_when_multiple_exist(
|
||||||
self, configured_log_manager: LogManager
|
self, configured_log_manager: LogManager
|
||||||
|
|||||||
@@ -118,6 +118,32 @@ def make_schema_name(func_name: str, part: str) -> str:
|
|||||||
return f"{func_name}_{part}"
|
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:
|
def main() -> None:
|
||||||
input_path = Path(os.environ["INPUT_PATH"])
|
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 ===
|
# === Add global definitions from $defs ===
|
||||||
for def_name, def_schema in defs.items():
|
for def_name, def_schema in defs.items():
|
||||||
fixed_schema = fix_nullables(deepcopy(def_schema))
|
fixed_schema = fix_nullables(deepcopy(def_schema))
|
||||||
|
|||||||
Reference in New Issue
Block a user