in api/yaml/openapi/combine.py [0:0]
def deconstruct():
yml = yaml.load(open(bpath + "/../openapi.yaml"))
noDefs = 0
print("Dumping paths into pages...")
for endpoint, defs in yml['paths'].items():
noDefs += 1
xendpoint = endpoint.replace("/api/", "")
ypath = os.path.abspath("%s/../../pages/%s.py" % (bpath, xendpoint))
print(ypath)
if os.path.isfile(ypath):
print("Editing %s" % ypath)
contents = open(ypath, "r").read()
contents = re.sub(r"^([#\n](?!\s*\"\"\")[^\r\n]*\n?)+", "", contents, re.MULTILINE)
odefs = yaml.dump(defs, default_flow_style=False)
odefs = "\n".join(["# %s" % line for line in odefs.split("\n")])
with open(ypath, "w") as f:
f.write(license)
f.write("########################################################################\n")
f.write("# OPENAPI-URI: %s\n" % endpoint)
f.write("########################################################################\n")
f.write(odefs)
f.write("\n########################################################################\n")
f.write("\n\n")
f.write(contents)
f.close()
print("Dumping security components...")
for basetype, bdefs in yml['components'].items():
for schema, defs in bdefs.items():
noDefs += 1
ypath = "%s/components/%s/%s.yaml" % (bpath, basetype, schema)
ydir = os.path.dirname(ypath)
if not os.path.isdir(ydir):
print("Making directory %s" % ydir)
os.makedirs(ydir, exist_ok = True)
with open(ypath, "w") as f:
f.write("########################################################################\n")
f.write("# %-68s #\n" % defs.get('summary', schema))
f.write("########################################################################\n")
f.write(yaml.dump(defs, default_flow_style=False))
f.close()
print("Dumped %u definitions." % noDefs)