owasp-define-error-responses-401
Define a 401 response and a schema for its body. The rule checks the first declared media type for a schema; a response description alone does not pass. A default or wildcard response does not replace the explicit 401 response.
Operations that explicitly disable authentication with security: [] or only anonymous requirements such as security: [{}] are skipped. Other operations are checked, including operations that inherit root security.
Bad example
openapi: "3.1.0"
info:
title: Chicken Nuggets API
version: "1.0"
paths:
/chickenNuggets:
get:
responses:
'200':
description: OK
Good example
openapi: "3.1.0"
info:
title: Chicken Nuggets API
version: "1.0"
paths:
/chickenNuggets:
get:
responses:
'200':
description: OK
'401':
description: Request failed
content:
application/problem+json:
schema:
type: object
properties:
detail:
type: string
How do I fix this violation?
Add the explicit response code and a content media type with a schema that describes the error body.