mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-06 08:19:56 -06:00
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:
42
scripts/fix-swagger-json.py
Normal file
42
scripts/fix-swagger-json.py
Normal 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)
|
||||
Reference in New Issue
Block a user