Skip to content

Commit e0c7734

Browse files
authored
Fix: allow missing fields field in SaladRecordSchema (#551)
* Fix: allow missing `fields` field in SaladRecordSchema The field SaladRecordSchema::fields is optional. see: - https://www.commonwl.org/v1.2/SchemaSalad.html#SaladRecordSchema - https://github.com/common-workflow-language/schema_salad/blob/d123d9c81fd22337e37a0b7e59f92019b0fdae3f/schema_salad/metaschema/metaschema_base.yml#L111
1 parent 8c92be2 commit e0c7734

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

schema_salad/avro/schema.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ def __init__(
520520
other_props: Optional[PropsType] = None,
521521
) -> None:
522522
# Ensure valid ctor args
523-
if fields is None:
524-
fail_msg = "Record schema requires a non-empty fields property."
525-
raise SchemaParseException(fail_msg)
526-
elif not isinstance(fields, list):
523+
if not isinstance(fields, list):
527524
fail_msg = "Fields property must be a list of Avro schemas."
528525
raise SchemaParseException(fail_msg)
529526

@@ -622,7 +619,7 @@ def make_avsc_object(json_data: JsonDataType, names: Optional[Names] = None) ->
622619
symbols = cast(List[str], symbols)
623620
return EnumSchema(name, namespace, symbols, names, doc, other_props)
624621
if atype in ["record", "error"]:
625-
fields = json_data.get("fields")
622+
fields = json_data.get("fields", [])
626623
if not isinstance(fields, list):
627624
raise SchemaParseException(
628625
'"fields" for type {} must be a list of mappings: {}'.format(

schema_salad/tests/test_java_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from schema_salad import codegen
66
from schema_salad.schema import load_schema
77

8-
from .util import cwl_file_uri, metaschema_file_uri, get_data
8+
from .util import cwl_file_uri, get_data, metaschema_file_uri
99

1010

1111
def test_cwl_gen(tmp_path: Path) -> None:

schema_salad/tests/test_misc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from schema_salad.avro.schema import Names
2+
from schema_salad.schema import load_schema
3+
4+
from .util import get_data
5+
6+
7+
def test_misc() -> None:
8+
path = get_data("tests/test_schema/no_field_schema.yml")
9+
assert path
10+
document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(path)
11+
assert isinstance(avsc_names, Names)

schema_salad/tests/test_python_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from schema_salad.avro.schema import Names
99
from schema_salad.schema import load_schema
1010

11-
from .util import cwl_file_uri, metaschema_file_uri, basket_file_uri
11+
from .util import basket_file_uri, cwl_file_uri, metaschema_file_uri
1212

1313

1414
def test_cwl_gen(tmp_path: Path) -> None:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- name: EmptyType
2+
documentRoot: true
3+
type: record

schema_salad/tests/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Optional, Text
33

44
from pkg_resources import Requirement, ResolutionError, resource_filename
5+
56
from schema_salad import ref_resolver
67

78

0 commit comments

Comments
 (0)