refactor(api): restructured API for type safety, maintainability and docs generation

- These changes makes the API incombatible with previous versions
- Added new types for error handling, success responses, and health checks.
- Updated health check logic to utilize the new types for better clarity and structure.
- Refactored existing handlers to improve response consistency and error handling.
- Updated Makefile to include a new target for generating API types from Swagger.
- Updated "new agent" API to respond an encrypted cert pair
This commit is contained in:
yusing
2025-08-16 13:04:05 +08:00
parent fce9ce21c9
commit 35a3e3fef6
149 changed files with 13173 additions and 2173 deletions

View File

@@ -0,0 +1,42 @@
# This script aims to fix the swagger.json file by setting the x-nullable flag to False if not present for all objects and arrays.
# This prevents from generating optional (undefined) fields in the generated API client.
import json
path = "internal/api/v1/docs/swagger.json"
with open(path, "r") as f:
data = json.load(f)
def set_non_nullable(data):
if not isinstance(data, dict):
return
if "x-nullable" not in data:
data["x-nullable"] = False
if "x-omitempty" not in data and data["x-nullable"] == False:
data["x-omitempty"] = False
if "type" not in data:
return
if data["type"] == "object" and "properties" in data:
for v in data["properties"].values():
set_non_nullable(v)
if data["type"] == "array":
for v in data["items"]:
set_non_nullable(v)
def set_operation_id(data):
if isinstance(data, dict):
if "x-id" in data:
data["operationId"] = data["x-id"]
return
for v in data.values():
set_operation_id(v)
for key, value in data.items():
if key == "definitions":
for k, v in value.items():
set_non_nullable(v)
else:
set_operation_id(value)
with open(path, "w") as f:
json.dump(data, f, indent=2)