-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (151 loc) · 5.22 KB
/
oas.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Run quality control on the (generated) Open API specification.
#
# The OAS must:
# * not be outdated w/r to the code from which it is generated
# * not have any linting errors
# * be valid input to generate a Postman collection
# * be valid input to generate SDKs in commonly used languages/frameworks
#
# When dealing with multiple versions, you can adapt this workflow to run a matrix and
# pass arguments down that way, and/or use a parent workflow to call this workflow for
# each matrix item. See https://docs.github.com/en/actions/sharing-automations/reusing-workflows
name: OpenAPI specification checks
on:
push:
branches:
- main
- stable/*
pull_request:
workflow_dispatch:
env:
DJANGO_SETTINGS_MODULE: open_producten.conf.ci
jobs:
generate:
name: Generate the API specification from code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
python-version: '3.11'
optimize-postgres: 'no'
setup-node: 'no'
# apt-packages: 'gettext postgresql-client' # the default
# npm-ci-flags: '--legacy-peer-deps' -> preferably use a .npmrc file
- name: Generate the API specification
run: ./bin/generate_api_schema.sh
- name: Store generated API specification for later use
uses: actions/upload-artifact@v4
with:
name: open_producten-oas
path: src/openapi.yaml
retention-days: 1
check-up-to-date:
name: Check for unexepected OAS changes
runs-on: ubuntu-latest
needs:
- generate
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- name: Check for OAS changes
run: |
diff openapi.yaml src/openapi.yaml
- name: Write failure markdown
if: ${{ failure() }}
run: |
echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo './bin/generate_api_schema.sh' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
lint:
name: Validate OAS
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install spectral
run: npm install -g @stoplight/spectral@5
- name: Run linter
run: spectral lint openapi.yaml
postman-collection:
name: Generate Postman collection
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install -g openapi-to-postmanv2
- name: Create tests folder
run: mkdir -p ./tests/postman
- name: Generate Postman collection
run: |
openapi2postmanv2 \
-s openapi.yaml \
-o ./tests/postman/collection.json \
--pretty
sdks:
name: Generate SDKs from API schema
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install -g @openapitools/openapi-generator-cli
- name: Validate schema
run: |
openapi-generator-cli \
validate -i openapi.yaml
- name: Generate Java client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/java \
-g java \
--additional-properties=dateLibrary=java8,java8=true,optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate .NET client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/net \
-g csharp \
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate Python client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/python \
-g python \
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false+