server-urls-no-trailing-slash

Since 0.12.0 · fixed by --fix · In the rulesets: Recommended at warning, Strict at error, All at error

This rule checks that no URL in the document’s top-level servers, other than /, ends with a slash.

Rule details

Paths start with a slash, and a client builds a request URL by appending the path to the server URL. A server URL that also ends with a slash gives https://api.example.com/v1//pets, which some servers and proxies route differently from /v1/pets, or refuse.

The rule reports Server URL ends with a slash on each such server. A server URL that is only / (the host the document is served from) is not reported. The servers of path items and operations are not checked.

Turn the rule off only for a document you can’t change: a path starts with a slash, so a server URL never needs one at its end.

Examples

Good.

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

Bad.

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

Automatic fixes

--fix removes the trailing slashes. When server-urls also fixes the same URL, one --fix makes one of the two changes, and the next makes the other.

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:
      server-urls-no-trailing-slash: off

Related rules

Was this helpful?