apigee-127 / swagger-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
702 stars 373 forks source link

Mock responses for some definitions always return with 200 status #518

Open JeanMarcGoepfert opened 7 years ago

JeanMarcGoepfert commented 7 years ago

Hi, thanks for this project!

I'm running into an issue with swagger router running in mock mode.

I have some definitions that have PUT and POST methods that should return a 204 status according to their definitions, but the mock response comes back with a status of 200.

It looks like this is intentionally done here: https://github.com/apigee-127/swagger-tools/blob/master/middleware/swagger-router.js#L280 where the status will only get set to 204 for requests with a DELETE method. Other requests get set to a default of 200.

I can't find any information about why 204 responses aren't allowed for PUT/POST requests, so is this a case that can be added? I'm happy to submit a PR.

Thanks!

whitlockjc commented 7 years ago

This is just how the mock functionality was written. The mocking support was just an initial pass with no input from anyone else. We could potentially just use some convention for identifying which response to use instead of hard coding them.

JeanMarcGoepfert commented 7 years ago

How about just returning the first 2XX status? I've done that here which seems to work. If you're ok with that approach I'm happy to make a PR with some tests/updated docs.