-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathworkflow2yaml.py
51 lines (37 loc) · 1.54 KB
/
workflow2yaml.py
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
#!/usr/bin/python3
import sys
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
import os
import sys
import re
import json
import requests
import json
import yaml
############################################ Main ############################################################
def main():
#### Parse command line options
import argparse
argparser = argparse.ArgumentParser(description='Fetch and convert the latest workflow operations definitions and convert to YAML')
argparser.add_argument('--verbose', action='count', help='If set, print more information about ongoing processing' )
params = argparser.parse_args()
response_content = requests.get('http://standards.ncats.io/operation/1.3.2/schema', headers={'accept': 'application/json'})
status_code = response_content.status_code
if status_code != 200:
eprint("Cannot fetch operation.json")
return
#### Unpack the response content into a dict
try:
response_dict = response_content.json()
except:
eprint("Cannot decode request response")
return
print(json.dumps(response_dict,indent=2))
response_dict['components'] = {}
response_dict['components']['schemas'] = response_dict['$defs']
del response_dict['$defs']
# replace $def with components/schemas for all of this list items in anyOf
response_dict['anyOf'] = [{'$ref': x['$ref'].replace('$defs','components/schemas')} for x in response_dict['anyOf']]
print(yaml.dump(response_dict))
return
if __name__ == "__main__": main()