def view_docstring(self, fulldata, d, rename_dict=rename_dict): if "parameters" not in d: return None parameters = defaultdict(list) for p in d["parameters"]: p = self.resolve_ref(fulldata, p) parameters[p["in"]].append(p) # "query", "header", "path", "formData" or "body" m = Module() body = parameters.pop("body", None) for name, vs in parameters.items(): pyramid_name = rename_dict.get(name) or name m.stmt(pyramid_name) m.stmt("") with m.scope(): for v in vs: name = v.get("name", "") description = v.get("description", "-") if description: description = " {}".format(description) extra = v.copy() extra.pop("in", None) extra.pop("name", None) extra.pop("description", None) if extra: extra_string = " `{}`".format(json.dumps(extra)) else: extra_string = "" m.stmt("* {name!r}{description}{extra}".format( name=name, description=description, extra=extra_string)) if body: m.stmt("") m.stmt(rename_dict["body"]) m.stmt("\n```") with m.scope(): schema = self.resolve_ref(fulldata, body[0]["schema"]) json_str = json.dumps(schema, ensure_ascii=False, indent=2) for line in json_str.split("\n"): m.stmt(line) m.stmt("```") return str(m)
from prestring import Module sm = Module() with sm.scope(): sm.stmt("- foo") sm.stmt("- bar") sm.stmt("- boo") m = Module() m.stmt("// start") with m.scope(): m.stmt("itemize") m.submodule(sm, newline=False) m.stmt("// end") print(m)
from prestring import Module m = Module() m.stmt("// start") with m.scope(): m.stmt("itemize") sm = m.submodule("") m.stmt("// end") with sm.scope(): sm.stmt("- foo") sm.stmt("- bar") sm.stmt("- boo") print(m)
def emit_internal(m: Module) -> None: with m.scope(): m.stmt("- foo") m.stmt("- bar") m.stmt("- boo")