Closed theisuru closed 2 weeks ago
A solution is the attributes
property will be defined in the following way:
tag
, value
, units
propertiestag
is en enum that can accept all synonyms of all attribute tags
"tag": {
"type": "string",
"enum": [
"tag1", "Tag1", "tag_one",
"tag2", "Tag2", "tag_two",
...
]
}
tag
and value
properties are required, units
is optionalvalue
is conditional using oneOf
according to the value of `taga:
"value": {
"oneOf": [
{
"if": {
"properties": {
"tag": {
"enum": ["tag1", "Tag1", "tag_one"]
}
}
},
"then": {
"type": "string",
"pattern": "^[A-Za-z]+$" // Example: Only alphabets
}
},
{
"if": {
"properties": {
"tag": {
"enum": ["tag2", "Tag2", "tag_two"]
}
}
},
"then": {
"type": "integer",
"minimum": 0 // Example: Only non-negative integers
}
},
...
}
allOf
condition for attrbitues
:
"allOf": [
{
"contains": {
"properties": {
"tag": {
"enum": ["tag1", "Tag1", "tag_one"]
}
}
}
},
{
"contains": {
"properties": {
"tag": {
"enum": ["tag2", "Tag2", "tag_two"]
}
}
}
},
@theisuru please continue this ticket. The unit tests are failing. The invalid document gets accepted while the invalid ones get rejected. I tried validating using a separate json schema validator and got different errors. I suggest trying this as well (I used an online validator). The error s were related to multiple matches in the oneOf
part of the value
property.
Seems current schema is not correct. The behaviour of schema is different from what we expect from if then else
block in programming. JSON Schema is very permissive and accept unexpected if
conditions.
It is documented here. I am looking for a solution to this.
After the recommendation from the stackoverlow, this seems to be working as expected. All the local test cases are working fine.
value
and unit
are validated using if then
clausecontains
keyword allOf
in two different levelsmerged this directly with main
since there are too much deviation from the branch
ENA checklist is an array of attributes:
Some of the tags are mandatory, some are optional and others are recommended which is another form of optional.
We used
contains
andminContains
keywords to validate fields.contains
expects the whole object within it to match with schema. Therefore, recommended and optional fields are ignored and not working as expected.minContains
enabled optional attributes.Example: This should fail validation because of "unit", but schema ignores the whole field.
sub-schema (ERC000052):
data fragment (SAMEA7025236):
definition of done