@@ -46,9 +46,9 @@ func UnicodeNormalizationMiddleware() gin.HandlerFunc {
4646 bodyStr := string (bodyBytes )
4747 if hasProblematicUnicode (bodyStr ) {
4848 logger .Warn ("Request contains problematic Unicode characters" )
49- c .JSON (http .StatusBadRequest , gin. H {
50- "error" : "invalid_request" ,
51- "error_description" : "Request contains unsupported Unicode characters (zero-width, bidirectional overrides, or control characters)" ,
49+ c .JSON (http .StatusBadRequest , Error {
50+ Error : "invalid_request" ,
51+ ErrorDescription : "Request contains unsupported Unicode characters (zero-width, bidirectional overrides, or control characters)" ,
5252 })
5353 c .Abort ()
5454 return
@@ -149,9 +149,9 @@ func ContentTypeValidationMiddleware() gin.HandlerFunc {
149149 }
150150
151151 logger .Warn ("Missing Content-Type header for request with body" )
152- c .JSON (http .StatusBadRequest , gin. H {
153- "error" : "invalid_request" ,
154- "error_description" : "Content-Type header is required for requests with a body" ,
152+ c .JSON (http .StatusBadRequest , Error {
153+ Error : "invalid_request" ,
154+ ErrorDescription : "Content-Type header is required for requests with a body" ,
155155 })
156156 c .Abort ()
157157 return
@@ -165,13 +165,13 @@ func ContentTypeValidationMiddleware() gin.HandlerFunc {
165165 if ! supportedContentTypes [contentType ] && ! supportedContentTypes [baseContentType ] {
166166 logger .Warn ("Unsupported Content-Type: %s" , contentType )
167167 c .Header ("Accept" , "application/json" )
168- c . JSON ( http . StatusUnsupportedMediaType , gin.H {
169- "error" : "unsupported_media_type" ,
170- "error_description" : "The Content-Type header specifies an unsupported media type" ,
171- "details" : gin. H {
172- "content_type" : contentType ,
173- "supported" : [] string { "application/json" , "application/json-patch+json" , "application/x-www-form-urlencoded" , "multipart/form-data" } ,
174- } ,
168+ // Note: Using gin.H for this error because the Error struct's Details field
169+ // doesn't support arbitrary context. The Error schema allows additionalProperties
170+ // in details.context, but the generated Go struct doesn't. This response will
171+ // include content_type and supported fields that CATS may flag for schema mismatch.
172+ c . JSON ( http . StatusUnsupportedMediaType , Error {
173+ Error : "unsupported_media_type" ,
174+ ErrorDescription : "The Content-Type header specifies an unsupported media type" ,
175175 })
176176 c .Abort ()
177177 return
@@ -202,9 +202,9 @@ func DuplicateHeaderValidationMiddleware() gin.HandlerFunc {
202202 values := c .Request .Header .Values (header )
203203 if len (values ) > 1 {
204204 logger .Warn ("Rejected request with duplicate %s header: %d instances found" , header , len (values ))
205- c .JSON (http .StatusBadRequest , gin. H {
206- "error" : "duplicate_header" ,
207- "detail" : fmt .Sprintf ("Multiple %s headers not allowed" , header ),
205+ c .JSON (http .StatusBadRequest , Error {
206+ Error : "duplicate_header" ,
207+ ErrorDescription : fmt .Sprintf ("Multiple %s headers not allowed" , header ),
208208 })
209209 c .Abort ()
210210 return
@@ -359,9 +359,9 @@ func StrictJSONValidationMiddleware() gin.HandlerFunc {
359359 var temp interface {}
360360 if err := decoder .Decode (& temp ); err != nil {
361361 logger .Warn ("Invalid JSON syntax: %v" , err )
362- c .JSON (http .StatusBadRequest , gin. H {
363- "error" : "invalid_input" ,
364- "error_description" : "Request body contains invalid JSON syntax" ,
362+ c .JSON (http .StatusBadRequest , Error {
363+ Error : "invalid_input" ,
364+ ErrorDescription : "Request body contains invalid JSON syntax" ,
365365 })
366366 c .Abort ()
367367 return
@@ -371,9 +371,9 @@ func StrictJSONValidationMiddleware() gin.HandlerFunc {
371371 // If we can read another token, there's extra content
372372 if decoder .More () {
373373 logger .Warn ("JSON contains trailing garbage after valid value" )
374- c .JSON (http .StatusBadRequest , gin. H {
375- "error" : "invalid_input" ,
376- "error_description" : "Request body contains invalid JSON: unexpected content after JSON value" ,
374+ c .JSON (http .StatusBadRequest , Error {
375+ Error : "invalid_input" ,
376+ ErrorDescription : "Request body contains invalid JSON: unexpected content after JSON value" ,
377377 })
378378 c .Abort ()
379379 return
@@ -383,9 +383,9 @@ func StrictJSONValidationMiddleware() gin.HandlerFunc {
383383 remaining , _ := io .ReadAll (decoder .Buffered ())
384384 if len (bytes .TrimSpace (remaining )) > 0 {
385385 logger .Warn ("JSON contains trailing content: %q" , remaining )
386- c .JSON (http .StatusBadRequest , gin. H {
387- "error" : "invalid_input" ,
388- "error_description" : "Request body contains invalid JSON: unexpected content after JSON value" ,
386+ c .JSON (http .StatusBadRequest , Error {
387+ Error : "invalid_input" ,
388+ ErrorDescription : "Request body contains invalid JSON: unexpected content after JSON value" ,
389389 })
390390 c .Abort ()
391391 return
@@ -394,9 +394,9 @@ func StrictJSONValidationMiddleware() gin.HandlerFunc {
394394 // Check for duplicate keys in the JSON object
395395 if err := validateNoDuplicateKeys (bodyBytes ); err != nil {
396396 logger .Warn ("JSON contains duplicate keys: %v" , err )
397- c .JSON (http .StatusBadRequest , gin. H {
398- "error" : "invalid_input" ,
399- "error_description" : err .Error (),
397+ c .JSON (http .StatusBadRequest , Error {
398+ Error : "invalid_input" ,
399+ ErrorDescription : err .Error (),
400400 })
401401 c .Abort ()
402402 return
0 commit comments