spectral:asyncapi error on by default

asyncapi-server-security

Server have to reference a defined security schemes.

Applies to
security
Selects
$.servers.*.security.*
Function
asyncApiSecurity
Specs
AsyncAPI 2.x
Message
{{error}}

Use it

This rule ships with OpenLint in spectral:asyncapi. Extending the ruleset turns it on:

extends: spectral:asyncapi
rules:
  asyncapi-server-security: error   # or off, or another severity

Definition

As defined in @openlint/openlint-rulesets. Functions show by name.

asyncapi-server-security:
  description: Server have to reference a defined security schemes.
  message: '{{error}}'
  severity: error
  recommended: true
  formats:
    - AsyncAPI 2.x
  given: $.servers.*.security.*
  then:
    function: asyncApiSecurity
    functionOptions:
      objectType: Server

About this rule

Server security values must match a scheme defined in the components.securitySchemes object. It also checks if there are oauth2 scopes that have been defined for the given security.

Good Example

asyncapi: 2.0.0
servers:
  production:
    url: test.mosquitto.org
    security:
      - petstore_auth: []
components:
  securitySchemes:
    petstore_auth: ...

Bad Example

asyncapi: 2.0.0
servers:
  production:
    url: test.mosquitto.org
    security:
      - not_defined: []
components:
  securitySchemes:
    petstore_auth: ...

Sources