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

"/swagger/ui/" doesn't work #54

Open
ghost opened this issue Dec 13, 2021 · 4 comments
Open

"/swagger/ui/" doesn't work #54

ghost opened this issue Dec 13, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 13, 2021

When running a service, visiting the "localhost:{port}/swagger/ui/" url doesn't work, but the "localhost:{port}/swagger/ui" does. Is there any way to allow the extra '/' to be ignored or the behaviour to be the same?

I tried adding a new ENDPOINT("GET", "/swagger/ui/", getUIRoot2) , but that didn't seem to work.

@lganzzzo
Copy link
Member

Hello @qvfh83 ,

You should be able to fix it by modifying /res/index.html file.
Both /swagger/ui and /swagger/ui/ endpoints return index.html file.
The problem is how other resource paths are defined in the index.html.

This is how swagger-ui.css is referenced in the index.html:

<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
  • When you use /swagger/ui endpoint its path is resolved as /swagger/swagger-ui.css.
  • When you use /swagger/ui/ endpoint its path is resolved as /swagger/ui/swagger-ui.css.

@ghost
Copy link
Author

ghost commented Dec 14, 2021

Thanks for the quick response @lganzzzo!

Hmm, I see - the files are being serviced out of the /swagger/{filename} endpoint added in Controller.hpp and thus are not available via a non-existent swagger/ui/{filename} endpoint. I suppose adding a duplicate endpoint for "GET", "/swagger/ui/{filename}" would solve this?

I'm not sure I quite understand the fix on the index.html side (don't come from that background so bear with me 😅) - I'd like to support paths both with and without the /.

I also suppose similar steps could be taken if I also want to support the localhost:{PORT}/swagger and localhost:{PORT}/swagger/ paths.

@lganzzzo
Copy link
Member

I'm not sure I quite understand the fix on the index.html side (don't come from that background so bear with me 😅) - I'd like to support paths both with and without the /.

If you change paths in the index.html to use full paths it should fix this issue.

<!-- change this -->
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >

<!-- to this: -->
<link rel="stylesheet" type="text/css" href="http://localhost:8000/swagger/swagger-ui.css" >

@ghost
Copy link
Author

ghost commented Dec 14, 2021

I see - I just tested this and it works if I use the below (that way we can still use any generic port). Not sure if you think this is a good change to make in the package itself? I could open up an MR if so.

<link rel="stylesheet" type="text/css" href="/swagger/swagger-ui.css" >

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

1 participant