Skip to content

Commit

Permalink
Merge pull request #43950 from phillip-kruger/endpoints-post-enhancement
Browse files Browse the repository at this point in the history
Dev UI: Change the endpoints to navigate to Swagger UI if included
  • Loading branch information
phillip-kruger authored Oct 18, 2024
2 parents 5c6a4c9 + 2789845 commit 2a077f6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.quarkus.devui.deployment.menu;

import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ConfigurationBuildItem;
import io.quarkus.devui.deployment.InternalPageBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.Page;
Expand All @@ -16,13 +19,24 @@ public class EndpointsProcessor {
private static final String DEVUI = "dev-ui";

@BuildStep(onlyIf = IsDevelopment.class)
InternalPageBuildItem createEndpointsPage(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) {
InternalPageBuildItem createEndpointsPage(Capabilities capabilities, ConfigurationBuildItem configurationBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) {

final boolean swaggerIsAvailable = capabilities.isPresent(Capability.SMALLRYE_OPENAPI);
final String swaggerUiPath;
if (swaggerIsAvailable) {
swaggerUiPath = nonApplicationRootPathBuildItem.resolvePath(
getProperty(configurationBuildItem, "quarkus.swagger-ui.path"));
} else {
swaggerUiPath = "";
}

String basepath = nonApplicationRootPathBuildItem.resolvePath(DEVUI);

InternalPageBuildItem endpointsPage = new InternalPageBuildItem("Endpoints", 25);

endpointsPage.addBuildTimeData("basepath", basepath);
endpointsPage.addBuildTimeData("swaggerUiPath", swaggerUiPath);

// Page
endpointsPage.addPage(Page.webComponentPageBuilder()
Expand All @@ -44,4 +58,31 @@ InternalPageBuildItem createEndpointsPage(NonApplicationRootPathBuildItem nonApp
JsonRPCProvidersBuildItem createJsonRPCService() {
return new JsonRPCProvidersBuildItem(NAMESPACE, ResourceNotFoundData.class);
}

private static String getProperty(ConfigurationBuildItem configurationBuildItem,
String propertyKey) {

String propertyValue = configurationBuildItem
.getReadResult()
.getAllBuildTimeValues()
.get(propertyKey);

if (propertyValue == null) {
propertyValue = configurationBuildItem
.getReadResult()
.getBuildTimeRunTimeValues()
.get(propertyKey);
} else {
return propertyValue;
}

if (propertyValue == null) {
propertyValue = configurationBuildItem
.getReadResult()
.getRunTimeDefaultValues()
.get(propertyKey);
}

return propertyValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '@vaadin/grid';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';
import { JsonRpc } from 'jsonrpc';
import { swaggerUiPath } from 'devui-data';

/**
* This component show all available endpoints
Expand Down Expand Up @@ -37,12 +38,14 @@ export class QwcEndpoints extends LitElement {
`;

static properties = {
filter: {type: String},
_info: {state: true}
}

constructor() {
super();
this._info = null;
this.filter = null;
}

connectedCallback() {
Expand All @@ -56,7 +59,9 @@ export class QwcEndpoints extends LitElement {
if (this._info) {
const typeTemplates = [];
for (const [type, list] of Object.entries(this._info)) {
typeTemplates.push(html`${this._renderType(type,list)}`);
if(!this.filter || this.filter === type){
typeTemplates.push(html`${this._renderType(type,list)}`);
}
}
return html`${typeTemplates}`;
}else{
Expand Down Expand Up @@ -86,8 +91,12 @@ export class QwcEndpoints extends LitElement {
}

_uriRenderer(endpoint) {
if (endpoint.uri) {
if (endpoint.uri && endpoint.description && endpoint.description.startsWith("GET")) {
return html`<a href="${endpoint.uri}" target="_blank">${endpoint.uri}</a>`;
}else if(swaggerUiPath!==""){
return html`<a href="${swaggerUiPath}" title="Test this Swagger UI" target="_blank">${endpoint.uri}</a>`;
}else{
return html`<span>${endpoint.uri}</span>`;
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a077f6

Please sign in to comment.