-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#19): openapi and licenses asset
- Loading branch information
1 parent
df91c62
commit 8eb63d6
Showing
7 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/eu/europa/ec/dgc/issuance/config/OpenApiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |