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