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

Easily go back to Dev UI from Swagger and GraphQL UI #20055

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<smallrye-config.version>2.4.4</smallrye-config.version>
<smallrye-health.version>3.1.1</smallrye-health.version>
<smallrye-metrics.version>3.0.1</smallrye-metrics.version>
<smallrye-open-api.version>2.1.13</smallrye-open-api.version>
<smallrye-graphql.version>1.3.2</smallrye-graphql.version>
<smallrye-open-api.version>2.1.14</smallrye-open-api.version>
<smallrye-graphql.version>1.3.3</smallrye-graphql.version>
<smallrye-opentracing.version>2.0.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.2.1</smallrye-fault-tolerance.version>
<smallrye-jwt.version>3.2.1</smallrye-jwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ body {
padding-top: 12px !important;
}

#graphiql .title a::after {
#graphQLUiTitleLink::after {
content: "GraphQL UI";
}

#graphiql .title a {
#graphQLUiTitleLink {
display: flex;
align-items:center;
color: white;
Expand All @@ -64,9 +64,13 @@ body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

#graphiql .title img {
#graphQLUiLogoLink img {
border-right: 1px solid darkgrey;
padding-right: 10px;
margin-right: 10px;
height: 30px;
}

.graphiql-container .title {
display: flex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ html{
padding-bottom: 5px !important;
}

#swagger-ui .swagger-ui .topbar a {
max-width: 180px;
#swaggerUiLogoLink {
max-width: 50px;
min-width: 50px;
}

#swagger-ui .topbar-wrapper .link a::after {
#swaggerUiTitleLink {
max-width: 120px;
}

#swaggerUiTitleLink::after {
content: "Swagger UI";
font-size: 1.25rem;
font-weight: normal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class SmallRyeGraphQLProcessor {
private static final String LINE_FORMAT = LINE_TO_UPDATE + "%s';";
private static final String UI_LINE_TO_UPDATE = "const ui = '";
private static final String UI_LINE_FORMAT = UI_LINE_TO_UPDATE + "%s';";
private static final String LOGO_LINE_TO_UPDATE = "const logo = '";
private static final String LOGO_LINE_FORMAT = LOGO_LINE_TO_UPDATE + "%s';";

// Branding files to monitor for changes
private static final String BRANDING_DIR = "META-INF/branding/";
Expand Down Expand Up @@ -519,6 +521,8 @@ void getGraphqlUiFinalDestination(
WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLPath, LINE_TO_UPDATE, LINE_FORMAT);
WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLUiPath,
UI_LINE_TO_UPDATE, UI_LINE_FORMAT);
WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), nonApplicationRootPathBuildItem.resolvePath("dev"),
LOGO_LINE_TO_UPDATE, LOGO_LINE_FORMAT);

smallRyeGraphQLBuildProducer
.produce(new SmallRyeGraphQLBuildItem(tempPath.toAbsolutePath().toString(), graphQLUiPath));
Expand Down Expand Up @@ -546,6 +550,11 @@ void getGraphqlUiFinalDestination(
UI_LINE_TO_UPDATE,
UI_LINE_FORMAT)
.getBytes(StandardCharsets.UTF_8);
content = WebJarUtil
.updateUrl(new String(content, StandardCharsets.UTF_8), graphQLUiPath,
LOGO_LINE_TO_UPDATE,
LOGO_LINE_FORMAT)
.getBytes(StandardCharsets.UTF_8);
}
fileName = GRAPHQL_UI_FINAL_DESTINATION + "/" + fileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void getSwaggerUiFinalDestination(
SWAGGER_UI_WEBJAR_PREFIX);
// Update index.html
WebJarUtil.updateFile(tempPath.resolve("index.html"),
generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig));
generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig, nonApplicationRootPathBuildItem));

swaggerUiBuildProducer.produce(new SwaggerUiBuildItem(tempPath.toAbsolutePath().toString(), swaggerUiPath));

Expand All @@ -151,7 +151,7 @@ public void getSwaggerUiFinalDestination(
if (fileName.equals(theme.toString()) || !fileName.startsWith("theme-")) {
byte[] content;
if (fileName.endsWith("index.html")) {
content = generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig);
content = generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig, null);
} else {
content = file.getValue();
}
Expand Down Expand Up @@ -194,12 +194,18 @@ public void registerSwaggerUiHandler(SwaggerUiRecorder recorder,
}
}

private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, SwaggerUiConfig swaggerUiConfig)
private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, SwaggerUiConfig swaggerUiConfig,
NonApplicationRootPathBuildItem nonApplicationRootPath)
throws IOException {
Map<Option, String> options = new HashMap<>();
Map<String, String> urlsMap = null;

options.put(Option.selfHref, swaggerUiPath);
if (nonApplicationRootPath != null) {
options.put(Option.backHref, nonApplicationRootPath.resolvePath("dev"));
} else {
options.put(Option.backHref, swaggerUiPath);
}

// Only add the url if the user did not specified urls
if (swaggerUiConfig.urls != null && !swaggerUiConfig.urls.isEmpty()) {
Expand Down