diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfWebConfiguration.java b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfWebConfiguration.java index 817e2ca85..00cedbb92 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfWebConfiguration.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfWebConfiguration.java @@ -7,6 +7,7 @@ import io.github.springwolf.core.asyncapi.AsyncApiService; import io.github.springwolf.core.asyncapi.components.ComponentsService; import io.github.springwolf.core.asyncapi.grouping.AsyncApiGroupService; +import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; import io.github.springwolf.core.controller.ActuatorAsyncApiController; import io.github.springwolf.core.controller.AsyncApiController; import io.github.springwolf.core.controller.PublishingPayloadCreator; @@ -52,8 +53,9 @@ public ActuatorAsyncApiController actuatorAsyncApiController( @Bean @ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "false", matchIfMissing = true) @ConditionalOnMissingBean - public UiConfigController uiConfigController(AsyncApiGroupService asyncApiGroupService) { - return new UiConfigController(asyncApiGroupService); + public UiConfigController uiConfigController( + AsyncApiGroupService asyncApiGroupService, SpringwolfConfigProperties configProperties) { + return new UiConfigController(asyncApiGroupService, configProperties); } @Bean diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java index afbef376e..4f5089d12 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java @@ -78,6 +78,13 @@ public enum InitMode { private ConfigDocket docket = new ConfigDocket(); + /** + * The UI configuration properties. + * + * @see UI + */ + private UI ui = new UI(); + @Nullable private Scanner scanner; @@ -222,6 +229,20 @@ public static class Group { } } + @Getter + @Setter + public static class UI { + /** + * Allows to show or hide the bindings in the UI when opening the UI. + */ + private boolean initiallyShowBindings = true; + + /** + * Allows to show or hide the headers in the UI when opening the UI. + */ + private boolean initiallyShowHeaders = true; + } + @Getter @Setter public static class Scanner { diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/controller/UiConfigController.java b/springwolf-core/src/main/java/io/github/springwolf/core/controller/UiConfigController.java index cb0eda456..553f1c26d 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/controller/UiConfigController.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/controller/UiConfigController.java @@ -2,6 +2,7 @@ package io.github.springwolf.core.controller; import io.github.springwolf.core.asyncapi.grouping.AsyncApiGroupService; +import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -16,18 +17,35 @@ public class UiConfigController { private final AsyncApiGroupService asyncApiGroupService; + private final SpringwolfConfigProperties configProperties; @GetMapping( path = {"${springwolf.path.base:/springwolf}/ui-config"}, produces = MediaType.APPLICATION_JSON_VALUE) public UiConfig getUiConfig() { - return new UiConfig(asyncApiGroupService + + final UiConfig.InitialConfig initial = createInitialConfig(); + final List groups = createGroups(); + + return new UiConfig(initial, groups); + } + + private List createGroups() { + return asyncApiGroupService .getAsyncApiGroups() .map(el -> new UiConfig.UiConfigGroup(el.getGroupName())) - .toList()); + .toList(); } - private record UiConfig(List groups) { + private UiConfig.InitialConfig createInitialConfig() { + return new UiConfig.InitialConfig( + configProperties.getUi().isInitiallyShowBindings(), + configProperties.getUi().isInitiallyShowHeaders()); + } + + private record UiConfig(InitialConfig initialConfig, List groups) { + private record InitialConfig(boolean showBindings, boolean showHeaders) {} + private record UiConfigGroup(String name) {} } } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigPropertiesIntegrationTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigPropertiesIntegrationTest.java index c725cd85e..c093b58ee 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigPropertiesIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigPropertiesIntegrationTest.java @@ -207,4 +207,44 @@ void groupConfigIsMappedCorrectly() { assertThat(actual.get(1)).isEqualTo(receiveGroup); } } + + @Nested + @ExtendWith(SpringExtension.class) + @EnableConfigurationProperties(SpringwolfConfigProperties.class) + @TestPropertySource( + properties = {"springwolf.ui.initially-show-bindings=false", "springwolf.ui.initially-show-headers=true"}) + class UiConfigTest { + + @Autowired + private SpringwolfConfigProperties properties; + + @Test + void uiConfigIsMappedCorrectly() { + // when + final SpringwolfConfigProperties.UI actual = properties.getUi(); + + // then + assertThat(actual.isInitiallyShowBindings()).isFalse(); + assertThat(actual.isInitiallyShowHeaders()).isTrue(); + } + } + + @Nested + @ExtendWith(SpringExtension.class) + @EnableConfigurationProperties(SpringwolfConfigProperties.class) + class DefaultConfigTest { + + @Autowired + private SpringwolfConfigProperties properties; + + @Test + void uiConfigIsMappedCorrectly() { + // when + final SpringwolfConfigProperties.UI actual = properties.getUi(); + + // then + assertThat(actual.isInitiallyShowBindings()).isTrue(); + assertThat(actual.isInitiallyShowHeaders()).isTrue(); + } + } } diff --git a/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties b/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties index b8d3f8122..feb700d7a 100644 --- a/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties @@ -32,6 +32,9 @@ springwolf.docket.servers.amqp-server.host=${spring.rabbitmq.host}:${spring.rabb springwolf.plugin.amqp.publishing.enabled=true +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-examples/springwolf-cloud-stream-example/src/main/resources/application.properties b/springwolf-examples/springwolf-cloud-stream-example/src/main/resources/application.properties index 01e2abba9..8191950f7 100644 --- a/springwolf-examples/springwolf-cloud-stream-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-cloud-stream-example/src/main/resources/application.properties @@ -41,6 +41,9 @@ springwolf.docket.servers.kafka-server.protocol=kafka springwolf.docket.servers.kafka-server.host=${spring.cloud.stream.binders.kafka.environment.spring.kafka.bootstrap-servers} springwolf.use-fqn=false +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-examples/springwolf-jms-example/src/main/resources/application.properties b/springwolf-examples/springwolf-jms-example/src/main/resources/application.properties index eb34ac783..04d24b5e9 100644 --- a/springwolf-examples/springwolf-jms-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-jms-example/src/main/resources/application.properties @@ -27,6 +27,9 @@ springwolf.docket.servers.jms-server.host=${spring.activemq.broker-url} springwolf.plugin.jms.publishing.enabled=true +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties b/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties index aec88ed49..fa0d1b149 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties @@ -43,6 +43,10 @@ springwolf.payload.extractable-classes.org.apache.kafka.clients.consumer.Consume springwolf.docket.group-configs[0].group=Only Vehicles springwolf.docket.group-configs[0].message-name-to-match=.*Vehicle.* +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true + # Springwolf kafka configuration springwolf.docket.servers.kafka-server.protocol=kafka springwolf.docket.servers.kafka-server.host=${spring.kafka.bootstrap-servers} diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/ui-config.json b/springwolf-examples/springwolf-kafka-example/src/test/resources/ui-config.json index e44f969cf..0fcf34c0d 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/ui-config.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/ui-config.json @@ -1 +1 @@ -{"groups":[{"name":"Only Vehicles"}]} \ No newline at end of file +{"initialConfig":{"showBindings":true,"showHeaders":true},"groups":[{"name":"Only Vehicles"}]} \ No newline at end of file diff --git a/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties b/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties index f28097d59..e6a8ecb87 100644 --- a/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties @@ -30,6 +30,9 @@ springwolf.docket.servers.sns-server.host=http://localhost:4566 springwolf.plugin.sns.publishing.enabled=true +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties b/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties index 538a1399a..cf289414f 100644 --- a/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties @@ -30,6 +30,9 @@ springwolf.docket.servers.sqs-server.host=http://localhost:4566 springwolf.plugin.sqs.publishing.enabled=true +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-examples/springwolf-stomp-example/src/main/resources/application.properties b/springwolf-examples/springwolf-stomp-example/src/main/resources/application.properties index c3dc78783..3c8dfe6b6 100644 --- a/springwolf-examples/springwolf-stomp-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-stomp-example/src/main/resources/application.properties @@ -21,6 +21,9 @@ springwolf.docket.servers.stomp.host=localhost:8080/myendpoint springwolf.plugin.stomp.endpoint.app=/app springwolf.plugin.stomp.endpoint.user=/user +# Springwolf ui configuration +springwolf.ui.initially-show-bindings=true +springwolf.ui.initially-show-headers=true # For debugging purposes logging.level.io.github.springwolf=DEBUG diff --git a/springwolf-ui/src/app/components/header/header.component.html b/springwolf-ui/src/app/components/header/header.component.html index 019f4081d..d60d9c370 100644 --- a/springwolf-ui/src/app/components/header/header.component.html +++ b/springwolf-ui/src/app/components/header/header.component.html @@ -44,13 +44,21 @@

{{ title }}

} - -