redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Path parameter isn't defined

Open adamaltman opened this issue 5 years ago • 3 comments
trafficstars

Describe the bug If a path has a named placeholder but doesn't have a path parameter, then we should show the problem.

Each template expression in the path MUST correspond to a path parameter that is included in the Path Item itself and/or in each of the Path Item's Operations.

To Reproduce Steps to reproduce the behavior:

  1. Given this .redocly.yaml file (just the recommended rules)
  2. Contact Adam or see a sample below.
  3. Run this command with these arguments... openapi lint
  4. See no error

Expected behavior I expect to see this error: https://redoc.ly/docs/cli/built-in-rules/#path-parameters-defined

Logs

validating /home/adam/Downloads/2020-09-23-13-03-openapi-od_3p8p9x.yaml...
/home/adam/Downloads/2020-09-23-13-03-openapi-od_3p8p9x.yaml: validated in in 86ms

Woohoo! Your OpenAPI definition is valid. 🎉

OpenAPI definition

This is an excerpt.

The one with the path template was defined first:

paths:
  /something/{id}:
   parameters:
     - name: foo
       in: header
       required: true
       schema:
         type: string
  /something:
# ...

openapi-cli Version(s) 1.0.0-beta.14

Node.js Version(s) v12.6.0

Additional context

Contact Adam if you need a full OpenAPI definition.

adamaltman avatar Sep 23 '20 15:09 adamaltman

As it turned out the parameter actually was defined on the path item level. But that wasn't noticed when submitting the issue as the parameters block was under the methods definitions.

andriyl avatar Sep 24 '20 13:09 andriyl

Hi Redocly team!

I was just about to create a new ticket, but I think it makes sense to report under this one. Basically, the path-params-defined is not flagging an error in a scenario when a templated path has two (or more) operations assigned, and only one of them defines the path parameter.

A minimal example of a failing openapi schema looks like this:

openapi: 3.0.0
info:
  title: Test
  version: 0.0.1
servers:
  - url: https://localhost:8080

paths:
  /items/{itemId}:
    get:
      summary: Get Items
      parameters:
        - name: itemId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
    options:
      summary: CORS support
      responses:
        '200':
          description: OK

Redocly CLI linting does not report any errors, however, it's violating the spec in terms of

Each template expression in the path MUST correspond to a path parameter that is included in the Path Item itself and/or in each of the Path Item's Operations.

mkucharek avatar Jul 26 '22 14:07 mkucharek

Hi @mkucharek!

Thank you for noticing this.

tatomyr avatar Aug 02 '22 09:08 tatomyr