Merge "Adding POSCA build job for Bottlenecks"
[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 if __name__ == '__main__':
37     parser = argparse.ArgumentParser(description='Create \
38                                       Swagger Spec documentation')
39     parser.add_argument('-ru', '--resource-listing-url',
40                         type=str,
41                         required=False,
42                         default='http://testresults.opnfv.org/auto/swagger/spec.json',
43                         help='Resource Listing Spec File')
44     parser.add_argument('-au', '--api-declaration-url',
45                         type=str,
46                         required=False,
47                         default='http://testresults.opnfv.org/auto/swagger/spec',
48                         help='API Declaration Spec File')
49     parser.add_argument('-o', '--output-directory',
50                         required=True,
51                         default='./',
52                         help='Output Directory where the \
53                                 file should be stored')
54     main(parser.parse_args())