swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Semantic error (path parameter not present in the path) detected in Swagger 2.X but not in OpenAPI 3.X

Open DCollart opened this issue 5 years ago • 1 comments

In short, this file contains a semantic error :

openapi: 3.0.1
info:
  title: Sample API
  version: v1
servers:
  - url: 'api.example.com'
paths:
  '/test/{foo}':
    get:
      parameters:
        - name: foo
          in: path
          required: true
          schema:
            type: string
        - name: bar
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: string

You can find this semantic error by posting it into the swagger editor

Semantic error at paths./test/{foo}.get.parameters.1.name
Path parameter "bar" must have the corresponding {bar} segment in the "/test/{foo}" path
Jump to line 16

But I was not able to find this semantic error. Neither in the swagger-cli or the online tool. According to both the file is valid.

I think it's a regression because the same error in version swagger 2.0 was detected as well :

swagger: "2.0"
info:
  title: Sample API
  version: v1
host: api.example.com
basePath: /v1
schemes:
  - https
paths:
  /test/{foo}:
    get:
      summary: Returns a user by ID.
      parameters:
        - in: path
          name: foo
          required: true
          type: string
        - in: path
          name: bar
          required: true
          type: string
      responses:
        200:
          description: OK

Thank you :-)

DCollart avatar Oct 01 '20 14:10 DCollart

@DCollart I see the reason as: This is so due to no validations applied for OpenAPI v3. https://github.com/APIDevTools/swagger-parser/blob/fa54e0a030c0ca4d1abd090b77ce7d0dbb3205e1/lib/validators/spec.js#L17

jaishirole avatar Aug 09 '21 16:08 jaishirole