Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Swagger UI using a Flag or Config #218

Open
mangalakader opened this issue Jan 1, 2019 · 3 comments
Open

Disable Swagger UI using a Flag or Config #218

mangalakader opened this issue Jan 1, 2019 · 3 comments

Comments

@mangalakader
Copy link

Hi @mbuhot ,

I'm currently searching for an option to disable or hide the swagger endpoint in production code, right now I'm using a dummy router like PhoenixSwagger.Plug.SwaggerUI to just forward based on the env flag. Is this the correct approach or am I missing something?

Note: If that's the correct approach, I can create a PR to implement it by default in the library.

Thanks!

@rarguelloF
Copy link

We are doing the same in our projects, so I would vote for adding this feature 👍 .

@mangalakader are you able to enable/disable the swagger UI route with an env variable at runtime instead of at compile time? If so, how are you doing it?

Thanks in advance!

@mbuhot
Copy link
Contributor

mbuhot commented Jan 23, 2019

@rarguelloF I would suggest to make a module plug that checks an environment variable and halts the Conn with a 404 response if the variable is false. You can then put this plug in the pipeline that runs before forwarding to the swagger-ui plug.

Such a module would be generally useful even outside of phoenix_swagger, so maybe it could be a separate package?

@rarguelloF
Copy link

rarguelloF commented Jan 26, 2019

@mbuhot I personally think it would very useful to add a flag (enabled: true/false) with that functionality into PhoenixSwagger.Plug.SwaggerUI since I think it's a pretty common pattern (e.g. you want to enable swagger docs in staging but not in production), however it's your call.

In case you agree with adding this functionality, I would be open to open a PR, so please let me know what you think.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants