Skip to content

Commit

Permalink
codegen: place 'class' field early
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Sep 8, 2021
1 parent 2c81f4e commit 8cbc01c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions schema_salad/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from .schema import shortname
from .utils import aslist

FIELD_SORT_ORDER = ["id", "class", "name"]


def codegen(
lang: str,
Expand Down Expand Up @@ -102,7 +104,14 @@ def codegen(
)
gen.add_vocab(shortname(rec["name"]), rec["name"])

for field in rec.get("fields", []):
sorted_fields = sorted(
rec.get("fields", []),
key=lambda i: FIELD_SORT_ORDER.index(i["name"].split("/")[-1])
if i["name"].split("/")[-1] in FIELD_SORT_ORDER
else 100,
)

for field in sorted_fields:
if field.get("jsonldPredicate") == "@id":
subscope = field.get("subscope")
fieldpred = field["name"]
Expand All @@ -115,7 +124,7 @@ def codegen(
)
break

for field in rec.get("fields", []):
for field in sorted_fields:
optional = bool("https://w3id.org/cwl/salad#null" in field["type"])
type_loader = gen.type_loader(field["type"])
jld = field.get("jsonldPredicate")
Expand Down

0 comments on commit 8cbc01c

Please sign in to comment.