-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
As an editor, I want to know when path parameters are not properly defined.
Swagger Editor currently has a validation for path templates that are missing path parameter definitions (e.g. /foo/{bar} without the bar parameter defined). It would be great to also check for the opposite situation - when a path parameter is defined but not included in the actual path string.
Definitions containing path parameters that are not included in the path string are invalid according to the OpenAPI Specification:
If
inis"path", thenamefield MUST correspond to the associated path segment from the path field in the Paths Object.
Swagger/OpenAPI definition
In the examples below, the /foo path contains 4 path parameter definitions none of which are actually used by the /foo path.
OAS2:
swagger: '2.0'
info:
title: Unused path parameters
version: 1.0.0
paths:
/foo:
parameters:
- name: param1
in: path
required: true
type: string
- $ref: '#/parameters/param2'
get:
parameters:
- name: param3
in: path
required: true
type: string
- $ref: '#/parameters/param4'
responses:
'200':
description: OK
parameters:
param2:
name: param2
in: path
required: true
type: string
param4:
name: param4
in: path
required: true
type: stringOAS3:
openapi: 3.0.2
info:
title: Unused path parameters
version: 1.0.0
paths:
/foo:
parameters:
- name: param1
in: path
required: true
schema:
type: string
- $ref: '#/components/parameters/param2'
get:
parameters:
- name: param3
in: path
required: true
schema:
type: string
- $ref: '#/components/parameters/param4'
responses:
'200':
description: OK
components:
parameters:
param2:
name: param2
in: path
required: true
schema:
type: string
param4:
name: param4
in: path
required: true
schema:
type: stringIs your feature request related to a problem?
Swagger Editor should ideally report as many syntax issues as possible to help the users write valid OpenAPI definitions. This particular validation would help avoid swagger-api/swagger-ui/issues/5447.
Describe the solution you'd like
Each path parameter in the examples above should trigger an error that says this parameter is unused.
Possible wording:
Path parameter "param1" must have the corresponding {param1} segment in the "/foo" path
Path parameter "param1" is defined but there is no {param1} segment in the "/foo" path
or similar. Suggestions are welcome!