Skip to content

Commit b95f1c7

Browse files
committed
Move error example to Error schema so it applies to all references
1 parent 6978cf0 commit b95f1c7

2 files changed

Lines changed: 11 additions & 38 deletions

File tree

openapi-public.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,54 +2064,36 @@ components:
20642064
application/json:
20652065
schema:
20662066
$ref: '#/components/schemas/Error'
2067-
example:
2068-
code: 400
2069-
message: 'Bad request: invalid or missing request parameters'
20702067
'401':
20712068
description: Authentication error
20722069
content:
20732070
application/json:
20742071
schema:
20752072
$ref: '#/components/schemas/Error'
2076-
example:
2077-
code: 401
2078-
message: 'Authentication error: missing or invalid API key'
20792073
'403':
20802074
description: Forbidden
20812075
content:
20822076
application/json:
20832077
schema:
20842078
$ref: '#/components/schemas/Error'
2085-
example:
2086-
code: 403
2087-
message: 'Forbidden: insufficient permissions'
20882079
'404':
20892080
description: Not found
20902081
content:
20912082
application/json:
20922083
schema:
20932084
$ref: '#/components/schemas/Error'
2094-
example:
2095-
code: 404
2096-
message: 'Not found: the requested resource does not exist'
20972085
'409':
20982086
description: Conflict
20992087
content:
21002088
application/json:
21012089
schema:
21022090
$ref: '#/components/schemas/Error'
2103-
example:
2104-
code: 409
2105-
message: 'Conflict: the resource is in a conflicting state'
21062091
'500':
21072092
description: Server error
21082093
content:
21092094
application/json:
21102095
schema:
21112096
$ref: '#/components/schemas/Error'
2112-
example:
2113-
code: 500
2114-
message: 'Server error: an unexpected error occurred'
21152097
schemas:
21162098
Error:
21172099
required:
@@ -2126,6 +2108,9 @@ components:
21262108
type: string
21272109
description: Error
21282110
type: object
2111+
example:
2112+
code: 400
2113+
message: 'Bad request: invalid or missing request parameters'
21292114
EntryInfo:
21302115
required:
21312116
- path

scripts/generate_openapi_reference.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,26 +1022,14 @@ def _singularize(word: str) -> str:
10221022
responses["500"] = {"$ref": "#/components/responses/500"}
10231023
fixes.append("/sandboxes/{sandboxID}/refreshes: added 500 response")
10241024

1025-
# 25. Add meaningful examples to error responses
1026-
error_examples = {
1027-
"400": {"code": 400, "message": "Bad request: invalid or missing request parameters"},
1028-
"401": {"code": 401, "message": "Authentication error: missing or invalid API key"},
1029-
"403": {"code": 403, "message": "Forbidden: insufficient permissions"},
1030-
"404": {"code": 404, "message": "Not found: the requested resource does not exist"},
1031-
"409": {"code": 409, "message": "Conflict: the resource is in a conflicting state"},
1032-
"500": {"code": 500, "message": "Server error: an unexpected error occurred"},
1033-
}
1034-
responses = spec.get("components", {}).get("responses", {})
1035-
for status, example in error_examples.items():
1036-
resp = responses.get(status)
1037-
if resp and "content" in resp:
1038-
schema = resp["content"].get("application/json", {}).get("schema")
1039-
if schema:
1040-
resp["content"]["application/json"]["schema"] = {
1041-
**schema,
1042-
"example": example,
1043-
}
1044-
fixes.append("Error responses: added example values for 400/401/403/404/409/500")
1025+
# 25. Add meaningful example to the Error schema (applies everywhere it's referenced)
1026+
error_schema = schemas.get("Error")
1027+
if error_schema and "example" not in error_schema:
1028+
error_schema["example"] = {
1029+
"code": 400,
1030+
"message": "Bad request: invalid or missing request parameters",
1031+
}
1032+
fixes.append("Error schema: added example values")
10451033

10461034
if fixes:
10471035
print(f"==> Fixed {len(fixes)} spec issues:")

0 commit comments

Comments
 (0)