Skip to content

Commit

Permalink
feat(doc): update the verification and generation of OpenAPI spec fil…
Browse files Browse the repository at this point in the history
…es (eclipse-edc#2209)

* feat: apply apiGroup configs

* delete embedded swagger UI

* bring back old and outdated Swagger UI

* updated api specs

* create-update logic for API doc
  • Loading branch information
paullatzelsperger committed Dec 12, 2022
1 parent 8421cc0 commit eb5605a
Show file tree
Hide file tree
Showing 33 changed files with 189 additions and 46 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/apidoc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Verify and Publish OpenAPI Specs

on:
push:
pull_request:
branches: [ main ]
paths-ignore:
- '**.md'
- 'docs/**'
- 'CODEOWNERS'
- 'LICENSE'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Verify-OpenAPI-Definitions:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
apiGroup: [ 'management-api', 'control-api' ]
env:
rootDir: resources/openapi/yaml/${{ matrix.apiGroup }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-build

- name: Save previous OpenAPI definition
run: |
mkdir -p git-sorted/${{ matrix.apiGroup }}
files=($(ls $rootDir))
for file in ${files[@]}; do
yq -P 'sort_keys(..)' $rootDir/$file > git-sorted/${{ matrix.apiGroup }}/$file
done
- name: Generate OpenAPI definitions from code
run: |
export
./gradlew resolve
# Can be used (and yq tasks removed) when https://github.com/kpramesh2212/openapi-merger-plugin/pull/11/files is merged
#- name: Check OpenAPI definitions match code
# run: git diff --exit-code

- name: Check OpenAPI definitions match code
run: |
mkdir -p git-regen/${{ matrix.apiGroup }}
files=($(ls resources/openapi/yaml/${{ matrix.apiGroup}}))
for file in ${files[@]}; do
yq -P 'sort_keys(..)' $rootDir/$file > git-regen/${{ matrix.apiGroup }}/$file
done
diff -r git-sorted git-regen
Publish-To-SwaggerHub:
# do NOT run on forks. The Org ("edc") is unique all across SwaggerHub
if: github.repository == 'eclipse-edc/Connector' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [ Verify-OpenAPI-Definitions ]
strategy:
matrix:
apiGroup: [ 'management-api', 'control-api' ]
env:
rootDir: resources/openapi/yaml/${{ matrix.apiGroup }}
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_TOKEN }}
SWAGGERHUB_USER: ${{ secrets.SWAGGERHUB_USER }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-build
- uses: actions/setup-node@v3

# merge together all api groups
- name: Generate API Specs
run: |
./gradlew -PapiTitle="${{ matrix.apiGroup }}" -PapiDescription="REST API documentation for the ${{ matrix.apiGroup }}" :mergeApiSpec --input=${{ env.rootDir }} --output=${{ matrix.apiGroup }}.yaml
# install swaggerhub CLI
- name: Install SwaggerHub CLI
run: npm i -g swaggerhub-cli

# create API, will fail if exists
- name: Create API
continue-on-error: true
run: |
swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/${{ matrix.apiGroup}} -f ${{ matrix.apiGroup }}.yaml --visibility=public --published=unpublish
# 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 }}/${{ matrix.apiGroup}} -f ${{ matrix.apiGroup }}.yaml --visibility=public --published=unpublish
24 changes: 0 additions & 24 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ jobs:
- name: Dependency analysis report
run: cat build/reports/dependency-analysis/build-health-report.txt

OpenAPI-Definitions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-build

- name: Save previous OpenAPI definition
run: yq -P 'sort_keys(..)' resources/openapi/openapi.yaml > openapi-git-sorted.yaml

- name: Generate OpenAPI definitions from code
run: |
./gradlew resolve
./gradlew mergeOpenApiFiles
# Can be used (and yq tasks removed) when https://github.com/kpramesh2212/openapi-merger-plugin/pull/11/files is merged
#- name: Check OpenAPI definitions match code
# run: git diff --exit-code

- name: Check OpenAPI definitions match code
run: |
yq -P 'sort_keys(..)' resources/openapi/openapi.yaml > openapi-ci-sorted.yaml
diff openapi-git-sorted.yaml openapi-ci-sorted.yaml
Unit-Tests:
runs-on: ubuntu-latest
env:
Expand Down
27 changes: 7 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

plugins {
`java-library`
// todo: remove once https://github.com/eclipse-edc/Connector/issues/2191 is complete
id("org.hidetake.swagger.generator") version "2.19.2"
}

val javaVersion: String by project
Expand All @@ -34,16 +32,15 @@ if (actualVersion == "unspecified") {
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
val edcGradlePluginsVersion: String by project
classpath("org.eclipse.edc.edc-build:org.eclipse.edc.edc-build.gradle.plugin:${edcGradlePluginsVersion}")
}
}

dependencies {
"swaggerUI"("org.webjars:swagger-ui:4.15.5")
}

allprojects {
apply(plugin = "${groupId}.edc-build")

Expand All @@ -68,8 +65,9 @@ allprojects {
scmUrl.set(edcScmUrl)
}
swagger {
title.set("EDC REST API")
description = "EDC REST APIs - merged by OpenApiMerger"
title.set((project.findProperty("apiTitle") ?: "EDC REST API") as String)
description =
(project.findProperty("apiDescription") ?: "EDC REST APIs - merged by OpenApiMerger") as String
outputFilename.set(project.name)
outputDirectory.set(file("${rootProject.projectDir.path}/resources/openapi/yaml"))
}
Expand Down Expand Up @@ -100,15 +98,4 @@ if (project.hasProperty("dependency.analysis")) {
configure<org.eclipse.edc.gradle.DependencyRulesPluginExtension> {
severity.set(project.property("dependency.analysis").toString())
}
}

// todo: remove once https://github.com/eclipse-edc/Connector/issues/2191 is complete
swaggerSources {
create("edc").apply {
setInputFile(file("./resources/openapi/openapi.yaml"))
ui(closureOf<org.hidetake.gradle.swagger.generator.GenerateSwaggerUI> {
outputDir = file("docs/swaggerui")
wipeOutputDir = true
})
}
}
}
7 changes: 7 additions & 0 deletions core/control-plane/control-plane-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("control-api")
}
}


publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ This context will expose the controllers defined by the following modules:
- `data-management-api`
- `data-plane-selector`
- `federated-catalog`
- `http-provisioner`.
- `http-provisioner`
- `observability-api`

Network context: intra-organization

Expand Down
6 changes: 6 additions & 0 deletions extensions/common/api/api-observability/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ dependencies {
testImplementation(project(":core:common:junit"))
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ dependencies {
testImplementation(project(":core:common:junit"))
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ dependencies {
testImplementation(libs.restAssured)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ dependencies {
testImplementation(libs.restAssured)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ dependencies {
testImplementation(libs.restAssured)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("control-api")
}
}

publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ dependencies {
testImplementation(libs.awaitility)
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}


publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ dependencies {
testImplementation(libs.jersey.multipart)
}

edcBuild {
swagger {
apiGroup.set("control-api")
}
}


publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ dependencies {
testImplementation(project(":core:common:junit"))
}

edcBuild {
swagger {
apiGroup.set("management-api")
}
}


publishing {
publications {
create<MavenPublication>(project.name) {
Expand Down
5 changes: 5 additions & 0 deletions extensions/data-plane/data-plane-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ dependencies {
testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
}
edcBuild {
swagger {
apiGroup.set("control-api")
}
}

publishing {
publications {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit eb5605a

Please sign in to comment.