@@ -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