-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add "root-path" to swagger-ui #44981
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
09546c7
840057e
067834f
d043978
8ebcae6
c698015
a6a817e
4005c90
2e3e4b5
251bef9
7317647
c87627f
89cc368
4081018
43af23e
44970a3
b7c8825
bc6018d
0d7353b
c3e7ab7
b4b0af7
9a1b1b1
6c75549
083be9b
0ff0029
614984c
ddc6831
5ef855b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,9 @@ public void getSwaggerUiFinalDestination( | |
| } | ||
|
|
||
| String openApiPath = nonApplicationRootPathBuildItem.resolvePath(openapi.path); | ||
| if (swaggerUiConfig.locationPath.isPresent()) { | ||
| openApiPath = swaggerUiConfig.locationPath.get() + openApiPath; | ||
|
||
| } | ||
|
|
||
| String swaggerUiPath = nonApplicationRootPathBuildItem.resolvePath(swaggerUiConfig.path); | ||
| ThemeHref theme = swaggerUiConfig.theme.orElse(ThemeHref.feeling_blue); | ||
|
|
@@ -379,6 +382,12 @@ private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, Swagg | |
| if (swaggerUiConfig.queryConfigEnabled) { | ||
| options.put(Option.queryConfigEnabled, "true"); | ||
| } | ||
| if (swaggerUiConfig.locationPath.isPresent()) { | ||
| var locationPath = swaggerUiConfig.locationPath.get(); | ||
| addLocationPath(locationPath, Option.selfHref, options); | ||
| addLocationPath(locationPath, Option.backHref, options); | ||
| addLocationPath(locationPath, Option.oauth2RedirectUrl, options); | ||
| } | ||
|
Comment on lines
+421
to
+426
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My problem with how it's implemented is that the value is fixed at build time. Will it fly in standard setups? (Honest question, I don't have an answer)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question. @phillip-kruger what do you think?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @gsmet but we have same problem for all variables in
Maybe we should fix this in another PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point swagger ui html is generated at build time. allowing dynamic creation at runtime will be a big change. We can maybe change the static generated html and js to allow some parameters that can change behavior at runtime, but even that is a much bigger change |
||
|
|
||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| Map<String, String> oauthAdditionalQueryStringParamMap = new HashMap<>(); | ||
|
|
@@ -437,6 +446,13 @@ private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, Swagg | |
| return IndexHtmlCreator.createIndexHtml(urlsMap, swaggerUiConfig.urlsPrimaryName.orElse(null), options); | ||
| } | ||
|
|
||
| private void addLocationPath(String locationPath, Option key, Map<Option, String> options) { | ||
| var value = options.get(key); | ||
| if (value != null) { | ||
| options.put(key, locationPath + value); | ||
| } | ||
| } | ||
|
|
||
| private static boolean shouldInclude(LaunchModeBuildItem launchMode, SwaggerUiConfig swaggerUiConfig) { | ||
| return launchMode.getLaunchMode().isDevOrTest() || swaggerUiConfig.alwaysInclude; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package io.quarkus.swaggerui.deployment; | ||
|
|
||
| import static org.hamcrest.Matchers.containsString; | ||
|
|
||
| import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.quarkus.test.QuarkusUnitTest; | ||
| import io.restassured.RestAssured; | ||
|
|
||
| public class LocationPathTest { | ||
|
|
||
| @RegisterExtension | ||
| static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
| .withApplicationRoot((jar) -> jar | ||
| .addAsResource(new StringAsset( | ||
| "quarkus.swagger-ui.location-path=/nginx/path"), "application.properties")); | ||
|
|
||
| @Test | ||
| public void shouldUseCustomOpenApiPath() { | ||
| RestAssured.when().get("/q/swagger-ui").then().statusCode(200).body(containsString("/nginx/path/q/openapi")); | ||
| RestAssured.when().get("/q/swagger-ui/index.html").then().statusCode(200).body(containsString("/nginx/path/q/openapi")); | ||
| RestAssured.when().get("/q/swagger-ui").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/swagger-ui/oauth2-redirect.html")); | ||
| RestAssured.when().get("/q/swagger-ui/index.html").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/swagger-ui/oauth2-redirect.html")); | ||
| RestAssured.when().get("/q/swagger-ui").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/dev")); | ||
| RestAssured.when().get("/q/swagger-ui/index.html").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/dev")); | ||
| RestAssured.when().get("/q/swagger-ui").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/swagger-ui")); | ||
| RestAssured.when().get("/q/swagger-ui/index.html").then() | ||
| .statusCode(200) | ||
| .body(containsString("/nginx/path/q/swagger-ui")); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the root path for openapi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should rename
locationPathtorootPath?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done