forked from getsling/flask-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_swagger_spec.py
33 lines (28 loc) · 983 Bytes
/
build_swagger_spec.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
import os
import sys
import argparse
import json
import pkg_resources
from flask_swagger import swagger
sys.path.append(os.getcwd())
parser = argparse.ArgumentParser()
parser.add_argument('app', help='the flask app to swaggerify')
#parser.add_argument('--definitions', help='json definitions file')
parser.add_argument('--template', help='template spec to start with')
parser.add_argument('--out-dir', default=None, help='the directory to output to')
args = parser.parse_args()
def run():
template = args.template
app = pkg_resources.EntryPoint.parse("x=%s" % args.app).load(False)
if template is not None:
with open(template, 'r') as f:
spec = swagger(app, template=json.loads(f.read()))
else:
spec = swagger(app)
if args.out_dir is None:
print json.dumps(spec, indent=4)
else:
with open("%s/swagger.json" % args.out_dir, 'w') as f:
f.write(json.dumps(spec, indent=4))
f.close()
run()