oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
94 stars 53 forks source link

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

Open ghost opened 2 years ago

ghost commented 2 years ago

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 commented 2 years ago

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" >
ghost commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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" >