Skip to content

Commit 2abc7f4

Browse files
author
Peter Amstutz
committed
Doc generation understands mapSubject/mapPredicate -> map<>
1 parent 93ed1fb commit 2abc7f4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

schema_salad/makedoc.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,27 @@ def __init__(self, toc, j, renderlist, redirects):
213213
("docAfter" not in f))):
214214
self.render_type(f, 1)
215215

216-
def typefmt(self, tp, redirects, nbsp=False):
216+
def typefmt(self, tp, redirects, nbsp=False, jsonldPredicate=None):
217217
# type: (Any, Dict[str, str], bool) -> Union[str, unicode]
218218
global primitiveType
219219
if isinstance(tp, list):
220220
if nbsp and len(tp) <= 3:
221-
return "&nbsp;|&nbsp;".join([self.typefmt(n, redirects) for n in tp])
221+
return "&nbsp;|&nbsp;".join([self.typefmt(n, redirects, jsonldPredicate=jsonldPredicate) for n in tp])
222222
else:
223223
return " | ".join([self.typefmt(n, redirects) for n in tp])
224224
if isinstance(tp, dict):
225225
if tp["type"] == "https://w3id.org/cwl/salad#array":
226-
return "array&lt;%s&gt;" % (self.typefmt(tp["items"], redirects, nbsp=True))
226+
ar = "array&lt;%s&gt;" % (self.typefmt(tp["items"], redirects, nbsp=True))
227+
if jsonldPredicate and "mapSubject" in jsonldPredicate:
228+
if "mapPredicate" in jsonldPredicate:
229+
ar += " | map&lt;%s.%s,&nbsp;%s.%s&gt" % (self.typefmt(tp["items"], redirects),
230+
jsonldPredicate["mapSubject"],
231+
self.typefmt(tp["items"], redirects),
232+
jsonldPredicate["mapPredicate"])
233+
ar += " | map&lt;%s.%s,&nbsp;%s&gt" % (self.typefmt(tp["items"], redirects),
234+
jsonldPredicate["mapSubject"],
235+
self.typefmt(tp["items"], redirects))
236+
return ar
227237
if tp["type"] in ("https://w3id.org/cwl/salad#record", "https://w3id.org/cwl/salad#enum"):
228238
frg = schema.avro_name(tp["name"])
229239
if tp["name"] in redirects:
@@ -345,7 +355,8 @@ def extendsfrom(item, ex):
345355
rfrg = schema.avro_name(i["name"])
346356
tr = "<td><code>%s</code></td><td>%s</td><td>%s</td>"\
347357
"<td>%s</td>" % (
348-
rfrg, self.typefmt(tp, self.redirects),
358+
rfrg, self.typefmt(tp, self.redirects,
359+
jsonldPredicate=i.get("jsonldPredicate")),
349360
"Optional" if opt else "Required",
350361
mistune.markdown(desc))
351362
if opt:

0 commit comments

Comments
 (0)