From 8eb63d60ee03b89f8b3220e3ce503f5d95a93115 Mon Sep 17 00:00:00 2001 From: Julien Hagestedt Date: Sat, 1 May 2021 12:01:37 +0200 Subject: [PATCH] feat(#19): openapi and licenses asset --- .editorconfig | 11 ++++++ .github/workflows/ci-main.yml | 2 +- .github/workflows/ci-release.yml | 10 +++++- pom.xml | 9 +++++ .../dgc/issuance/DgcIssuanceApplication.java | 7 ---- .../ec/dgc/issuance/config/OpenApiConfig.java | 35 ++++++++++++++++++ src/test/java/OpenApiTest.java | 36 +++++++++++++++++++ 7 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 .editorconfig create mode 100644 src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java create mode 100644 src/test/java/OpenApiTest.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f0881c0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true + +[*.java] +indent_size = 4 diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 98e2ca1..83734ac 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -55,6 +55,6 @@ jobs: --tag "${APP_PACKAGES_URL}:${APP_VERSION}"; docker push "${APP_PACKAGES_URL}:${APP_VERSION}"; env: - APP_PACKAGES_URL: docker.pkg.github.com/${{ github.repository }}/container + APP_PACKAGES_URL: docker.pkg.github.com/${{ github.repository }}/dgca-issuance-service APP_PACKAGES_USERNAME: ${{ github.actor }} APP_PACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index d3205d0..20699ca 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -56,6 +56,14 @@ jobs: docker push "${APP_PACKAGES_URL}:latest"; docker push "${APP_PACKAGES_URL}:${APP_VERSION}"; env: - APP_PACKAGES_URL: docker.pkg.github.com/${{ github.repository }}/container + APP_PACKAGES_URL: docker.pkg.github.com/${{ github.repository }}/dgca-issuance-service APP_PACKAGES_USERNAME: ${{ github.actor }} APP_PACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + - name: assets + run: >- + gh release upload ${APP_TAG} + --clobber + ./target/openapi.json#openapi-${APP_TAG}.json + ./target/generated-resources/licenses.xml#licenses-${APP_TAG}.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/pom.xml b/pom.xml index 92d5871..6a68276 100644 --- a/pom.xml +++ b/pom.xml @@ -410,6 +410,15 @@ true true + + + download-licenses + validate + + download-licenses + + + diff --git a/src/main/java/eu/europa/ec/dgc/issuance/DgcIssuanceApplication.java b/src/main/java/eu/europa/ec/dgc/issuance/DgcIssuanceApplication.java index 0767afe..5eb9dc3 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/DgcIssuanceApplication.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/DgcIssuanceApplication.java @@ -34,13 +34,6 @@ */ @SpringBootApplication @EnableConfigurationProperties({IssuanceConfigProperties.class}) -@OpenAPIDefinition( - info = @Info( - title = "Digital Green Certificate Issuance", - description = "The API defines Issuance Service for digital green certificates.", - license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0") - ) -) public class DgcIssuanceApplication extends SpringBootServletInitializer { /** diff --git a/src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java b/src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java new file mode 100644 index 0000000..884330c --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java @@ -0,0 +1,35 @@ +package eu.europa.ec.dgc.issuance.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import lombok.Generated; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.info.BuildProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Generated +@Configuration +@RequiredArgsConstructor +public class OpenApiConfig { + + private final BuildProperties buildProperties; + + /** + * Configure the OpenApi bean with title and version. + * + * @return the OpenApi bean. + */ + @Bean + public OpenAPI openApi() { + return new OpenAPI() + .info(new Info() + .title("Digital Green Certificate Issuance") + .description("The API defines Issuance Service for digital green certificates.") + .version(buildProperties.getVersion()) + .license(new License() + .name("Apache 2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0"))); + } +} diff --git a/src/test/java/OpenApiTest.java b/src/test/java/OpenApiTest.java new file mode 100644 index 0000000..fe6a13c --- /dev/null +++ b/src/test/java/OpenApiTest.java @@ -0,0 +1,36 @@ +import eu.europa.ec.dgc.issuance.DgcIssuanceApplication; +import java.io.BufferedInputStream; +import java.io.FileOutputStream; +import java.net.URL; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest( + classes = DgcIssuanceApplication.class, + properties = { + "server.port=8080", + "springdoc.api-docs.enabled=true", + "springdoc.api-docs.path=/openapi" + }, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT +) +public class OpenApiTest { + + @Test + public void apiDocs() { + try (BufferedInputStream in = new BufferedInputStream(new URL("http://localhost:8080/openapi").openStream()); + FileOutputStream out = new FileOutputStream("target/openapi.json")) { + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer, 0, buffer.length)) != -1) { + out.write(buffer, 0, read); + } + } catch (Exception e) { + log.error("Failed to download openapi specification.", e); + Assertions.fail(); + } + } +}