From b19b8db18c0c5a21110ff785d5db86f4bc4f54d3 Mon Sep 17 00:00:00 2001 From: Esta Nagy Date: Thu, 28 Sep 2023 06:11:47 +0200 Subject: [PATCH] Swagger not working no 2.x.x (#719) - Replaces Swagger dependency with the correct one. - Updates configuration to use new names - Adds new test to verify that Swagger UI page is present Resolves #718 {patch} Signed-off-by: Esta Nagy --- gradle/libs.versions.toml | 4 +- gradle/verification-metadata.xml | 372 ++++++++++-------- .../src/main/resources/application.properties | 5 +- .../lowkeyvault/steps/ManagementStepDefs.java | 19 + .../lowkeyvault/management/Management.feature | 3 + 5 files changed, 228 insertions(+), 175 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f13375f8..a2278666 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ checkstyle = "10.12.2" jacoco = "0.8.10" jacksonBom = { strictly = "2.15.2" } jackson = { strictly = "2.15.2" } -openApiUi = "1.7.0" +openApiUi = "2.2.0" abortMissionPlugin = "4.1.22" dockerPlugin = "0.35.0" @@ -40,7 +40,7 @@ spring-boot-starter-tomcat = { module = "org.springframework.boot:spring-boot-st spring-boot-starter-validation = { module = "org.springframework.boot:spring-boot-starter-validation", version.ref = "springBoot" } spring-boot-configuration-processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "springBoot" } spring-boot-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "springBoot" } -springdoc-openapi-ui = { module = "org.springdoc:springdoc-openapi-ui", version.ref = "openApiUi" } +springdoc-openapi-ui = { module = "org.springdoc:springdoc-openapi-starter-webmvc-ui", version.ref = "openApiUi" } spring-core = { module = "org.springframework:spring-core", version.ref = "spring" } spring-context = { module = "org.springframework:spring-context", version.ref = "spring" } spring-web = { module = "org.springframework:spring-web", version.ref = "spring" } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index c1c83f9a..4eb117c4 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -139,9 +139,9 @@ - - - + + + @@ -778,9 +778,9 @@ - - - + + + @@ -822,9 +822,9 @@ - - - + + + @@ -832,9 +832,17 @@ - - - + + + + + + + + + + + @@ -1154,14 +1162,14 @@ - - - + + + - - - + + + @@ -1179,9 +1187,9 @@ - - - + + + @@ -1200,19 +1208,29 @@ + + + + + - - - + + + + + + + + - - - + + + @@ -1257,24 +1275,19 @@ - - - - - - - - + + + - - - + + + - - - + + + @@ -1287,33 +1300,33 @@ - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + @@ -1321,12 +1334,14 @@ - - - + + + - - + + + + @@ -1363,12 +1378,12 @@ - - - + + + - - + + @@ -1379,9 +1394,9 @@ - - - + + + @@ -1629,11 +1644,6 @@ - - - - - @@ -1827,6 +1837,11 @@ + + + + + @@ -1993,11 +2008,6 @@ - - - - - @@ -2016,11 +2026,6 @@ - - - - - @@ -2262,6 +2267,11 @@ + + + + + @@ -2353,11 +2363,6 @@ - - - - - @@ -2424,16 +2429,6 @@ - - - - - - - - - - @@ -2444,6 +2439,11 @@ + + + + + @@ -2452,16 +2452,16 @@ + + + + + - - - - - @@ -2509,9 +2509,14 @@ - - - + + + + + + + + @@ -2558,14 +2563,14 @@ - - - + + + - - - + + + @@ -2613,11 +2618,6 @@ - - - - - @@ -2667,9 +2667,9 @@ - - - + + + @@ -2786,9 +2786,9 @@ - - - + + + @@ -2983,6 +2983,11 @@ + + + + + @@ -3229,33 +3234,33 @@ - - - + + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + @@ -3288,9 +3293,9 @@ - - - + + + @@ -3313,6 +3318,16 @@ + + + + + + + + + + @@ -3338,9 +3353,9 @@ - - - + + + @@ -3368,9 +3383,9 @@ - - - + + + @@ -3403,24 +3418,34 @@ - - - + + + - - - + + + - - - + + + - - - + + + + + + + + + + + + + @@ -3439,6 +3464,11 @@ + + + + + @@ -3478,12 +3508,12 @@ - - - + + + - - + + diff --git a/lowkey-vault-app/src/main/resources/application.properties b/lowkey-vault-app/src/main/resources/application.properties index 59db14a6..fa0967e4 100644 --- a/lowkey-vault-app/src/main/resources/application.properties +++ b/lowkey-vault-app/src/main/resources/application.properties @@ -18,8 +18,9 @@ server.error.include-binding-errors=always server.error.include-message=always # springdoc.api-docs.path=/api/docs -springdoc.swagger-ui.path=/api/swagger-ui.html -springdoc.pathsToMatch=/management/** +springdoc.swagger-ui.enabled=true +springdoc.swagger-ui.path=/api/swagger-ui/index.html +springdoc.paths-to-match=/management/** springdoc.swagger-ui.operationsSorter=alpha # spring.jackson.generator.flush-passed-to-stream=true diff --git a/lowkey-vault-docker/src/test/java/com/github/nagyesta/lowkeyvault/steps/ManagementStepDefs.java b/lowkey-vault-docker/src/test/java/com/github/nagyesta/lowkeyvault/steps/ManagementStepDefs.java index ec3e448a..5659da86 100644 --- a/lowkey-vault-docker/src/test/java/com/github/nagyesta/lowkeyvault/steps/ManagementStepDefs.java +++ b/lowkey-vault-docker/src/test/java/com/github/nagyesta/lowkeyvault/steps/ManagementStepDefs.java @@ -1,7 +1,11 @@ package com.github.nagyesta.lowkeyvault.steps; +import com.azure.core.http.HttpMethod; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; import com.github.nagyesta.lowkeyvault.context.ManagementTestContext; import com.github.nagyesta.lowkeyvault.context.TestContextConfig; +import com.github.nagyesta.lowkeyvault.http.ApacheHttpClient; import com.github.nagyesta.lowkeyvault.http.ApacheHttpClientProvider; import com.github.nagyesta.lowkeyvault.http.AuthorityOverrideFunction; import com.github.nagyesta.lowkeyvault.http.management.RecoveryLevel; @@ -11,10 +15,14 @@ import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import java.net.MalformedURLException; import java.net.URI; import java.time.OffsetDateTime; import java.util.*; +import java.util.function.Function; import static com.github.nagyesta.lowkeyvault.context.TestContextConfig.CONTAINER_AUTHORITY; @@ -26,6 +34,17 @@ public ManagementStepDefs(final TestContextConfig config) { this.context = config.managementContext(); } + @SuppressWarnings("checkstyle:MagicNumber") + @When("OpenAPI ui is available") + public void openApiUiIsAvailable() throws MalformedURLException { + final URI swaggerUri = URI.create("https://" + CONTAINER_AUTHORITY+"/api/swagger-ui/index.html"); + final ApacheHttpClient client = new ApacheHttpClient(Function.identity(), new TrustSelfSignedStrategy(), new NoopHostnameVerifier()); + final HttpResponse response = client.send(new HttpRequest(HttpMethod.GET, swaggerUri.toURL())).block(); + assertNotNull(response); + assertEquals(200, Objects.requireNonNull(response).getStatusCode()); + assertTrue(Objects.requireNonNull(response.getBodyAsString().block()).contains("Swagger UI")); + } + @Given("a vault is created with name {name}") public void aVaultIsCreatedWithName(final String vaultName) { final String vaultAuthority = vaultName + ".localhost:8443"; diff --git a/lowkey-vault-docker/src/test/resources/com/github/nagyesta/lowkeyvault/management/Management.feature b/lowkey-vault-docker/src/test/resources/com/github/nagyesta/lowkeyvault/management/Management.feature index d81736e5..f908480a 100644 --- a/lowkey-vault-docker/src/test/resources/com/github/nagyesta/lowkeyvault/management/Management.feature +++ b/lowkey-vault-docker/src/test/resources/com/github/nagyesta/lowkeyvault/management/Management.feature @@ -1,6 +1,9 @@ @Sequential Feature: Vault Management + Scenario: SWAGGER_01 Swagger UI is available + When OpenAPI ui is available + @CreateVault Scenario: MANAGEMENT_01 A vault is created, deleted, then recovered. Given a vault is created with name vault-management