path-keys-no-trailing-slash
- Applies to
paths- Selects
$.paths- Function
pattern- Specs
- OpenAPI 2.0OpenAPI 3.0OpenAPI 3.1OpenAPI 3.2
- Message
Path must not end with slash.
Use it
This rule ships with OpenLint in spectral:oas. Extending the ruleset turns it on:
extends: spectral:oas
rules:
path-keys-no-trailing-slash: warn # or off, or another severity
Definition
As defined in @openlint/openlint-rulesets. Functions show by name.
path-keys-no-trailing-slash:
message: Path must not end with slash.
recommended: true
given: $.paths
then:
field: '@key'
function: pattern
functionOptions:
notMatch: .+\/$
About this rule
Keep trailing slashes off of paths, as it can cause some confusion. Some web tooling (like mock servers, real servers, code generators, application frameworks, etc.) will treat example.com/foo and example.com/foo/ as the same thing, but other tooling will not. Avoid any confusion by just documenting them without the slash, and maybe some tooling will let people shove a / on there when they’re using it, or maybe not, but at least the docs are suggesting how it should be done properly.