Skip to content

Commit

Permalink
feat(#19): openapi and licenses asset
Browse files Browse the repository at this point in the history
  • Loading branch information
jhagestedt committed May 1, 2021
1 parent df91c62 commit 8eb63d6
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
10 changes: 9 additions & 1 deletion .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@
<trimHeaderLine>true</trimHeaderLine>
<emptyLineAfterHeader>true</emptyLineAfterHeader>
</configuration>
<executions>
<execution>
<id>download-licenses</id>
<phase>validate</phase>
<goals>
<goal>download-licenses</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java
Original file line number Diff line number Diff line change
@@ -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")));
}
}
36 changes: 36 additions & 0 deletions src/test/java/OpenApiTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 8eb63d6

Please sign in to comment.