1

I have a configuration file as json with some numerical attributes that have min and max constraints in order to set a range of valid values. Using a json schema validator was easy and quick to validate the configuration file, but now I have a new set of attributes which valid ranges depends on the value of other attribute.

For example:

foo: [10, 20]
bar: [foo*0.6, foo*0.8]

If foo is set to 15, valid values for bar are from 9 to 12.

The only thing I could manage to find is the if-then-else function but it doesn't solves my issue.

Is there a way I could do something like this?

"foo": {
            "type": "integer",
            "minimum": 10,
            "maximum": 20
        },
"bar": {
            "type": "integer",
            "minimum": 0.6*foo,
            "maximum": 0.8*foo
        }

I think the answer most probably must be no and I should do that validation externally, but if I can kill two birds with one stone...

Thanks in advance.

Carlos3dx
  • 481
  • 1
  • 6
  • 13
  • 1
    Does this answer your question? [Express that, for a given property value, a property with the same name should exist using json schema?](https://stackoverflow.com/questions/55691332/express-that-for-a-given-property-value-a-property-with-the-same-name-should-e) – Relequestual Sep 29 '21 at 09:33
  • 1
    Although it's slightly different, the answer really is, no. Sorry. – Relequestual Sep 29 '21 at 09:34
  • I see. I'm checking about extend the validator or looking for another validators (found one that extends the draft to read the data setted, but nothing about multiplying it and for python), but I think it will be quicker (to implement) and cleaner to put the range of bar as large as it can be and later check each bar against its foo if they are 0.6*foo<=bar<=0.8*foo – Carlos3dx Sep 29 '21 at 11:56
  • 1
    JSON Schema is really only to define the SHAPE of your data, not do business logic validation. Business logic validation may seem simple at first, but usually extends. – Relequestual Sep 29 '21 at 12:44

0 Answers0