camtrap-dp icon indicating copy to clipboard operation
camtrap-dp copied to clipboard

Create Frictionless pattern to support conditional constraints

Open niconoe opened this issue 4 years ago • 1 comments

In GitLab by @peterdesmet on Sep 25, 2020, 14:25

Conditional constraints are not supported by Table Schema (see https://github.com/frictionlessdata/specs/issues/169).

So to support:

scientific_name = required if observation_type = "animal"

We would have to extend the schema as suggested in https://stackoverflow.com/a/38781027/2463806, i.e. (if I interpret this correctly) adding the following at the end of observations-table-schema.json:

"anyOf": [
  {
    "properties": {
       "observation_type": { "const": "animal" }
    },
    "required": ["scientific_name"]
  }
]

Or (using the JSON Schema (draft-07)):

"if": {
  "properties": {
    "observation_type": { "const": "animal" }
  },
  "required": ["observation_type"]
},
"then": { "required": ["scientific_name"] }

But in my understanding, it wouldn't be picked up by any of the Table Schema validators, so it's probably not worth adding and just leave scientific_name not required.

niconoe avatar Mar 11 '21 13:03 niconoe

Another option would be to suggest conditional constraints as a new pattern to Frictionless. We would then have to define how conditional constrains should be specified (the syntax) and have tools such as Frictionless Framework implement it.

peterdesmet avatar May 25 '23 09:05 peterdesmet