Skip to content

Commit c8f4c42

Browse files
docs: shorten response_description
i think its best not to remove response_description, u can understand what the endpoint does just from reading the source code also removed summary as requested
1 parent 6361a22 commit c8f4c42

File tree

10 files changed

+141
-595
lines changed

10 files changed

+141
-595
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pydantic import BaseModel
2+
from typing import List, Optional
3+
4+
class ErrorResponse(BaseModel):
5+
"""
6+
Generic error response
7+
msg_code: 0 (db_error), 2 (ctf_not_found)
8+
"""
9+
msg_code: int
10+
11+
class ContainerStartResponse(BaseModel):
12+
"""
13+
Response for container start operation
14+
msg_code: 3 (success), 7 (already running), 8 (limit reached), 0 (db_error)
15+
"""
16+
msg_code: int
17+
ports: Optional[List[int]] = None
18+
ctf_id: Optional[int] = None
19+
20+
class ContainerStopResponse(BaseModel):
21+
"""
22+
Response for container stop operations
23+
msg_code: 4 (stop success), 5 (stopall success), 6 (not found), 0 (db_error)
24+
"""
25+
msg_code: int

src/pwncore/routes/admin.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,13 @@ class AdminResponse(BaseModel):
5858
success: bool
5959
message: Optional[str] = None
6060

61-
61+
# shorten response_description
6262
@atomic()
6363
@router.get("/union",
64-
summary="Calculate and update team coins",
6564
response_model=AdminResponse,
6665
response_description="""Successful calculation of team points and coin updates.
6766
68-
Example response:
69-
```json
70-
{
71-
"success": true,
72-
"message": "Team coins updated successfully"
73-
}
74-
```
67+
Response parameters: boolean `success`, `message`
7568
7669
Note: Returns 401 if authentication fails.
7770
""")
@@ -106,20 +99,13 @@ async def calculate_team_coins(
10699

107100
return AdminResponse(success=True, message="Team coins updated successfully")
108101

109-
102+
# shorten response_description
110103
@router.get("/create",
111-
summary="Initialize database with sample data",
112104
response_model=AdminResponse,
113105
response_description="""Database initialization with sample data.
114106
115-
Example response:
116-
```json
117-
{
118-
"success": true,
119-
"message": "Database initialized with sample data"
120-
}
121-
```
122-
107+
Response parameters: boolean `success`, `message`
108+
123109
Note: Returns 401 if authentication fails.
124110
This endpoint should only be used in development environment.
125111
""")

src/pwncore/routes/admin_dashboard.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/pwncore/routes/auth.py

Lines changed: 20 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ErrorResponse(BaseModel):
7878
def normalise_tag(tag: str):
7979
return tag.strip().casefold()
8080

81-
81+
# shorten response_description
8282
@atomic()
8383
@router.post("/signup",
8484
response_model=SignupResponse,
@@ -90,48 +90,16 @@ def normalise_tag(tag: str):
9090
},
9191
response_description="""Create a new team with associated members.
9292
93-
Request body example:
94-
```json
95-
{
96-
"name": "TeamAwesome",
97-
"password": "securepassword123",
98-
"tags": ["user1", "user2", "user3"]
99-
}
100-
```
101-
102-
Responses:
103-
- 200: Successful signup
104-
```json
105-
{
106-
"msg_code": 13
107-
}
108-
```
109-
- 406: Team already exists
110-
```json
111-
{
112-
"msg_code": 17
113-
}
114-
```
115-
- 404: Users not found
116-
```json
117-
{
118-
"msg_code": 24,
119-
"tags": ["user2", "user3"]
120-
}
121-
```
122-
- 401: Users already in team
123-
```json
124-
{
125-
"msg_code": 20,
126-
"tags": ["user1"]
127-
}
128-
```
129-
- 500: Database error
130-
```json
131-
{
132-
"msg_code": 0
133-
}
134-
```
93+
Parameters:
94+
- in request: `name`, `password`, `tags`
95+
- in response: `msg_code`, `tags` _only in error responses_
96+
97+
msg_codes for Responses:
98+
- 200: Successful signup : 13
99+
- 406: Team already exists: 17
100+
- 404: Users not found: 24
101+
- 401: Users already in team: 20
102+
- 500: Database error: 0
135103
""")
136104
async def signup_team(team: SignupBody, response: Response):
137105
team.name = team.name.strip()
@@ -175,7 +143,7 @@ async def signup_team(team: SignupBody, response: Response):
175143
return {"msg_code": config.msg_codes["db_error"]}
176144
return {"msg_code": config.msg_codes["signup_success"]}
177145

178-
146+
# shorten response_description
179147
@router.post("/login",
180148
response_model=LoginResponse,
181149
responses={
@@ -184,35 +152,15 @@ async def signup_team(team: SignupBody, response: Response):
184152
},
185153
response_description="""Authenticate a team and receive a JWT token.
186154
187-
Request body example:
188-
```json
189-
{
190-
"name": "TeamAwesome",
191-
"password": "securepassword123"
192-
}
193-
```
155+
Parameters:
156+
- in request: `name`, `password`
157+
- in successful response: `msg_code`, `access_token`,`token_type`
158+
- in error responses: `msg_code`
194159
195-
Responses:
196-
- 200: Successful login
197-
```json
198-
{
199-
"msg_code": 15,
200-
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
201-
"token_type": "bearer"
202-
}
203-
```
204-
- 404: Team not found
205-
```json
206-
{
207-
"msg_code": 10
208-
}
209-
```
210-
- 401: Wrong password
211-
```json
212-
{
213-
"msg_code": 14
214-
}
215-
```
160+
msg_codes for Responses:
161+
- 200: Successful login: 15
162+
- 404: Team not found: 10
163+
- 401: Wrong password: 14
216164
""")
217165
async def team_login(team_data: AuthBody, response: Response):
218166
# TODO: Simplified logic since we're not doing refresh tokens.

0 commit comments

Comments
 (0)