bug-hunters / oas3-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
27 stars 50 forks source link

Validating the response not compatible with OAS 3.0+ #9

Open FMCorz opened 5 years ago

FMCorz commented 5 years ago

Validating the response value does not work as expected, the schema is not read from responses.[code].content.[media type].schema. Leading to the following error:

  swagger-tools:middleware:validator   Response validation: +2ms
  swagger-tools:middleware:validator     Response code: 200 +0ms
  swagger-tools:middleware:validator     Validation: failed +1ms
  swagger-tools:middleware:validator   Reason: Value at index 0 is not a valid void: [object Object] +0ms
  swagger-tools:middleware:validator   Stack: +8ms
  swagger-tools:middleware:validator       at throwErrorWithCode (oas3-tools/lib/validators.js:116:13) +0ms
  swagger-tools:middleware:validator       at oas3-tools/lib/validators.js:489:9 +0ms
  swagger-tools:middleware:validator       at arrayEach (lodash/lodash.js:516:11) +0ms
  swagger-tools:middleware:validator       at Function.forEach (lodash/lodash.js:9344:14) +0ms
  swagger-tools:middleware:validator       at validateTypeAndFormat (oas3-tools/lib/validators.js:487:7) +0ms
  swagger-tools:middleware:validator       at Object.module.exports.validateSchemaConstraints (oas3-tools/lib/validators.js:643:7) +0ms
  swagger-tools:middleware:validator       at validateValue (oas3-tools/middleware/swagger-validator.js:130:16) +0ms
  swagger-tools:middleware:validator       at ServerResponse.res.end (oas3-tools/middleware/swagger-validator.js:302:9) +0ms
  swagger-tools:middleware:validator       at exports.listPets (snip/controllers/pets.ts:5:7) +0ms
  swagger-tools:middleware:validator       at swaggerRouter (oas3-tools/middleware/swagger-router.js:388:20) +0ms
  connect:dispatcher <anonymous>  : /pets +11ms

I used the following spec, but I had to add to update the version to 3.0.1 or nothing happened (the server never started), and add the x-swagger-router-controller.