Skip to content

Commit 5cc3047

Browse files
committed
Update documentation and script for api
1 parent 14359bc commit 5cc3047

File tree

4 files changed

+139
-32
lines changed

4 files changed

+139
-32
lines changed

.DS_Store

0 Bytes
Binary file not shown.

docs/liberty/api/liberty-api.md

Lines changed: 119 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
# Liberty API
22

3-
**Description:** API For Liberty Framework
3+
**Description:**
4+
**Liberty API** provides a powerful and scalable backend for managing authentication,
5+
database operations, and framework functionalities in the **Liberty Framework**.
6+
7+
### 🔹 Key Features:
8+
- **Authentication & Authorization**: Secure endpoints with JWT tokens and OAuth2.
9+
- **Database Management**: Query, insert, update, and delete records across multiple pools.
10+
- **Framework Controls**: Manage modules, applications, themes, and logs.
11+
- **Security & Encryption**: Encrypt data and ensure safe database access.
12+
- **Logging & Auditing**: Retrieve and analyze logs for security and debugging.
13+
14+
### 🔹 Authentication
15+
- **`/api/auth/token`** - Generate a JWT token for authentication.
16+
- **`/api/auth/user`** - Retrieve authenticated user details.
17+
18+
### 🔹 Database Operations
19+
- **`/api/db/check`** - Validate database connection.
20+
- **`/api/db/query`** - Retrieve, insert, update, or delete records.
21+
- **`/api/db/audit/{table}/{user}`** - Audit changes on a specific table.
22+
23+
### 🔹 Framework Features
24+
- **`/api/fmw/modules`** - Retrieve framework modules.
25+
- **`/api/fmw/applications`** - Retrieve available applications.
26+
- **`/api/fmw/themes`** - Manage application themes.
27+
28+
**🔗 Explore the API using Swagger UI (`/api/test`) or Redoc (`/api`).**
29+
430

531
**Version:** 1.0.0
632

@@ -43,32 +69,8 @@ Retrieve user information.
4369
"status": "success"
4470
}
4571
```
46-
??? warning "Response `422`: Validation Error"
72+
??? warning "Response `422`: Unprocessable Entity"
4773
- **Content-Type:** `application/json`
48-
- **Example:**
49-
50-
```json
51-
{
52-
"detail": [
53-
{
54-
"loc": [
55-
"query",
56-
"name"
57-
],
58-
"msg": "field required",
59-
"type": "value_error.missing"
60-
},
61-
{
62-
"loc": [
63-
"query",
64-
"quantity"
65-
],
66-
"msg": "value is not a valid integer",
67-
"type": "type_error.integer"
68-
}
69-
]
70-
}
71-
```
7274
??? danger "Response `500`: Internal server error"
7375
- **Content-Type:** `application/json`
7476
- **Example:**
@@ -98,7 +100,29 @@ Generate a JWT token for the user.
98100

99101
```json
100102
{
101-
"$ref": "#/components/schemas/LoginRequest"
103+
"properties": {
104+
"user": {
105+
"type": "string",
106+
"title": "User"
107+
},
108+
"password": {
109+
"anyOf": [
110+
{
111+
"type": "string"
112+
},
113+
{
114+
"type": "null"
115+
}
116+
],
117+
"title": "Password"
118+
}
119+
},
120+
"type": "object",
121+
"required": [
122+
"user",
123+
"password"
124+
],
125+
"title": "LoginRequest"
102126
}
103127
```
104128
**📥 Responses:**
@@ -620,7 +644,7 @@ Performs a basic check to ensure the database connection is functional. Returns
620644
"rows": [
621645
{
622646
"ROW_ID": 1,
623-
"CURRENT_TIME": "2025-01-27T08:14:13.809494+00:00"
647+
"CURRENT_DATE": "2025-01-27T08:14:13.809494+00:00"
624648
}
625649
],
626650
"rowCount": 1,
@@ -630,7 +654,7 @@ Performs a basic check to ensure the database connection is functional. Returns
630654
"type": "int"
631655
},
632656
{
633-
"name": "CURRENT_TIME",
657+
"name": "CURRENT_DATE",
634658
"type": "datetime"
635659
}
636660
]
@@ -927,10 +951,75 @@ Audit user actions on a table.
927951
- **`user`** *(in path)*: No description (**Required**)
928952
**📥 Responses:**
929953

930-
??? success "Response `200`: Successful Response"
954+
??? success "Response `200`: Data inserted/updated successfully"
931955
- **Content-Type:** `application/json`
956+
- **Example:**
957+
958+
```json
959+
{
960+
"items": [],
961+
"status": "success",
962+
"count": 0
963+
}
964+
```
965+
??? warning "Response `400`: Bad Request"
966+
- **Content-Type:** `application/json`
967+
- **Example:**
968+
969+
```json
970+
{
971+
"status": "failed",
972+
"message": "Request body cannot be empty. JSON object with key-value pairs is required."
973+
}
974+
```
932975
??? warning "Response `422`: Validation Error"
933976
- **Content-Type:** `application/json`
977+
- **Example:**
978+
979+
```json
980+
{
981+
"detail": [
982+
{
983+
"loc": [
984+
"query",
985+
"name"
986+
],
987+
"msg": "field required",
988+
"type": "value_error.missing"
989+
},
990+
{
991+
"loc": [
992+
"query",
993+
"quantity"
994+
],
995+
"msg": "value is not a valid integer",
996+
"type": "type_error.integer"
997+
}
998+
]
999+
}
1000+
```
1001+
??? danger "Response `500`: Internal server error"
1002+
- **Content-Type:** `application/json`
1003+
- **Example:**
1004+
1005+
```json
1006+
{
1007+
"status": "failed",
1008+
"message": {
1009+
"items": [
1010+
{
1011+
"message": "Error: Query execution failed: Query execution failed: INSERT INTO...",
1012+
"line": {
1013+
"field1": "<string>",
1014+
"field2": "<string>"
1015+
}
1016+
}
1017+
],
1018+
"status": "error",
1019+
"count": 0
1020+
}
1021+
}
1022+
```
9341023

9351024
---
9361025

json/liberty-api.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

scripts/gendoc.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
with open("../json/liberty-api.json", "r") as f:
66
openapi_data = json.load(f)
77

8+
# Store schema definitions
9+
schemas = openapi_data.get("components", {}).get("schemas", {})
10+
11+
12+
def resolve_schema(ref):
13+
"""Resolve a $ref schema reference."""
14+
if ref.startswith("#/components/schemas/"):
15+
schema_name = ref.split("/")[-1]
16+
return schemas.get(schema_name, {})
17+
return {}
18+
819
# Add background color for method
920
def method_with_style(method):
1021
color_map = {
@@ -56,6 +67,10 @@ def method_with_style(method):
5667
if "parameters" in details:
5768
for param in details["parameters"]:
5869
required = " (**Required**)" if param.get("required", False) else ""
70+
param_schema = param.get("schema", {})
71+
if "$ref" in param_schema:
72+
param_schema = resolve_schema(param_schema["$ref"]) # Resolve $ref
73+
5974
default = f" *(Default: `{param['schema']['default']}`)*" if "default" in param["schema"] else ""
6075
markdown += f" - **`{param['name']}`** *(in {param['in']})*: {param.get('description', 'No description')}{required}{default}\n"
6176
else:
@@ -67,7 +82,10 @@ def method_with_style(method):
6782
request_body = details["requestBody"]["content"]
6883
for content_type, body_details in request_body.items():
6984
markdown += f" - **Content-Type:** `{content_type}`\n"
70-
body_json = json.dumps(body_details.get('schema', {}), indent=4)
85+
body_schema = body_details.get("schema", {})
86+
if "$ref" in body_schema:
87+
body_schema = resolve_schema(body_schema["$ref"]) # Resolve $ref
88+
body_json = json.dumps(body_schema, indent=4)
7189
json_block = "\n".join([f" {line}" for line in body_json.splitlines()])
7290
markdown += f" - **Example:**\n\n"
7391
markdown += f" ```json\n{json_block}\n ```\n"

0 commit comments

Comments
 (0)