Skip to content

Commit

Permalink
Merge pull request #37 from eu-digital-green-certificates/feature/aut…
Browse files Browse the repository at this point in the history
…omate_OpenApiDocCreation

Add files for Open Api Creation workflow
  • Loading branch information
SchulzeStTSI authored Dec 8, 2021
2 parents c2343cc + e6536df commit 4e0ea1a
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/ci-openapi.yml
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
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();
}
}
}

0 comments on commit 4e0ea1a

Please sign in to comment.