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

Moving away from oneOf

Open glenrobson opened this issue 3 years ago • 2 comments

Fixes #154

glenrobson avatar Nov 18 '22 13:11 glenrobson

This is quiet a large change to move away from oneOf in the schema to if/then/else. It provides much better error reporting than oneOf which prints a generic:

"is not valid under any of the given schemas"

without any context as it doesn't know which oneOf is closest to the one you want. This means I can get rid of all of the custom error diagnosis in error_processor.py and rely on Jsonschema to produce a better error message.

I've run out of time to complete this pull request but still to do:

  • [ ] check if/then/else works with iiif-prezi3
  • [x] move failing fixtures to /fixtures/3/broken/
  • [x] check error messages of broken (both path + title and description)
  • [x] remove redundant code in schemavalidator.py and the file error_processor.py
  • [x] remove any other oneOfs in the schema
  • [ ] look at moving placeholder and accompanying canvas to being recursive
  • [x] move schema tests into its own file
  • [x] read all valid manifests and check

glenrobson avatar Dec 10 '22 03:12 glenrobson

So Mike tested and unfortunately pydantic-codegen doesn't support if / then / else. But it looks like this use of if then else is what is intended: (see json schema issue: https://github.com/json-schema-org/json-schema-spec/issues/31). For pydantic we can downgrade the if then else block to the following form:

{
  "if": {"$ref": "condition" },
  "then": {"$ref": "schema1"},
  "else": {"$ref": "schema2"}
}

to:

{
  "anyOf": [
    { "allOf": [ {"$ref": "condition" }, {"$ref": "schema1"} ] },
    { "allOf": [ {"not": {"$ref": "condition" } }, {"$ref": "schema2"} ] }
  ]
}

From https://github.com/json-schema-org/json-schema-spec/issues/180

glenrobson avatar Dec 14 '22 10:12 glenrobson