19from __future__
import print_function
25 print(
"Pystache required. Please sudo pip install pystache.", file=sys.stderr)
30from asterisk_processor
import AsteriskProcessor
31from argparse
import ArgumentParser
as ArgParser
32from swagger_model
import ResourceListing
33from transform
import Transform
35TOPDIR = os.path.dirname(os.path.abspath(__file__))
39 """Helper to get a file relative to the script's directory
41 @parm file: Relative file path.
43 return os.path.join(TOPDIR, file)
47 'Command line utility to export ARI documentation to markdown'
50 parser = ArgParser(description=description)
51 parser.add_argument(
'--resources', type=str, default=
"rest-api/resources.json",
52 help=
"resources.json file to process", required=
False)
53 parser.add_argument(
'--source-dir', type=str, default=
".",
54 help=
"Asterisk source directory", required=
False)
55 parser.add_argument(
'--dest-dir', type=str, default=
"doc/rest-api",
56 help=
"Destination directory", required=
False)
57 parser.add_argument(
'--docs-prefix', type=str, default=
"../",
58 help=
"Prefix to apply to links", required=
False)
60 args = parser.parse_args()
64 renderer = pystache.Renderer(search_dirs=[TOPDIR], missing_tags=
'strict')
69 '%s/{{name_title}}_REST_API.md' % args.dest_dir),
71 'res/res_ari_{{c_name}}.c'),
73 'res/ari/resource_{{c_name}}.h'),
75 'res/ari/resource_{{c_name}}.c', overwrite=
False),
78 RESOURCES_TRANSFORMS = [
80 '%s/Asterisk_REST_Data_Models.md' % args.dest_dir),
83 'res/ari/ari_model_validators.h'),
85 'res/ari/ari_model_validators.c'),
89 base_dir = os.path.dirname(args.resources)
91 for api
in resources.apis:
92 api.load_api_declaration(base_dir, processor)
95 for api
in resources.apis:
96 for transform
in API_TRANSFORMS:
97 transform.render(renderer, api, args.source_dir)
98 for transform
in RESOURCES_TRANSFORMS:
99 transform.render(renderer, resources, args.source_dir)
101if __name__ ==
"__main__":
102 sys.exit(
main(sys.argv)
or 0)
static int load_file(const char *filename, char **ret)
Read a TEXT file into a string and return the length.