operation-security-defined
Since 0.0.1 · In the rulesets: Recommended at warning, Strict at warning, All at error
This rule checks that every operation has security requirements, its own or the document’s.
Rule details
The security requirements tell a client how to authenticate, and generated clients, mocks and the validating proxy what to send and check. An operation with none is public as far as every tool is concerned, which is rarely what the server does.
The rule reports Security requirement is not defined on an operation without security when the
document has no top-level security either. An operation that resets the document’s requirements
with security: [] is taken as meant public and is not reported. Turn the rule off for an API
that restricts nothing.
Examples
Good. The operation inherits the document’s requirement.
paths:
/users:
get:
responses:
"200":
description: A page of users.
security:
- api_key: []
components:
securitySchemes:
api_key:
type: apiKey
in: header
name: X-Api-Key
Good. The operation has a requirement of its own.
paths:
/users:
get:
security:
- api_key: []
responses:
"200":
description: A page of users.
components:
securitySchemes:
api_key:
type: apiKey
in: header
name: X-Api-Key
Bad. Neither the document nor the operation says how to authenticate.
paths:
/users:
get:
responses:
"200":
description: A page of users.
Turn it off or change its severity
In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.rules has the details.
commands:
lint:
rules:
operation-security-defined: off