-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from eu-digital-green-certificates/feature/aut…
…omate_OpenApiDocCreation Add files for Open Api Creation workflow
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 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,67 @@ | ||
name: ci-openapi | ||
on: | ||
workflow_dispatch: | ||
release: | ||
types: | ||
- created | ||
jobs: | ||
release: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/setup-java@v2 | ||
with: | ||
java-version: 11 | ||
distribution: adopt | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.m2/repository | ||
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }} | ||
- name: version | ||
run: >- | ||
APP_SHA=$(git rev-parse --short ${GITHUB_SHA}); | ||
APP_TAG=${GITHUB_REF/refs\/tags\/} | ||
APP_VERSION=${APP_TAG}; | ||
echo "APP_SHA=${APP_SHA}" >> ${GITHUB_ENV}; | ||
echo "APP_TAG=${APP_TAG}" >> ${GITHUB_ENV}; | ||
echo "APP_VERSION=${APP_VERSION}" >> ${GITHUB_ENV}; | ||
- name: mvn | ||
run: >- | ||
mvn versions:set | ||
--batch-mode | ||
--file ./pom.xml | ||
--settings ./settings.xml | ||
--define newVersion="${APP_VERSION}"; | ||
mvn clean verify | ||
--batch-mode | ||
--file ./pom.xml | ||
--settings ./settings.xml | ||
--define app.packages.username="${APP_PACKAGES_USERNAME}" | ||
--define app.packages.password="${APP_PACKAGES_PASSWORD}"; | ||
env: | ||
APP_PACKAGES_USERNAME: ${{ github.actor }} | ||
APP_PACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: openapi.json | ||
path: target/openapi.json | ||
- name: Checkout OpenApi Doc Branch | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: openapi-doc | ||
- name: Delete existing openapi.json | ||
run: rm -f openapi.json | ||
- name: Download openapi.json | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: openapi.json | ||
- name: Commit and Push changes | ||
run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
git commit -a --allow-empty -m "Update OpenAPI JSON" | ||
git push |
56 changes: 56 additions & 0 deletions
56
src/test/java/eu/europa/ec/dgc/validation/decorator/OpenApiTest.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,56 @@ | ||
package eu.europa.ec.dgc.validation.decorator;/*- | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-validation-decorator | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
|
||
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( | ||
properties = { | ||
"server.port=8080", | ||
"springdoc.api-docs.enabled=true", | ||
"springdoc.api-docs.path=/openapi" | ||
}, | ||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT | ||
) | ||
class OpenApiTest { | ||
|
||
|
||
@Test | ||
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(); | ||
} | ||
} | ||
} |