apigee-127/swagger-tools

Response validation blocks stream

Opened this issue · 3 comments

I wrote an API that streams data from another server to client. The problem is that my API buffers the whole stream to memory until it starts sending it to client. This is of course pretty much wrecks the idea. Then I noticed that if I disable swagger validation for the responses { validateResponse: false }, the block is removed and stream+flow control works as they should.

I am just guessing here, but is it so that swagger response validation does not actually allow anything to be written to client until end() is called?
https://github.com/apigee-127/swagger-tools/blob/master/middleware/swagger-validator.js#L185

Any ideas what to do here? I would hate to disable the response validation for all the APIs, but apparently I cannot disable that per API.

Answering to self: Did not come up with any sane solution so I made an insane hack instead master...kuha-tnx:feature/ignore-resp-validation

Then just in client:

someApiHandler: (req, res) => {
  ...
  res.swaggerIgnoreResponseValidation = true;
  someStream.pipe(res);

+1

@JusbeR Came with same issue lately, instead of forking swagger-validator.js you can do

` app.use((req, res, next) => {

middleware.swaggerValidator({
  validateResponse: req.swagger.apiPath !== {API}
})(req, res, next);

});`