Skip to content

Commit

Permalink
fix(validation): updates to schema
Browse files Browse the repository at this point in the history
1) Fixes problem in Type: validation (where 'Type: enum' was not
called invalid, although 'enum' is not in the list of
simple types) - correctly expressing alternative, mutual exclusive
properties in the schema.

2) Fixes the #/def/url matcher regexp which probably had never been
in correct JS form (required by the JSONSchema spec)

3) Fixes test (001) of the CRDC example MDF, which did not 'assert'
the result of validate_instance_with_schema and so was a no-op.
(once asserted, I found the issue with the URL regexp)

4) Adds test that 'Type: enum' validation is fixed
  • Loading branch information
majensen committed Nov 11, 2024
1 parent 82bdeac commit 6f50cc8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
4 changes: 3 additions & 1 deletion python/tests/samples/test-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Nodes:
- disease
Relationships:
of_case:
Props: ~
Mul: one_to_one
Ends:
- Src: sample
Expand All @@ -44,6 +45,7 @@ Relationships:
Value: 'of_case'
Origin: 'CTDC'
of_sample:
Props: ~
Mul: one_to_one
Ends:
- Src: file
Expand Down Expand Up @@ -73,7 +75,7 @@ PropDefinitions:
patient_id:
Type: string
sample_type:
Type:
Enum:
- normal
- tumor
amount:
Expand Down
27 changes: 24 additions & 3 deletions python/tests/test_001validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
tdir / "samples" / "ctdc_model_properties_enum_and_type_kw.yaml",
]
crdc_dh_file = tdir / "samples" / "crdc_datahub_mdf.yml"
test_model_file = tdir / "samples" / "test-model.yml"
test_model_file_bad_type_value = tdir / "samples" / "test-model-bad-type-value-1.yml"


def test_with_all_file_args():
Expand Down Expand Up @@ -97,15 +99,15 @@ def test_list_type():
assert v
assert v.load_and_validate_schema()
assert v.load_and_validate_yaml()
v.validate_instance_with_schema()
assert v.validate_instance_with_schema()


def test_enum_vs_type_kw():
v = MDFValidator(test_latest_schema, *test_enum_kw_files)
assert v
assert v.load_and_validate_schema()
assert v.load_and_validate_yaml()
v.validate_instance_with_schema()
assert v.validate_instance_with_schema()


def test_enum_and_type_kw():
Expand All @@ -122,4 +124,23 @@ def test_validate_crdc_model():
assert v
assert v.load_and_validate_schema()
assert v.load_and_validate_yaml()
v.validate_instance_with_schema()
assert v.validate_instance_with_schema()


def test_example_model():
v = MDFValidator(test_latest_schema, test_model_file)
assert v
assert v.load_and_validate_schema()
assert v.load_and_validate_yaml()
assert v.validate_instance_with_schema()


def test_bad_type_value():
# test that 'Type: enum' is invalid
v = MDFValidator(test_latest_schema, test_model_file_bad_type_value,
raise_error = True)
assert v
assert v.load_and_validate_schema()
assert v.load_and_validate_yaml()
with pytest.raises(ValidationError):
v.validate_instance_with_schema()
41 changes: 19 additions & 22 deletions schema/mdf-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defs:
enumType (an array - could be size 1; or a reference to value
domain api)
items:
oneOf:
anyOf:
-
type:
string
Expand Down Expand Up @@ -388,36 +388,33 @@ defs:
found in the specified Enum. This is useful when the acceptable value list has not
been solidified in initial development.
type: boolean
oneOf:
-
Type:
description: |
Type:
description: |
Property values can have (1) simple types (number, integer, string
datetime, or --if necessary-- \'TBD\'; (2) a number_with_units type
(e.g., { \"value_type\":\"integer\", \"units\":\"mm\" }); (3) a regular
expression that a (string) value must match; (4) an enumeration
of acceptable values, or a url or path fragment to an api that will validate against
such a list.
oneOf:
-
$ref: "#/defs/simpleType"
-
$ref: "#/defs/numberWithUnits"
-
$ref: "#/defs/regex"
-
$ref: "#/defs/url"
-
$ref: "#/defs/enumType"
-
$ref: "#/defs/listType"
-
Enum:
description: |
oneOf:
-
$ref: "#/defs/simpleType"
-
$ref: "#/defs/numberWithUnits"
-
$ref: "#/defs/regex"
-
$ref: "#/defs/url"
-
$ref: "#/defs/enumType"
-
$ref: "#/defs/listType"
Enum:
description: |
Same as Type:[<strings>], defines an enumeration. This keyword is meant to assist
readability. Either one of Type or Enum may be present in a property definition,
but not both.
$ref: "#/defs/enumType"
$ref: "#/defs/enumType"
Tags:
$ref: "#/defs/tagsSpec"
Term:
Expand Down

0 comments on commit 6f50cc8

Please sign in to comment.