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

Semantic error at paths is not detected by validator

Open lenchvolodymyr opened this issue 4 years ago • 6 comments

The swagger-parser doesn't validate semantic error when path parameter has invalid type.

This schema is invalid according to swagger-editor

openapi: 3.0.3
info:
  title: ''
  version: '1.0'
paths:
  '/items/{id}':
    get:
      parameters:
        - name: id
          in: query
          required: true
          schema:
            type: object
            nullable: false
      responses:
        '200':
          description: ''
components: {}

It shows the following error:

Semantic error at paths./items/{id}
Declared path parameter "id" needs to be defined as a path parameter at either the path or operation level

But swagger-parser doesn't throw any errors when validating the schema.

const SwaggerParser = require('swagger-parser');

SwaggerParser.validate(script, {}, (err, api) => {...});

lenchvolodymyr avatar Jul 01 '21 14:07 lenchvolodymyr

@lenchvolodymyr 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 14:08 jaishirole

@jaishirole thanks for the response, I see now. I would keep the issue open until it's implemented for OpenAPI

lenchvolodymyr avatar Aug 09 '21 14:08 lenchvolodymyr

@lenchvolodymyr Sure.

jaishirole avatar Aug 09 '21 15:08 jaishirole

@lenchvolodymyr This PR hopefully shall address this issue for OpenAPI v3: https://github.com/APIDevTools/swagger-parser/pull/179/files

jaishirole avatar Aug 10 '21 19:08 jaishirole

@jaishirole nice, hope it will be merged soon. Thank you!

lenchvolodymyr avatar Aug 11 '21 06:08 lenchvolodymyr

Any news on this?

jurgen-kammcs avatar Aug 02 '23 22:08 jurgen-kammcs