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 configuration problem #170

Open
pezra opened this issue Jan 3, 2025 · 1 comment
Open

Swagger UI configuration problem #170

pezra opened this issue Jan 3, 2025 · 1 comment

Comments

@pezra
Copy link

pezra commented Jan 3, 2025

I'm getting a 404 when I try to access the swagger UI. The 404 response comes from the swaggerUI routing because it's body is different from the 404s from my application. The openapi JSON generation is working correctly. My config is

     routing {
        route("/account/v2/api.json") {
            openApiSpec()
        }
        route("/account/v2/swagger") {
            swaggerUI("/account/v2/api.json")
        }    
    }

when I visit accounts/v2/swagger in my browser, I get a 404 with the body index.html could not be found. Same thing using cUrl

curl http://localhost:8081/account/v2/swagger -vL
> GET /account/v2/swagger HTTP/1.1
...
< HTTP/1.1 302 Found
< Location: /account/v2/swagger/index.html
...
> GET /account/v2/swagger/index.html HTTP/1.1
...
< HTTP/1.1 404 Not Found
...
index.html could not be found%

Any pointers on how to correct this?

@SMILEY4
Copy link
Owner

SMILEY4 commented Jan 5, 2025

Hi @pezra

strange. Your routes look fine and I'm not sure what else could affect this.

I did a quick test with this application:

fun main() {
    embeddedServer(Netty, port = 8081, host = "localhost", module = Application::myModule).start(wait = true)
}

private fun Application.myModule() {
    install(SwaggerUI)
    routing {
        route("/account/v2/api.json") {
            openApiSpec()
        }
        route("/account/v2/swagger") {
            swaggerUI("/account/v2/api.json")
        }
        get("test", {
            description = "A test route"
        }) {
            call.respondText("test response")
        }
    }
}

This works in my browser (both with and without /index.html) and got this output from curl:

~ » curl http://localhost:8081/account/v2/swagger -vL

> GET /account/v2/swagger HTTP/1.1
...
< HTTP/1.1 302 Found
< Location: /account/v2/swagger/index.html
...
* Issue another request to this URL: 'http://localhost:8081/account/v2/swagger/index.html'
...
> GET /account/v2/swagger/index.html HTTP/1.1
...
< HTTP/1.1 200 OK
< Content-Length: 734
< Content-Type: text/html
...

Does only the redirect result in a 404 or also when you access the /index.html directly?
Do you have a rootPath or anything else configured for ktor that could influence that?

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

2 participants