khrt / Raisin

Raisin - a REST API micro framework for Perl 🐫 🐪
62 stars 31 forks source link

Fix swagger route #61

Closed mschout closed 5 years ago

mschout commented 5 years ago

We discovered that the route to fetch the Swagger for the API broke in commit c06323360c13fecfdb09b4575aa19de0d496b91c. What this looks like is the first request for the swagger returns a 404 Not Found, and this ends up getting cached in Raisin. You can see this for yourself using the example REST app. E.g.:

plackup ./examples/sample-app/script/restapp.psgi

Then try to fetch the swagger using /api/swagger:

$ http --json http://localhost:5000/api/swagger
HTTP/1.0 404 Not Found
...

Note that you can request it at a different URI to avoid hitting the cache and it resolves with the second request:

$ http --json http://localhost:5000/api/swagger.json 
HTTP/1.0 200 OK
Content-Length: 8005
Content-Type: application/json
...

This PR avoids the problem by not caching the result if no routes match the request.

khrt commented 5 years ago

Thanks for the contribution! It's going to be on CPAN in a few minutes.