Skip to content

Commit 311254f

Browse files
authored
Add OpenAPI sample generation. (#21)
Signed-off-by: Caroline Russell <[email protected]>
1 parent eef70dd commit 311254f

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

.github/workflows/generate_samples.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,19 @@ jobs:
130130
- name: Setup Node.js environment
131131
uses: actions/[email protected]
132132
with:
133-
node-version: 20
133+
node-version: 21
134+
135+
- name: Setup Python
136+
uses: actions/setup-python@v5
137+
with:
138+
python-version: 3.12
134139

135140
- name: Atom, cdxgen, sdkman installs
136141
run: |
137142
npm install -g @cyclonedx/cdxgen
138143
npm install -g @appthreat/atom
144+
python -m pip install --upgrade pip
145+
python -m pip install atom-tools
139146
curl -s "https://get.sdkman.io" | bash
140147
source "/home/runner/.sdkman/bin/sdkman-init.sh"
141148

generate.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def exec_on_repo(clone, output_dir, skip_build, slice_types, repo):
180180
lang = repo['language']
181181
loc = Path.cwd()
182182
repo_dir = repo['repo_dir']
183+
gen_api = repo['gen_api']
183184
commands = ''
184185

185186
if clone:
@@ -204,12 +205,26 @@ def exec_on_repo(clone, output_dir, skip_build, slice_types, repo):
204205
for stype in slice_types:
205206
slice_file = Path.joinpath(output_dir, lang, f'{project}-{stype}.json')
206207
atom_file = Path.joinpath(repo_dir, f'{project}.atom')
207-
cmd = ['atom', stype, '-l', lang, '-o', atom_file, '-s', slice_file, repo_dir]
208+
if stype == 'usages' and gen_api:
209+
commands += generate_openapi(project, output_dir, lang, slice_file, atom_file, repo_dir)
210+
continue
211+
cmd = ['atom', stype,'-l', lang, '-o', atom_file, '-s', slice_file, repo_dir]
208212
commands += f'\n{subprocess.list2cmdline(cmd)}'
209213
commands += '\n\n'
210214
return commands
211215

212216

217+
def generate_openapi(project, output_dir, lang, slice_file, atom_file, repo_dir):
218+
cmds = ''
219+
cmd = ['atom', 'usages', '--extract-endpoints', '-l', lang, '-o', atom_file, '-s', slice_file,
220+
repo_dir]
221+
cmds += f'\n{subprocess.list2cmdline(cmd)}'
222+
openapi_file = Path.joinpath(repo_dir, 'openapi.generated.json')
223+
cmd = ['mv', openapi_file, Path.joinpath(output_dir, lang, f'{project}_openapi.json')]
224+
cmds += f'\n{subprocess.list2cmdline(cmd)}'
225+
return cmds
226+
227+
213228
def read_csv(csv_file, langs, projects, clone_dir):
214229
"""
215230
Reads a CSV file and filters the data based on a list of languages.

sources.csv

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
project,link,language,pre_build_cmd,build_cmd
2-
"apollo","https://github.com/apolloconfig/apollo.git","java","sdk use maven 3.5.4;sdk use java 17.0.9-zulu","mvn -B clean compile -Dmaven.gitcommitid.skip=true -DskipTests=true"
3-
"karate","https://github.com/karatelabs/karate.git","java","sdk use java 21.ea.35-open","mvn -B clean install -P pre-release -pl '!karate-gatling' -Djavacpp.platform=linux-x86_64 -DskipTests=true"
4-
"piggymetrics","https://github.com/sqshq/piggymetrics.git","java","sdk use java 8.0.392-zulu","mvn -B -ntp package -DskipTests=true"
5-
"axios","https://github.com/axios/axios.git","javascript","",""
6-
"videojs","https://github.com/videojs/video.js.git","javascript","",""
7-
"sequelize","https://github.com/sequelize/sequelize.git","javascript","","yarn install"
8-
"ava","https://github.com/avajs/ava.git","javascript","","npm install"
9-
"spaCy","https://github.com/explosion/spaCy.git","python","",""
10-
"scrapy","https://github.com/scrapy/scrapy.git","python","","python -m venv venv; source venv/bin/activate && pip install ."
11-
"tinydb","https://github.com/msiemens/tinydb.git","python","","python -m venv venv; source venv/bin/activate && pip install ."
12-
"tornado","https://github.com/tornadoweb/tornado.git","python","","python -m venv venv; source venv/bin/activate && pip install ."
1+
project,link,language,pre_build_cmd,build_cmd,gen_api
2+
"apollo","https://github.com/apolloconfig/apollo.git","java","sdk use maven 3.5.4;sdk use java 17.0.9-zulu","mvn -B clean compile -Dmaven.gitcommitid.skip=true -DskipTests=true",""
3+
"java-sec-code","https://github.com/JoyChou93/java-sec-code.git","java","sdk use java 8.0.392-zulu","mvn -B clean compile -DskipTests=true",1
4+
"karate","https://github.com/karatelabs/karate.git","java","sdk use java 21.ea.35-open","mvn -B clean install -P pre-release -pl '!karate-gatling' -Djavacpp.platform=linux-x86_64 -DskipTests=true",""
5+
"piggymetrics","https://github.com/sqshq/piggymetrics.git","java","sdk use java 8.0.392-zulu","mvn -B -ntp package -DskipTests=true",1
6+
"axios","https://github.com/axios/axios.git","javascript","","",""
7+
"juiceshop","https://github.com/juice-shop/juice-shop.git","javascript","","npm install",1
8+
"node-goat","https://github.com/OWASP/NodeGoat.git","javascript","","npm install",1
9+
"sequelize","https://github.com/sequelize/sequelize.git","javascript","","yarn install",""
10+
"videojs","https://github.com/videojs/video.js.git","javascript","","",""
11+
"ava","https://github.com/avajs/ava.git","javascript","","npm install",""
12+
"django-goat","https://github.com/red-and-black/DjangoGoat.git","python","","python -m venv venv; source venv/bin/activate && pip install -r requirements_app.txt",1
13+
"spaCy","https://github.com/explosion/spaCy.git","python","","",""
14+
"scrapy","https://github.com/scrapy/scrapy.git","python","","python -m venv venv; source venv/bin/activate && pip install .",""
15+
"tinydb","https://github.com/msiemens/tinydb.git","python","","python -m venv venv; source venv/bin/activate && pip install .",""
16+
"tornado","https://github.com/tornadoweb/tornado.git","python","","python -m venv venv; source venv/bin/activate && pip install .",""

0 commit comments

Comments
 (0)