Created
February 27, 2020 22:24
-
-
Save goneri/4d1ce451d27ed48126c3648cf6219bc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
from pprint import pprint | |
def path_to_module_name(path, value): | |
def is_element(i): | |
if i and not '{' in i: | |
return True | |
else: | |
return False | |
path = path.split('?')[0] | |
elements = [i for i in path.split('/') if is_element(i)] | |
if 'post' in value and value['post']['operationId'] == elements[-1]: | |
elements = elements[:-1] | |
module_name = '_'.join(elements) | |
return module_name | |
#assert path_to_module_name("/vcenter/vm/{vm}/hardware/serial/{port}") == "vcenter_vm_hardware_serial" | |
with open("vcenter.json", "r") as fd: | |
data = json.loads(fd.read()) | |
modules = {} | |
for k, v in data['definitions'].items(): | |
print(k) | |
print(v['type']) | |
# pprint(v) | |
for k, v in data['paths'].items(): | |
module = path_to_module_name(k, v) | |
print("PATH: {k} MODULE: {module}".format(k=k, module=module)) | |
if module not in modules: | |
modules[module] = {'operationIds': [], 'parameters': {}} | |
#print(v.keys()) | |
for verb, desc in v.items(): | |
#print(verb) | |
#pprint(desc) | |
if 'operationId' in desc: | |
modules[module]['operationIds'].append(desc['operationId']) | |
# TODO: parameters of the different HTTP verbs may be different, | |
# especially, the description | |
modules[module]['parameters'] = desc['parameters'] | |
pprint(modules[module]) | |
#pprint(modules) |
Author
goneri
commented
Feb 27, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment