bids-validator icon indicating copy to clipboard operation
bids-validator copied to clipboard

Feature request: Trigger "warning" if specific value encountered in JSON field

Open sappelhoff opened this issue 5 years ago • 4 comments

We use the schema for JSON validation and that's great -> however, for some failures (or use cases), I would like to send a specific warning to the user.

Example:

  • User tries to specify RAS in EEGCoordinateSystem
  • RAS is not on the [list of restricted keywords], the schema errors and prints a list of accepted values
  • among the printed list, there is Other, and because it seems like the only fit, the user picks Other and moves on

--> that's a problem, because if Other is specified in EEGCoordinateSystem, I want the user to specify a string for the EEGCoordinateSystemDescription field to explain in detail what Other means.

So ideally, the validator would provide a re-usable structure to check:

  • if value A in field B of any JSON, do action X
  • where Z could be either of:
    • send a specifically phrased warning
    • check value in field C ... and if that value is D, pass ... else raise specifically phrased warning

Does that sound reasonable?

sappelhoff avatar Sep 16 '20 09:09 sappelhoff

this enhancement would be a neat and powerful way to improve validation and BIDS usage ... and just to draw attention back to another important (IMHO) and generalizable feature, please see: https://github.com/bids-standard/bids-validator/issues/672 ... if we could implement both of these, we'd be making a big step towards a better validation.

sappelhoff avatar Sep 16 '20 09:09 sappelhoff

I think a part of this issue could be solved with JSON schema conditionals, but that wouldn't allow us to send out targeted warnings

more specifically, see: https://stackoverflow.com/a/38781027/5201771

Either the "foo" property does not equal "bar", or the "bar" property is required

{
  "type": "object",
  "properties": {
    "foo": { "type": "string" },
    "bar": { "type": "string" }
  },
  "anyOf": [
    {
      "not": {
        "properties": {
          "foo": { "const": "bar" }
        },
        "required": ["foo"]
      }
    },
    { "required": ["bar"] }
  ]
}

sappelhoff avatar Sep 16 '20 12:09 sappelhoff

also related to https://github.com/bids-standard/bids-validator/issues/945 ... but the feature request here goes beyond that issue.

sappelhoff avatar Sep 29 '20 08:09 sappelhoff

This can be done in the schema.

effigies avatar Nov 05 '24 02:11 effigies