Cody2333 / koa-swagger-decorator

using decorator to automatically generate swagger doc for koa-router
348 stars 81 forks source link

Support for custom swagger-json redirect #142

Open kylemillar608 opened 2 years ago

kylemillar608 commented 2 years ago

I am working on a project with a router that exposes the endpoints - "/v1/swagger-html" and "/v1/swagger-json". Running the app locally, the redirect to "swagger-json" works fine.

Issue: When not on local machine, my app sits behind an API gateway. The url that I use to hit the "/v1/swagger-html" endpoint not on localhost is different - "example.com/dev-v1/swagger-html". Once the API gateway receives the request, it is mapped to "/v1/swagger-html" on the backend. This works, however the redirect to the swagger-json endpoint is broken. It redirects to the endpoint - "example.com/v1/swagger-json", which does not exist.

What I have tried:

  1. Changing the swaggerJsonEndpoint property to be dependent on environment. On localhost, it does not change ("/v1/swagger-json"). When deployed to dev environment, it will be "/dev-v1/swagger-json". This fixes the issue above, but leads to a new issue - the request gets past the Api gateway and the Api gateway still maps the url to "/v1/swagger-json", but now the app is exposing "/dev-v1/swagger-json". I get a 404 from the app.
  2. Adding prefix property - /dev-v1/. Again the html request works, but the redirect breaks. This time because the redirect goes to "/dev-v1/v1/swagger-json" which, again, does not exist on the Api gateway.

I need to be able to have swaggerJsonEndpoint: "/v1/swagger-json" on the app side. But, I need the redirect to go to "/dev-v1/swagger-json".