swagger-express-middleware
swagger-express-middleware copied to clipboard
api-docs doesn't seem to work
I was having trouble getting api-docs to work on my prototype, so I tried it out.
With a fresh clone, all tests pass, then I run npm start.
When I try to access the two Swagger API links ( http://localhost:8000/api-docs/PetStore.yaml and http://localhost:8000/api-docs ) I get 404 errors.
Debug output:
~/projects/swagger-express-middleware master npm start
> [email protected] start /Users/aschamp/projects/swagger-express-middleware
> cd samples && node sample2.js
The Swagger Pet Store is now running at http://localhost:8000
swagger:middleware GET / matches Swagger path / +0ms
swagger:middleware Validating Accept header (text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8) +8ms
swagger:middleware Validating Content-Length header (NaN) +4ms
swagger:middleware Using default (200) response for GET / +1ms
swagger:middleware Running the queryResource mock +1ms
swagger:middleware GET / does not exist, but the response schema defines a fallback value. So, using the fallback value +1ms
swagger:middleware Setting 0 response headers... +0ms
swagger:middleware Using text/html MIME type, which is allowed by the Swagger API +10ms
swagger:middleware Sending raw buffer data +0ms
WARNING! Unable to find a Swagger path that matches "/favicon.ico"
swagger:middleware Client requested path "/favicon.ico", which is not defined in the Swagger API. Returning HTTP 404 (Not Found) +803ms
WARNING! Unable to find a Swagger path that matches "/api-docs"
swagger:middleware Client requested path "/api-docs", which is not defined in the Swagger API. Returning HTTP 404 (Not Found) +5s
WARNING! Unable to find a Swagger path that matches "/api-docs/PetStore.yaml"
swagger:middleware Client requested path "/api-docs/PetStore.yaml", which is not defined in the Swagger API. Returning HTTP 404 (Not Found) +7s
WARNING! Unable to find a Swagger path that matches "/api-docs/PetStore.yaml"
swagger:middleware Client requested path "/api-docs/PetStore.yaml", which is not defined in the Swagger API. Returning HTTP 404 (Not Found) +2m
WARNING! Unable to find a Swagger path that matches "/api-docs"
swagger:middleware Client requested path "/api-docs", which is not defined in the Swagger API. Returning HTTP 404 (Not Found) +723ms
Ah, looking at the example that actually gets run, the JSON is to be served from swagger/api, and the PetStore.yaml is configured not to be served at all. I'll take a stab at cleaning this up in a pull request.
So my problem was I put the files() middleware at the end, after everything else. putting it right after metadata(), like in the example, made it start to work.
Upon further testing, files() works as long as it is installed before validateRequest(), but I have not done the digging to find out why.
If you understand why this is the case, and can update the documentation, it will help the next poor sucker that comes along.