Skip to content

Commit

Permalink
Don't expose avro namespaces in makedoc.
Browse files Browse the repository at this point in the history
Co-authored-by: Michael R. Crusoe <[email protected]>
  • Loading branch information
tetron and mr-c committed Nov 4, 2021
1 parent 3770e80 commit 4a5def8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions schema_salad/makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
_logger = logging.getLogger("salad")


def vocab_type_name(url: str) -> str:
"""Remove the avro namespace, if any."""
return avro_type_name(url).split(".")[-1]


def has_types(items: Any) -> List[str]:
r = [] # type: List[str]
if isinstance(items, MutableMapping):
Expand Down Expand Up @@ -317,7 +322,7 @@ def typefmt(
"https://w3id.org/cwl/salad#record",
"https://w3id.org/cwl/salad#enum",
):
frg = avro_type_name(tp["name"])
frg = vocab_type_name(tp["name"])
if tp["name"] in redirects:
return """<a href="{}">{}</a>""".format(redirects[tp["name"]], frg)
if tp["name"] in self.typemap:
Expand All @@ -337,7 +342,7 @@ def typefmt(
return f"""<a href="{redirects[tp]}">{redirects[tp]}</a>"""
if str(tp) in basicTypes:
return """<a href="{}">{}</a>""".format(
self.primitiveType, avro_type_name(str(tp))
self.primitiveType, vocab_type_name(str(tp))
)
frg2 = urldefrag(tp)[1]
if frg2 != "":
Expand Down Expand Up @@ -692,12 +697,15 @@ def arg_parser() -> argparse.ArgumentParser:
parser.add_argument("--brandstyle")
parser.add_argument("--brandinverse", default=False, action="store_true")
parser.add_argument("--primtype", default="#PrimitiveType")
parser.add_argument("--debug", action="store_true")
return parser


def main() -> None:
"""Shortcut entrypoint."""
args = arg_parser().parse_args()
if args.debug:
_logger.setLevel(logging.DEBUG)
makedoc(
sys.stdout,
args.schema,
Expand Down

0 comments on commit 4a5def8

Please sign in to comment.