Matteo Scandolo | 431781c | 2017-09-06 15:33:07 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import os |
| 16 | from xosgenx.generator import XOSGenerator |
| 17 | |
| 18 | CWD = OUTPUT_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) |
| 19 | SWAGGER_DOCS_DIR = os.path.abspath(CWD + '/../swagger/specs') |
| 20 | ORCHESTRATION_DIR = os.path.abspath(CWD + "/../../../") |
| 21 | SERVICE_DIR = os.path.abspath(ORCHESTRATION_DIR + "/xos_services") |
| 22 | |
| 23 | XOS_XPROTO = os.path.abspath(CWD + "/../../xos/core/models/core.xproto") |
| 24 | |
| 25 | class Args: |
| 26 | pass |
| 27 | |
| 28 | def generate_swagger_docs(xproto): |
| 29 | |
| 30 | # if not os.path.isfile(xproto): |
| 31 | # print "ERROR: Couldn't find xproto file for %s at: %s" % (service, xproto) |
| 32 | # return |
| 33 | |
| 34 | print "Generating swagger docs for %s" % (xproto) |
| 35 | args = Args() |
| 36 | args.files = xproto |
| 37 | args.target = 'swagger.xtarget' |
| 38 | args.output = SWAGGER_DOCS_DIR |
| 39 | args.write_to_file = "single" |
| 40 | args.dest_file = "swagger.yaml" |
| 41 | args.quiet = False |
| 42 | try: |
| 43 | XOSGenerator.generate(args) |
| 44 | except Exception, e: |
| 45 | print "ERROR: Couldn't generate swagger specs" |
| 46 | print e |
| 47 | |
| 48 | def main(): |
| 49 | |
| 50 | # generate_swagger_docs('core', XOS_XPROTO) |
| 51 | protos = [XOS_XPROTO] |
| 52 | |
| 53 | services = os.listdir(SERVICE_DIR) |
| 54 | for service in services: |
| 55 | xos_folder = os.path.abspath(SERVICE_DIR + "/%s/xos" % service); |
| 56 | if os.path.isdir(xos_folder): |
| 57 | for file in os.listdir(xos_folder): |
| 58 | if 'xproto' in file and "monitoring" not in file: |
| 59 | proto = os.path.abspath(xos_folder + "/%s" % file) |
| 60 | # generate_swagger_docs(service, proto) |
| 61 | if os.path.isfile(proto): |
| 62 | protos.append(proto) |
| 63 | else: |
| 64 | print "ERROR: Couldn't find xproto file for %s at: %s" % (service, file) |
| 65 | else: |
| 66 | "WARNING: %s does not have an xproto file" % service |
| 67 | else: |
| 68 | print "WARNING: %s does not have an XOS folder" % service |
| 69 | generate_swagger_docs(protos) |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | main() |