Skip to content

Commit c2e36c4

Browse files
authored
Merge pull request #69 from madpah/feat/openapi-draft
beginning of draft OpenApi Spec for TEA
2 parents 4cb362c + d7ca7ee commit c2e36c4

11 files changed

+797
-0
lines changed

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @oej
2+
* @madpah
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Build & Test Generated API Clients
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
OPEN_API_GENERATOR_VERSION: 'v7.9.0'
14+
PYTHON_VERSION_DEFAULT: '3.12'
15+
POETRY_VERSION: '1.8.1'
16+
17+
jobs:
18+
generate-library-code:
19+
name: Generate Library Code ${{ matrix.language }}
20+
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
language: ['go', 'java-webclient', 'python', 'typescript']
24+
steps:
25+
- name: Checkout
26+
# see https://github.com/actions/checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Create Output Directory
30+
run: mkdir out/${{ matrix.language }}
31+
32+
- name: Run OpenAPI Generator
33+
uses: addnab/docker-run-action@v3
34+
with:
35+
image: openapitools/openapi-generator-cli:${{ env.OPEN_API_GENERATOR_VERSION }}
36+
options: -v ${{ github.workspace }}:/local
37+
run: /usr/local/bin/docker-entrypoint.sh batch --clean /local/spec/generators/${{ matrix.language }}.yaml
38+
39+
- name: Copy our scripts across too
40+
run: cp spec/generators/*.sh ./out/${{ matrix.language }}
41+
42+
- name: Save to Cache
43+
uses: actions/cache/save@v4
44+
with:
45+
path: out/${{ matrix.language }}
46+
key: '${{ matrix.language }}-${{ github.run_id }}'
47+
48+
validate-go:
49+
name: Validate Go Library
50+
runs-on: ubuntu-latest
51+
needs: generate-library-code
52+
53+
steps:
54+
- name: Setup Go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version: 1.22
58+
59+
- name: Get generated code from cache
60+
uses: actions/cache/restore@v4
61+
with:
62+
path: out/go
63+
key: 'go-${{ github.run_id }}'
64+
fail-on-cache-miss: true
65+
66+
- name: Build Go API Client
67+
run: go build -v ./
68+
working-directory: out/go
69+
70+
- name: Install test dependencies & run generated tests
71+
run: |
72+
go get github.com/stretchr/testify/assert
73+
go test -v ./test/
74+
working-directory: out/go
75+
76+
validate-java-webclient:
77+
name: Validate Java Webclient
78+
runs-on: ubuntu-latest
79+
needs: generate-library-code
80+
81+
steps:
82+
- name: Set up JDK 17 for x64
83+
uses: actions/setup-java@v4
84+
with:
85+
java-version: '17'
86+
distribution: 'temurin'
87+
architecture: x64
88+
89+
- name: Set up Maven
90+
uses: stCarolas/setup-maven@v5
91+
with:
92+
maven-version: 3.9.4
93+
94+
- name: Get generated code from cache
95+
uses: actions/cache/restore@v4
96+
with:
97+
path: out/java-webclient
98+
key: 'java-webclient-${{ github.run_id }}'
99+
fail-on-cache-miss: true
100+
101+
- name: Build & Test Java Webclient API Client
102+
run: |
103+
./update-pom.sh pom.xml
104+
mvn clean test
105+
working-directory: out/java-webclient
106+
107+
validate-python:
108+
name: Validate Python Library
109+
runs-on: ubuntu-latest
110+
needs: generate-library-code
111+
112+
steps:
113+
- name: Set up Python
114+
uses: actions/setup-python@v5
115+
with:
116+
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
117+
118+
- name: Install poetry
119+
# see https://github.com/marketplace/actions/setup-poetry
120+
uses: Gr1N/setup-poetry@v9
121+
with:
122+
poetry-version: ${{ env.POETRY_VERSION }}
123+
124+
- name: Get generated code from cache
125+
uses: actions/cache/restore@v4
126+
with:
127+
path: out/python
128+
key: 'python-${{ github.run_id }}'
129+
fail-on-cache-miss: true
130+
131+
- name: Install dependencies
132+
run: poetry install --no-root
133+
working-directory: out/python
134+
135+
- name: Ensure build successful
136+
run: poetry build
137+
working-directory: out/python
138+
139+
- name: Run Tests
140+
run: |
141+
pip install -r test-requirements.txt
142+
poetry run pytest
143+
working-directory: out/python
144+
145+
validate-typescript:
146+
name: Validate Typescript Library
147+
runs-on: ubuntu-latest
148+
needs: generate-library-code
149+
150+
steps:
151+
- name: Setup Node
152+
uses: actions/setup-node@v4
153+
with:
154+
node-version: latest
155+
156+
- name: Get generated code from cache
157+
uses: actions/cache/restore@v4
158+
with:
159+
path: out/typescript
160+
key: 'typescript-${{ github.run_id }}'
161+
fail-on-cache-miss: true
162+
163+
- name: Build Typescript API Client
164+
run: npm i && npm run build
165+
working-directory: out/typescript

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea/
2+
out

spec/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TEA OpenAPI Spec
2+
3+
The OpenAPI 3.1 specification for the Transparency Exchange API is available in [openapi.json](./openapi.json).
4+
5+
- [Generating API Clients from OpenAPI Spec](#generating-api-clients-from-openapi-spec)
6+
7+
## Generating API Clients from OpenAPI Spec
8+
9+
We use the OpenAPI Generator with configuration per language/framework in the `generators` folder. An example is:
10+
11+
```
12+
docker run --rm -v "$(PWD):/local" openapitools/openapi-generator-cli batch --clean /local/spec/generators/typescript.yaml
13+
```

spec/generators/common.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
inputSpec: /local/spec/openapi.json
2+
gitUserId: CycloneDX
3+
gitRepoId: transparency-exchange-api
4+
5+
globalProperties:
6+
skipFormModel: false

spec/generators/go.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'!include': 'common.yaml'
2+
outputDir: /local/out/go
3+
generatorName: go
4+
gitRepoId: transparency-exchange-api-go
5+
additionalProperties:
6+
goImportAlias: tea_client
7+
packageName: tea_client

spec/generators/java-webclient.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'!include': 'common.yaml'
2+
outputDir: /local/out/java-webclient
3+
generatorName: java
4+
additionalProperties:
5+
library: webclient
6+
artifactDescription: Transparency Exchange API Java Webclient
7+
artifactId: tea-api-webclient
8+
artifactUrl: https://github.com/CycloneDX/transparency-exchange-api
9+
invokerPackage: org.cyclonedx.tea.webclient
10+
apiPackage: org.cyclonedx.tea.webclient.api
11+
modelPackage: org.cyclonedx.tea.webclient.model
12+
developerEmail: community@sonatype.com
13+
developerName: OWASP Foundation
14+
developerOrganization: OWASP Foundation
15+
developerOrganizationUrl: https://cyclonedx.org/
16+
groupId: org.cyclonedx.tea
17+
licenseName: Apache-2.0
18+
licenseUrl: https://github.com/CycloneDX/transparency-exchange-api/blob/main/LICENSE
19+
scmConnection: scm:git:git@github.com:CycloneDX/transparency-exchange-api.git
20+
scmDeveloperConnection: scm:git:git@github.com:CycloneDX/transparency-exchange-api.git
21+
scmUrl: https://github.com/CycloneDX/transparency-exchange-api
22+
useJakartaEe: true
23+
asyncNative: true
24+
generateBuilders: true
25+
parentGroupId: org.sonatype.buildsupport
26+
parentArtifactId: public-parent
27+
parentVersion: 50

spec/generators/python.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'!include': 'common.yaml'
2+
outputDir: /local/out/python
3+
generatorName: python
4+
additionalProperties:
5+
library: urllib3
6+
licenseInfo: "Apache-2.0"
7+
packageName: "tea-api-client"
8+
projectName: "Transparency Exchange API (TEA)"

spec/generators/typescript.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'!include': 'common.yaml'
2+
outputDir: /local/out/typescript
3+
generatorName: typescript-fetch
4+
additionalProperties:
5+
npmName: "@cyclonedx/tea-api-client"
6+
supportsES6: true
7+
withInterfaces: true

spec/generators/update-pom.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Check if the file path is provided
4+
if [ -z "$1" ]; then
5+
echo "Usage: $0 <path-to-xml-file>"
6+
exit 1
7+
fi
8+
9+
# File path
10+
FILE=$1
11+
12+
# Use sed to remove the <build> tag and its content
13+
sed -i.bak '/<build>/,/<\/build>/d' "$FILE"
14+
15+
echo "The <build> tag has been removed from $FILE. A backup has been saved as $FILE.bak."

0 commit comments

Comments
 (0)