Skip to content

Commit 1869913

Browse files
authored
fix bug where there no validation rules set (#1628)
* fix bug where there no validation rules set * update_invalid data models * ran pre-commit
1 parent a311e8e commit 1869913

File tree

4 files changed

+56
-37
lines changed

4 files changed

+56
-37
lines changed

schematic/schemas/create_json_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def _get_validation_rule_based_fields(
258258
- js_pattern: If the type is string the JSON Schema pattern
259259
"""
260260
js_is_array = False
261-
js_type = None
261+
js_type = explicit_js_type
262262
js_format = None
263263
js_minimum = None
264264
js_maximum = None
@@ -291,8 +291,6 @@ def _get_validation_rule_based_fields(
291291
f"derived from its validation rules: {validation_rules}"
292292
)
293293
raise ValueError(msg)
294-
# otherwise the explicit type is used
295-
js_type = explicit_js_type
296294
# If there is no explicit type...
297295
else:
298296
# and there is an implicit type...

tests/data/example.model.column_type_component.invalid.csv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ MockFilename,,,"Component, Filename",,FALSE,DataType,,,,
5656
JSONSchemaComponent,Component to hold attributes for testing JSON Schemas,,"Component, No Rules, No Rules Not Required, String, String Not Required, Enum, Enum Not Required, Date, URL, InRange, Regex, List, List Not Required, List Enum, List Enum Not Required, List String, List InRange",,FALSE,DataType,,,,
5757
No Rules,,,,,TRUE,DataProperty,,,,
5858
No Rules Not Required,,,,,FALSE,DataProperty,,,,
59-
String,,,,,TRUE,DataProperty,,,str error,
60-
String Not Required,,,,,FALSE,DataProperty,,,str error,
59+
String,,,,,TRUE,DataProperty,,,str error,string
60+
String Not Required,,,,,FALSE,DataProperty,,,str error,string
6161
Enum,,"ab, cd, ef, gh",,,TRUE,DataProperty,,,,
6262
Enum Not Required,,"ab, cd, ef, gh",,,FALSE,DataProperty,,,,
63-
Date,,,,,TRUE,DataProperty,,,date,
64-
URL,,,,,TRUE,DataProperty,,,url,
65-
InRange,,,,,TRUE,DataProperty,,,inRange 50 100,
66-
Range,,,,,TRUE,DataProperty,,,inRange 50 100,
63+
Date,,,,,TRUE,DataProperty,,,date,string
64+
URL,,,,,TRUE,DataProperty,,,url,string
65+
InRange,,,,,TRUE,DataProperty,,,inRange 50 100,number
66+
Regex,,,,,TRUE,DataProperty,,,regex search [a-f],string
6767
List,,,,,TRUE,DataProperty,,,list,
6868
List Not Required,,,,,FALSE,DataProperty,,,list,
6969
List Enum,,"ab, cd, ef, gh",,,TRUE,DataProperty,,,list,
7070
List Enum Not Required,,"ab, cd, ef, gh",,,FALSE,DataProperty,,,list,
71-
List String,,,,,TRUE,DataProperty,,,list::str,
72-
List InRange,,,,,TRUE,DataProperty,,,list::inRange 50 100,
71+
List String,,,,,TRUE,DataProperty,,,list::str,string
72+
List InRange,,,,,TRUE,DataProperty,,,list::inRange 50 100,number
7373
TypeDefinitionComponent,Component to check type specification,,"Component, String type, String type caps, Int type, Int type caps, Num type, Num type caps, Nan type, Missing type, Boolean type, Boolean type caps, Invalid type spec",,FALSE,DataType,,,,
7474
String type,,,,,TRUE,DataProperty,,,,string
7575
String type caps,,,,,TRUE,DataProperty,,,,STRING

tests/data/example.model.column_type_component.invalid.jsonld

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@
19321932
"schema:isPartOf": {
19331933
"@id": "http://schema.biothings.io"
19341934
},
1935+
"sms:columnType": "string",
19351936
"sms:displayName": "String",
19361937
"sms:required": "sms:true",
19371938
"sms:validationRules": [
@@ -1951,6 +1952,7 @@
19511952
"schema:isPartOf": {
19521953
"@id": "http://schema.biothings.io"
19531954
},
1955+
"sms:columnType": "string",
19541956
"sms:displayName": "String Not Required",
19551957
"sms:required": "sms:false",
19561958
"sms:validationRules": [
@@ -2066,15 +2068,18 @@
20662068
"rdfs:label": "InRange",
20672069
"rdfs:subClassOf": [
20682070
{
2069-
"@id": "bts:Thing"
2071+
"@id": "bts:DataProperty"
20702072
}
20712073
],
20722074
"schema:isPartOf": {
20732075
"@id": "http://schema.biothings.io"
20742076
},
2077+
"sms:columnType": "number",
20752078
"sms:displayName": "InRange",
2076-
"sms:required": "sms:false",
2077-
"sms:validationRules": []
2079+
"sms:required": "sms:true",
2080+
"sms:validationRules": [
2081+
"inRange 50 100"
2082+
]
20782083
},
20792084
{
20802085
"@id": "bts:Regex",
@@ -2083,15 +2088,18 @@
20832088
"rdfs:label": "Regex",
20842089
"rdfs:subClassOf": [
20852090
{
2086-
"@id": "bts:Thing"
2091+
"@id": "bts:DataProperty"
20872092
}
20882093
],
20892094
"schema:isPartOf": {
20902095
"@id": "http://schema.biothings.io"
20912096
},
2097+
"sms:columnType": "string",
20922098
"sms:displayName": "Regex",
2093-
"sms:required": "sms:false",
2094-
"sms:validationRules": []
2099+
"sms:required": "sms:true",
2100+
"sms:validationRules": [
2101+
"regex search [a-f]"
2102+
]
20952103
},
20962104
{
20972105
"@id": "bts:List",
@@ -2210,6 +2218,7 @@
22102218
"schema:isPartOf": {
22112219
"@id": "http://schema.biothings.io"
22122220
},
2221+
"sms:columnType": "string",
22132222
"sms:displayName": "List String",
22142223
"sms:required": "sms:true",
22152224
"sms:validationRules": [
@@ -2230,32 +2239,14 @@
22302239
"schema:isPartOf": {
22312240
"@id": "http://schema.biothings.io"
22322241
},
2242+
"sms:columnType": "number",
22332243
"sms:displayName": "List InRange",
22342244
"sms:required": "sms:true",
22352245
"sms:validationRules": [
22362246
"list",
22372247
"inRange 50 100"
22382248
]
22392249
},
2240-
{
2241-
"@id": "bts:Range",
2242-
"@type": "rdfs:Class",
2243-
"rdfs:comment": "TBD",
2244-
"rdfs:label": "Range",
2245-
"rdfs:subClassOf": [
2246-
{
2247-
"@id": "bts:DataProperty"
2248-
}
2249-
],
2250-
"schema:isPartOf": {
2251-
"@id": "http://schema.biothings.io"
2252-
},
2253-
"sms:displayName": "Range",
2254-
"sms:required": "sms:true",
2255-
"sms:validationRules": [
2256-
"inRange 50 100"
2257-
]
2258-
},
22592250
{
22602251
"@id": "bts:TypeDefinitionComponent",
22612252
"@type": "rdfs:Class",
@@ -2304,6 +2295,9 @@
23042295
},
23052296
{
23062297
"@id": "bts:Booleantypecaps"
2298+
},
2299+
{
2300+
"@id": "bts:Invalidtypespec"
23072301
}
23082302
],
23092303
"sms:validationRules": []
@@ -2486,6 +2480,23 @@
24862480
"sms:required": "sms:true",
24872481
"sms:validationRules": []
24882482
},
2483+
{
2484+
"@id": "bts:Invalidtypespec",
2485+
"@type": "rdfs:Class",
2486+
"rdfs:comment": "TBD",
2487+
"rdfs:label": "Invalidtypespec",
2488+
"rdfs:subClassOf": [
2489+
{
2490+
"@id": "bts:Thing"
2491+
}
2492+
],
2493+
"schema:isPartOf": {
2494+
"@id": "http://schema.biothings.io"
2495+
},
2496+
"sms:displayName": "Invalid type spec",
2497+
"sms:required": "sms:false",
2498+
"sms:validationRules": []
2499+
},
24892500
{
24902501
"@id": "bts:Invalidtypespec",
24912502
"@type": "rdfs:Class",

tests/unit/test_create_json_schema.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ def test_get_validation_rule_based_fields_no_explicit_type(
263263
@pytest.mark.parametrize(
264264
"validation_rules, explicit_type, expected_type, expected_is_array, expected_min, expected_max, expected_pattern, expected_format",
265265
[
266+
(
267+
[],
268+
JSONSchemaType.STRING,
269+
JSONSchemaType.STRING,
270+
False,
271+
None,
272+
None,
273+
None,
274+
None,
275+
),
266276
(
267277
["str"],
268278
JSONSchemaType.STRING,
@@ -314,7 +324,7 @@ def test_get_validation_rule_based_fields_no_explicit_type(
314324
JSONSchemaFormat.URI,
315325
),
316326
],
317-
ids=["String", "InRange", "Regex", "Date", "URL"],
327+
ids=["No rules", "String", "InRange", "Regex", "Date", "URL"],
318328
)
319329
def test_get_validation_rule_based_fields_with_explicit_type(
320330
validation_rules: list[str],

0 commit comments

Comments
 (0)