spectral:oas warn on by default

oas3-server-trailing-slash

Server URL must not have trailing slash.

Applies to
url
Selects
$.servers[*].url
Function
pattern
Specs
OpenAPI 3.0OpenAPI 3.1OpenAPI 3.2

Use it

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

extends: spectral:oas
rules:
  oas3-server-trailing-slash: warn   # or off, or another severity

Definition

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

oas3-server-trailing-slash:
  description: Server URL must not have trailing slash.
  recommended: true
  formats:
    - OpenAPI 3.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 paths, and you can get awkward URLs like https://example.com/api//pets. Best to just strip them off yourself.

Good Example

servers:
  - url: https://example.com
  - url: https://example.com/api

Bad Example

servers:
  - url: https://example.com/
  - url: https://example.com/api/

Sources