From 27898457d26171df60b362b456547e004ff4d7d7 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Fri, 18 Oct 2024 12:47:49 +1100 Subject: [PATCH] Dev UI: Change the endpoints to navigate to Swagger UI if included (non-GET) Signed-off-by: Phillip Kruger --- .../deployment/menu/EndpointsProcessor.java | 43 ++++++++++- .../resources/dev-ui/qwc/qwc-endpoints.js | 13 +++- .../main/resources/dev-ui/qwc/qwc-welcome.js | 72 +------------------ 3 files changed, 55 insertions(+), 73 deletions(-) diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/menu/EndpointsProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/menu/EndpointsProcessor.java index 84b9b46399985..47e3e8c0ccd1a 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/menu/EndpointsProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/menu/EndpointsProcessor.java @@ -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; @@ -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() @@ -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; + } } diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js index fd0479db7311b..5afea65ed153f 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js @@ -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 @@ -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() { @@ -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{ @@ -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`${endpoint.uri}`; + }else if(swaggerUiPath!==""){ + return html`${endpoint.uri}`; + }else{ + return html`${endpoint.uri}`; } } diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-welcome.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-welcome.js index e56cf4778b957..bb0423c2b7e12 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-welcome.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-welcome.js @@ -1,17 +1,11 @@ import { LitElement, html, css } from 'lit'; import { devuiState } from 'devui-state'; -import { JsonRpc } from 'jsonrpc'; -import '@vaadin/progress-bar'; -import '@vaadin/grid'; -import { columnBodyRenderer } from '@vaadin/grid/lit.js'; -import '@vaadin/grid/vaadin-grid-sort-column.js'; +import 'qwc/qwc-endpoints.js'; /** * This component shows the welcome screen */ export class QwcWelcome extends LitElement { - jsonRpc = new JsonRpc("devui-endpoints"); - static styles = css` a { color: inherit; } @@ -118,22 +112,6 @@ export class QwcWelcome extends LitElement { } `; - static properties = { - _info: {state: true} - }; - - constructor() { - super(); - this._info = null; - } - - connectedCallback() { - super.connectedCallback(); - this.jsonRpc.getJsonContent().then(jsonRpcResponse => { - this._info = jsonRpcResponse.result; - }); - } - render() { return html`
@@ -202,7 +180,7 @@ export class QwcWelcome extends LitElement { Static assets: ${devuiState.welcomeData.resourcesDir}/META-INF/resources/ Code: ${devuiState.welcomeData.sourceDir}
- ${this._renderEndpoints()} +
${this._renderSelectedExtensions()} @@ -222,52 +200,6 @@ export class QwcWelcome extends LitElement { window.location.href = '/'; } - _renderEndpoints(){ - if (this._info) { - const typeTemplates = []; - for (const [type, list] of Object.entries(this._info)) { - if(type !== "Additional endpoints") - typeTemplates.push(html`${this._renderType(type,list)}`); - } - return html`${typeTemplates}`; - }else{ - return html` -
-
Fetching information...
- -
- `; - } - } - - _renderType(type, items){ - return html`

${type}

- - - - - - - `; - } - - _uriRenderer(endpoint) { - if (endpoint.uri) { - return html`${endpoint.uri}`; - } - } - - _descriptionRenderer(endpoint) { - if (endpoint.description) { - return html`${endpoint.description}`; - } - } - _renderSelectedExtensions(){ if(devuiState.welcomeData.selectedExtensions){ return html`

Selected extensions