Merge "utils/jenkins-jnlp-connect.sh: Make sure the pid directory exists"
[releng.git] / utils / test / testapi / htmlize / htmlize.py
1 #!/usr/bin/env python
2
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 import argparse
9 import requests
10 import json
11 import os
12
13
14 def main(args):
15
16     # Merging two specs
17     api_response = requests.get(args.api_declaration_url)
18     api_response = json.loads(api_response.content)
19     resource_response = requests.get(args.resource_listing_url)
20     resource_response = json.loads(resource_response.content)
21     resource_response['models'] = api_response['models']
22     resource_response['apis'] = api_response['apis']
23
24     # Storing the swagger specs
25     with open('specs.json', 'w') as outfile:
26         json.dump(resource_response, outfile)
27
28     # Generating html page
29     cmd = 'java -jar swagger-codegen-cli.jar generate \
30         -i specs.json -l html2 -o %s' % (args.output_directory)
31     os.system(cmd)
32
33 if __name__ == '__main__':
34     parser = argparse.ArgumentParser(description='Create \
35                                       Swagger Spec documentation')
36     parser.add_argument('-ru', '--resource-listing-url',
37                         type=str,
38                         required=False,
39                         default='http://localhost:8000/swagger/spec.json',
40                         help='Resource Listing Spec File')
41     parser.add_argument('-au', '--api-declaration-url',
42                         type=str,
43                         required=False,
44                         default='http://localhost:8000/swagger/spec',
45                         help='API Declaration Spec File')
46     parser.add_argument('-o', '--output-directory',
47                         required=True,
48                         default='./',
49                         help='Output Directory where the \
50                                 file should be stored')
51     main(parser.parse_args())