Swagger - 不是好友的错误

时间:2018-06-07 19:20:22

标签: swagger swagger-editor swagger-codegen

在我的swagger API文档中,我有route / pet / {petId},其中petId必须是数字。

Usign Swagger编辑器我将它导出到NodeJS服务器并启动了服务器。 当我要求/ pet / 1时,每个标志都有效。 当我尝试请求/ pet / djnsdfnsd时,它会播出这个错误:

Error: Parameter (petId) is not a valid integer: a
at throwErrorWithCode (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\lib\validators.js:121:13)
at validateTypeAndFormat (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\lib\validators.js:538:7)
at Object.module.exports.validateSchemaConstraints (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\lib\validators.js:630:7)
at validateValue (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\middleware\swagger-validator.js:119:16)
at C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\middleware\swagger-validator.js:343:21
at C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\async\lib\async.js:356:13
at async.forEachOf.async.eachOf (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\async\lib\async.js:233:13)
at _asyncMap (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\async\lib\async.js:355:9)
at Object.map (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\async\lib\async.js:337:20)
at swaggerValidator (C:\Users\Meldiron\Desktop\nodejs-server-server\node_modules\swagger-tools\middleware\swagger-validator.js:323:15)

在控制台中发生同样的事情。 有没有办法发送错误的JSON对象而不是抛出错误?

0 个答案:

没有答案