APIDevTools / swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser/validator
https://apitools.dev/swagger-parser
MIT License
1.09k stars 154 forks source link

Missing semantic error for parameter schema of type `"array"` #164

Closed schloerke closed 3 years ago

schloerke commented 3 years ago

When validating an API on https://editor.swagger.io/, the editor presents a valid error.

Semantic error at paths./test/{values}.get.parameters.0.schema Schemas with 'type: array', require a sibling 'items: ' field

Screen Shot 2021-04-21 at 10 50 10 AM


When running the same code through swagger-parser, there is no error.

Reprex:

const fs = require("fs");
const SwaggerParser = require("@apidevtools/swagger-parser");

fs.writeFileSync("openapi.yaml", 
`
servers:
  - url: ''
openapi: 3.0.0
info:
  version: 0.1.0
  title: Test
paths:
  '/test/{values}':
    get:
      parameters:
        - in: path
          required: true
          name: values
          schema:
            type: array
      responses:
        '200':
          description: OK
`)

SwaggerParser.validate("openapi.yaml", (err, api) => {
  if (err) {
    console.error(err);
  }
  else {
    console.log("API name: %s, Version: %s", api.info.title, api.info.version);
  }
});

//> Promise { <pending> }
//> API name: Test, Version: 0.1.0

(No error given, api is presented as valid.)


(I hope I am not missing something obvious...)

Related: https://github.com/rstudio/plumber/issues/796 cc @karawoo

jaishirole commented 3 years ago

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

schloerke commented 3 years ago

Thank you @jaishirole . This is too bad. Closing the issue