spectral:asyncapi warn on by default

asyncapi-server-no-trailing-slash

Server URL must not end with slash.

Applies to
url
Selects
$.servers[*].url
Function
pattern
Specs
AsyncAPI 2.x

Use it

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

extends: spectral:asyncapi
rules:
  asyncapi-server-no-trailing-slash: warn   # or off, or another severity

Definition

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

asyncapi-server-no-trailing-slash:
  description: Server URL must not end with slash.
  recommended: true
  formats:
    - AsyncAPI 2.x
  given: '$.servers[*].url'
  then:
    function: pattern
    functionOptions:
      notMatch: /$

About this rule

Server URL should not have a trailing slash.

Some tooling forgets to strip trailing slashes off when it’s joining the servers.url with channels, and you can get awkward URLs like mqtt://example.com/broker//pets. Best to just strip them off yourself.

Good Example

servers:
  - url: mqtt://example.com
  - url: mqtt://example.com/broker

Bad Example

servers:
  - url: mqtt://example.com/
  - url: mqtt://example.com/broker/

Sources