Open nsisodiya opened 7 years ago
Error: Response validation failed: failed schema validation
at throwErrorWithCode (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/swagger-tools/lib/validators.js:121:13)
at Object.module.exports.validateAgainstSchema (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/swagger-tools/lib/validators.js:176:7)
at /Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/swagger-tools/middleware/swagger-validator.js:141:22
at /Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/async/lib/async.js:356:13
at async.forEachOf.async.eachOf (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/async/lib/async.js:233:13)
at _asyncMap (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/async/lib/async.js:355:9)
at Object.map (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/async/lib/async.js:337:20)
at validateValue (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/swagger-tools/middleware/swagger-validator.js:134:11)
at ServerResponse.res.end (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/swagger-tools/middleware/swagger-validator.js:252:9)
at ServerResponse.send (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/express/lib/response.js:211:10)
at ServerResponse.json (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/express/lib/response.js:256:15)
at Model.<anonymous> (/Users/narendrasisodiya/Coding/Billexo/billexo-api/api/controllers/customers.js:12:11)
at bound (domain.js:280:14)
at Model.runBound (domain.js:293:12)
at Model.tryCatcher (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/narendrasisodiya/Coding/Billexo/billexo-api/node_modules/bluebird/js/release/promise.js:512:31)
Also, I get this error log in console. My main query is - "Why I am getting incomplete JSON". because of this, I am finding difficulty in debugging.
Looks like this come from the 'swagger-validator' pipe: https://github.com/apigee-127/swagger-tools/blob/master/middleware/swagger-validator.js#L152-L163, it validates the response JSON against the Response model in your Swagger-definition.
Any update on this?
I am sure that you defined the format of response using for example:
200:
description: "A list of customers"
schema:
$ref: "#/definitions/Customers"
and Customers
should be defined as an array for example:
Customers:
type: "array"
items:
$ref: "#/definitions/Customer"
Customer:
required:
- "_id"
- "name"
properties:
_id:
type: "integer"
description: "The generated unique identifier"
name:
type: "string"
description: "Name of the customer"
description:
type: "string"
description: "Description text"
And take a look at your controller that is responsible for endpoint /customers
.
The format of the data should be the same as you defined.
When there is an error, I get incomplete JSON. Please check following.