SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
182 stars 33 forks source link

support ktor.deployment.rootPath #97

Closed mcxinyu closed 6 months ago

mcxinyu commented 6 months ago

Add ktor.deployment.rootPath to paths in openapi.json.

mcxinyu commented 6 months ago

I have no good way to get io.ktor.server.config.ApplicationConfig in the io.github.smiley4.ktorswaggerui.builder.openapi.PathsBuilder class, so I added it in the io.github.smiley4.ktorswaggerui.routing.ControllerUtils utils class A field for storing it, maybe you can have a good idea?

SMILEY4 commented 6 months ago

Hi, thanks for the pr. Could you quickly explain why this change is necessary, i.e. which problem this is trying to solve. I think I'm overlooking something here :)

mcxinyu commented 6 months ago

RootPath is A servlet context path.

It is the same concept as SwaggerUIDsl.kt#L33, but ktor will add this path to the front.

It is similar to the path of a reverse proxy, but it is implemented internally within ktor.

e.g.

in route.kt

get("/test") {}

in application.conf

ktor {
  deployment {
    rootPath = "xxxApi"
  }
}

So the path of this api should be '/xxxApi/test'`.

mcxinyu commented 6 months ago

The problem I solved here is that the user configures rootPath, but the generated openapi.json did not include the path, causing 404 errors in the access interface.

SMILEY4 commented 6 months ago

Ah, i see. Looks good then 👍 Thank you!