swagger-tools
swagger-tools copied to clipboard
Swagger Metadata Does Not Parse Body If A Separate Body Parser Is Set Up But Skips Parsing
Hello. I just ran into an interesting issue with the library.
We want to parse some of our request bodies using the raw parser, so we added a separate body parser middleware before the Swagger Metadata middleware, based on this comment:
https://github.com/apigee-127/swagger-tools/issues/454
We have this parser only configured for application/octet-stream requests. However, I discovered today that when a request with a different type comes in (e.g. application/json), even though no parsing is performed, req.body is set to {}.
https://github.com/expressjs/body-parser/blob/master/lib/types/raw.js#L62
When this request is picked up by Swagger Metadata, it sees that req.body is defined, and therefore skips its own parsing. This means that body parameters do not get set, which then caused Swagger Validator to fail for missing a required parameter.
Could I ask you to look into this issue?
Thank you!
I think that swagger-tools is doing the right thing and that the linked issue is the real issue. It seems that once that's fixed, swagger-tools should benefit from the fix. I'll give it some thought to see if we can come up with an interim fix.