def generate_schema(entries, resources): resource_names = nlp.plural_extend(resources) model = {} hateoas_model = {} nlp_model = nlp.resource_analysis(resources, resource_names) model = nlp_model['model'] hateoas_model = nlp_model['graph'] with open('data.txt', 'w') as outfile: json.dump(model, outfile, indent=4) with open('graph.txt', 'w') as outfile: json.dump(hateoas_model, outfile, indent=4) # with open('data.txt') as data_file: # model = json.load(data_file) # with open('graph.txt') as data_file: # hateoas_model = json.load(data_file) graph.draw(hateoas_model) oas_schema = formatter.generate_swagger(model) oas_schema['info'] = {} for entry in entries: field = entry[0] text = entry[1].get() if field in ['title', 'description', 'version']: oas_schema['info'][field] = text elif field in ['basePath', 'host']: oas_schema[field] = text oas_schema['swagger'] = '2.0' oas_schema['schemes'] = ['https'] oas_schema['produces'] = ['application/json'] with open('swagger.json', 'w') as outfile: json.dump(oas_schema, outfile, indent=4) with open('swagger.yaml', 'w') as outfile: yaml.dump(oas_schema, outfile, indent=4)
nlp_model = {} with open(args['model']) as data_file: nlp_model = json.load(data_file) model = nlp_model['model'] resource_graph = nlp_model['resource_graph'] state_graph = nlp_model['state_graph'] elif args['folder']: print('Parsing resources...') resources = preprocessor.main(args['folder']) if not resources: print( 'No resources found, did you insert the correct resources folder?') sys.exit() resource_names = nlp.plural_extend(resources) print('Processing resources...') nlp_model = nlp.resource_analysis(resources, resource_names) model = nlp_model['model'] resource_graph = nlp_model['resource_graph'] state_graph = nlp_model['state_graph'] with open('output_files/nlp_model.json', 'w') as outfile: json.dump(nlp_model, outfile, indent=4) print('Generating files...') graph.draw(resource_graph, state_graph, args['fixgraph']) oas_schema = formatter.generate_swagger(model) oas_schema['swagger'] = '2.0' oas_schema['info'] = { "title": oas_settings['INFO']['title'], "description": oas_settings['INFO']['description'], "version": oas_settings['INFO']['version'],