pickJSONContent finds the JSON content variant of a response and returns it along with the matched media type (for diagnostic messages when no JSON variant exists). It accepts both "application/json" and vendor variants like "application/vnd.api+json" — anything that declares a JSON payload is fair
(resp *openapi3.Response)
| 245 | // vendor variants like "application/vnd.api+json" — anything that |
| 246 | // declares a JSON payload is fair game. |
| 247 | func pickJSONContent(resp *openapi3.Response) (*openapi3.MediaType, string) { |
| 248 | if resp == nil || resp.Content == nil { |
| 249 | return nil, "" |
| 250 | } |
| 251 | for ct, mt := range resp.Content { |
| 252 | if strings.Contains(strings.ToLower(ct), "json") { |
| 253 | return mt, ct |
| 254 | } |
| 255 | } |
| 256 | // Return first media type for diagnostic purposes only. |
| 257 | for ct := range resp.Content { |
| 258 | return nil, ct |
| 259 | } |
| 260 | return nil, "" |
| 261 | } |
| 262 | |
| 263 | // collectParams merges PathItem-level parameters (shared) with |
| 264 | // Operation-level parameters (operation-specific) and buckets the result |