swagger-express-middleware
swagger-express-middleware copied to clipboard
Response body validation of mocks
It appears as though I can set my mocks to be any data structure, and the response will be served without validating against the swagger file's response schema for the path.
For example, if my /users/:id
endpoint had the following response schema:
{
title: 'User',
description: 'User description.',
type: 'object',
properties: {
userId: {
description: 'account id',
type: number
}
},
required: ['userId'],
additionalProperties: false
};
I can still add the following mocks for the path, and they are served regardless of the fact that the data structure is missing userId
, and has additional properties:
let myDB = new MemoryDataStore()
let invalidResponse = { foo: "bar" };
myDB.save(new Resource('/users/1', invalidResponse))
To me, enforcing accurate responses is one of the most important potential value-adds, so this feels like a gap to me. Thoughts on adding a json-validator around the mock middleware, or perhaps I'm missing something?
Sorry for the delayed response. I've been away on holiday for a few weeks.
This feature is definitely on the to-do list. It probably won't be in version 1.0, but hopefully will come soon thereafter. It's little bit tricky, because Express only has request middleware. It doesn't really have a concept of "response middleware", so intercepting the response and validating it against the Swagger response schema isn't totally straightforward. There are a couple ways that I can think of to do it, but they both have pros and cons that will need to be considered.
+1 - this feature would be great! have not seen a lot of activity on this project in a while though. Has it been abandoned/superseded?
There's a lot of work going on behind the scenes. Doing some big refactoring of the underlying projects that Swagger Express Middleware relies on. I have a day job too though, so my time is limited to nights and weekends, but I assure you that I'm just as eager for new features.