-
Notifications
You must be signed in to change notification settings - Fork 22
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
Serve swagger-ui from WebJar instead of unpkg.com #193
Comments
Hi... you can do this. There is a module called I would recommend looking at that implementation and porting the code necessary over to your own application. Ultimately, the Swagger and ReDoc routes that Kompendium provides are mostly for ease of use. Any custom requirements that you have would fall under the requirements for your application, and can be solved on your end, due to the decoupled nature of the library. I'm going to close this as I don't think there is any work to do here. |
On second thought, the OAuth use case is compelling... I'll leave this open. I'm not going to be working on this personally, but if you'd like to handle the necessary work to get the swagger web jar module fully functional, then I'd welcome a PR :) |
Can you add some details about:
|
This is one #128 There was another one that I'm blanking on as well. If you can get a PR running that leverages webjars and points to the correct openapi spec on launch, then I think that should be enough to consider the webjar module functional. Then we can file any other bugs that users run into. |
This shouldn't be a problem, but I believe there must be also a problem with context path if project launched like this: I'll try to adopt my code but I have only implementation for OAuth authentication, there are multiple others will remain. |
I was able to launch Swagger-UI with OAuth using WebJar with kompendium and it works well for me. This will require to update this part of code in core: var openApiJson: Routing.(OpenApiSpec) -> Unit = { spec ->
route("/openapi.json") {
get {
call.respond(HttpStatusCode.OK, spec)
}
}
} If you agree with that I'll do pull request. By the way is there any channel for this project? I like it and would love to contribute more. |
Where would this live?
You can :) Would look something like this install(Kompendium) {
spec = Util.baseSpec
openApiJson = { spec ->
route("/testing/testing/123/cool-doc.json") {
get {
call.respond(HttpStatusCode.OK, spec)
}
}
}
}
// Configures the routes for our API
routing {
// This adds ReDoc support at the `/docs` endpoint.
// By default, it will point at the `/openapi.json` created by Kompendium
redoc(pageTitle = "Simple API Docs", specUrl = "/testing/testing/123/cool-doc.json")
Thanks! Any PRs are welcome :) Even just submitting these issues is super useful. There isn't any kind of channel for this project, since it's mostly just me sitting alone in my castle 😂 Right now, the best thing to do is probably open a discussion for things that aren't directly related to an issue. If this project grows to be more people, maybe we can start a Gitter or something for it, that would be cool :) but I think we'll save that for down the line. |
Is your feature request related to a problem? Please describe.
I just can't imagine how current implementation can work with OAuth authentication for REST calls.
To use OAuth there is must be oauth2-redirect.html specified on the OAuth server side and it'll redirect to this URL after successful authentication. Currently this url is located on external unpkg.com site. So there is no way to redirect there and complete authentication flow executed by swagger-ui.
Moreover many projects just don't want to serve anything from 3-rd party mirrors.
Describe the solution you'd like
The better approach would be to instal KTor WebJars extension and serve all static like JS & CSS from there .
Additionally there must be:
oauth2RedirectUrl
specified, generally it is done inswagger-config.json
and
clientId
&clientSecretId
should be provided like described here (see the bottom of the page: "initOAuth"):https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/
Describe alternatives you've considered
Don't see any good alternatives, because AFAIK all external bundles just can't work well with external authentication.
Additional context
Having bundled Swagger-UI via WebJar and custom extended implementation for
index.html
&swagger-config.json
there will be a better tuning possibilities for Swagger.Moreover there is no any need to write full implementation for index.html, you can just replace dynamic part like this:
this::class.java.getResource("/META-INF/resources/webjars/swagger-ui/$swaggerVersion/index.html")?.readText()?.replaceFirst("window.ui = ui", "YOUR SCRIPT CODE that ends with replaced string")
The text was updated successfully, but these errors were encountered: