Skip to content

Commit 830a859

Browse files
committed
Add meaningful examples to error responses (400/401/403/404/409/500)
1 parent 98c4972 commit 830a859

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

openapi-public.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,36 +2020,54 @@ components:
20202020
application/json:
20212021
schema:
20222022
$ref: '#/components/schemas/Error'
2023+
example:
2024+
code: 400
2025+
message: 'Bad request: invalid or missing request parameters'
20232026
'401':
20242027
description: Authentication error
20252028
content:
20262029
application/json:
20272030
schema:
20282031
$ref: '#/components/schemas/Error'
2032+
example:
2033+
code: 401
2034+
message: 'Authentication error: missing or invalid API key'
20292035
'403':
20302036
description: Forbidden
20312037
content:
20322038
application/json:
20332039
schema:
20342040
$ref: '#/components/schemas/Error'
2041+
example:
2042+
code: 403
2043+
message: 'Forbidden: insufficient permissions'
20352044
'404':
20362045
description: Not found
20372046
content:
20382047
application/json:
20392048
schema:
20402049
$ref: '#/components/schemas/Error'
2050+
example:
2051+
code: 404
2052+
message: 'Not found: the requested resource does not exist'
20412053
'409':
20422054
description: Conflict
20432055
content:
20442056
application/json:
20452057
schema:
20462058
$ref: '#/components/schemas/Error'
2059+
example:
2060+
code: 409
2061+
message: 'Conflict: the resource is in a conflicting state'
20472062
'500':
20482063
description: Server error
20492064
content:
20502065
application/json:
20512066
schema:
20522067
$ref: '#/components/schemas/Error'
2068+
example:
2069+
code: 500
2070+
message: 'Server error: an unexpected error occurred'
20532071
schemas:
20542072
Error:
20552073
required:

scripts/generate_openapi_reference.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,27 @@ def _singularize(word: str) -> str:
10131013
responses["500"] = {"$ref": "#/components/responses/500"}
10141014
fixes.append("/sandboxes/{sandboxID}/refreshes: added 500 response")
10151015

1016+
# 25. Add meaningful examples to error responses
1017+
error_examples = {
1018+
"400": {"code": 400, "message": "Bad request: invalid or missing request parameters"},
1019+
"401": {"code": 401, "message": "Authentication error: missing or invalid API key"},
1020+
"403": {"code": 403, "message": "Forbidden: insufficient permissions"},
1021+
"404": {"code": 404, "message": "Not found: the requested resource does not exist"},
1022+
"409": {"code": 409, "message": "Conflict: the resource is in a conflicting state"},
1023+
"500": {"code": 500, "message": "Server error: an unexpected error occurred"},
1024+
}
1025+
responses = spec.get("components", {}).get("responses", {})
1026+
for status, example in error_examples.items():
1027+
resp = responses.get(status)
1028+
if resp and "content" in resp:
1029+
schema = resp["content"].get("application/json", {}).get("schema")
1030+
if schema:
1031+
resp["content"]["application/json"]["schema"] = {
1032+
**schema,
1033+
"example": example,
1034+
}
1035+
fixes.append("Error responses: added example values for 400/401/403/404/409/500")
1036+
10161037
if fixes:
10171038
print(f"==> Fixed {len(fixes)} spec issues:")
10181039
for f in fixes:

0 commit comments

Comments
 (0)