Update table headers in the reporting page
[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     if os.system(cmd) == 0:
32         exit(0)
33     else:
34         exit(1)
35
36
37 if __name__ == '__main__':
38     parser = argparse.ArgumentParser(description='Create \
39                                       Swagger Spec documentation')
40     parser.add_argument('-ru', '--resource-listing-url',
41                         type=str,
42                         required=False,
43                         default=('http://testresults.opnfv.org'
44                                  '/test/swagger/resources.json'),
45                         help='Resource Listing Spec File')
46     parser.add_argument('-au', '--api-declaration-url',
47                         type=str,
48                         required=False,
49                         default=('http://testresults.opnfv.org'
50                                  '/test/swagger/APIs'),
51                         help='API Declaration Spec File')
52     parser.add_argument('-o', '--output-directory',
53                         required=True,
54                         default='./',
55                         help='Output Directory where the \
56                                 file should be stored')
57     main(parser.parse_args())