Skip to content

Commit

Permalink
fix: openapi publication (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Aug 9, 2023
1 parent f7441b7 commit 5a45c36
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 542 deletions.
36 changes: 27 additions & 9 deletions .github/workflows/publish-swaggerhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ on:
required: false
type: string

workflow_dispatch:
inputs:
downstream-version:
required: false
description: "Version of the Tractus-X EDC API to be should be published"
type: string
upstream-version:
required: false
description: "Version of upstream EDC which is to be used"
type: string

jobs:
swagger-api:
runs-on: ubuntu-latest
Expand All @@ -50,38 +61,39 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3

- name: Install tools
- name: Install Swagger CLI
run: |
npm i -g swaggerhub-cli
- name: Extract versions
run: |
if [ -z ${{ inputs.downstream-version }} ]; then
export DOWNSTREAM_VERSION=$(sed -nr "{ :l /^version[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" ./gradle.properties | tr -d ' ' | tr -d '"')
export DOWNSTREAM_VERSION=$(grep "version" gradle.properties | awk -F= '{print $2}')
else
export DOWNSTREAM_VERSION=${{ inputs.downstream-version }}
fi
if [ -z ${{ inputs.upstream-version }} ]; then
export UPSTREAM_VERSION=$(sed -nr "/^\[versions\]/ { :l /^edc[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" ./gradle/libs.versions.toml | tr -d ' ' | tr -d '"')-SNAPSHOT
export UPSTREAM_VERSION=$(grep "edc = " gradle/libs.versions.toml | awk -F= '{print $2}' | jq -r)
else
export UPSTREAM_VERSION=${{ inputs.upstream-version }}
fi
echo "DOWNSTREAM_VERSION=$DOWNSTREAM_VERSION" >> "$GITHUB_ENV"
echo "UPSTREAM_VERSION=$UPSTREAM_VERSION" >> "$GITHUB_ENV"
- name: Resolve TX EDC API Spec
shell: bash
run: |
./gradlew :edc-extensions:dataplane-proxy:edc-dataplane-proxy-provider-api:resolve
./gradlew :edc-extensions:dataplane-proxy:edc-dataplane-proxy-consumer-api:resolve
./gradlew resolve
- name: Download upstream API specs
run: |
swaggerhub api:get eclipse-edc-bot/management-api/${{ env.UPSTREAM_VERSION }} > resources/openapi/yaml/upstream-management-api.yaml
swaggerhub api:get eclipse-edc-bot/control-api/${{ env.UPSTREAM_VERSION }} > resources/openapi/yaml/upstream-control-api.yaml
curl -X GET https://api.swaggerhub.com/apis/eclipse-edc-bot/management-api/${{ env.UPSTREAM_VERSION }}/swagger.yaml > resources/openapi/yaml/upstream-management-api.yaml
curl -X GET https://api.swaggerhub.com/apis/eclipse-edc-bot/control-api/${{ env.UPSTREAM_VERSION }}/swagger.yaml > resources/openapi/yaml/upstream-control-api.yaml
- name: Merge API specs
run: |
./gradlew -PapiTitle="tractusx-edc-api" -PapiDescription="Tractus EDC API Doc" :mergeApiSpec --input=./resources/openapi/yaml --output=./resources/openapi/yaml/tractusx-edc-api.yaml
./gradlew -PapiTitle="Tractus-X EDC REST API" -PapiDescription="Tractus-X EDC API Documentation" :mergeApiSpec --input=./resources/openapi/yaml --output=./resources/openapi/yaml/tractusx-edc-api.yaml
# create API, will fail if exists
- name: Create API
Expand All @@ -92,4 +104,10 @@ jobs:
# Post the API to SwaggerHub as "unpublished", because published APIs cannot be overwritten
- name: Publish API Specs to SwaggerHub
run: |
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=unpublish
if [[ ${{ env.DOWNSTREAM_VERSION }} != *-SNAPSHOT ]]; then
echo "no snapshot, will set the API to 'published'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=publish
else
echo "snapshot, will set the API to 'unpublished'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=unpublish
fi
3 changes: 2 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ jobs:
permissions:
contents: read
needs: [ secret-presence ]
if: needs.secret-presence.output.HAS_SWAGGER
if: needs.secret-presence.outputs.HAS_SWAGGER
uses: ./.github/workflows/publish-swaggerhub.yaml
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;

@OpenAPIDefinition(info = @Info(description = "With this API clients can create, read, update and delete BusinessPartnerNumber groups. It allows the assigning of BPNs to groups.", title = "Business Partner Group API"))
@Tag(name = "BusinessPartnerGroup")
@Tag(name = "Business Partner Group")
public interface BusinessPartnerGroupApi {


Expand Down
43 changes: 0 additions & 43 deletions resources/openapi/yaml/edc-dataplane-proxy-consumer-api.yaml

This file was deleted.

Loading

0 comments on commit 5a45c36

Please sign in to comment.