fractal-analytics-platform / fractal-web

Web client for Fractal
https://fractal-analytics-platform.github.io/fractal-web/
BSD 3-Clause "New" or "Revised" License
6 stars 0 forks source link

Adapt to JSON Schema 2020-12 changes in `items` #534

Closed tcompa closed 2 months ago

tcompa commented 2 months ago

There is at least one more issue related to #531, which will require a bit more work (i.e. handling/testing pydantic_v1 and pydantic_v2 schemas in different ways).


Pydantic V2 generates JSON Schemas that comply with draft 2020-12, which means that they follow the new style for items: https://json-schema.org/draft/2020-12/release-notes#changes-to-items-and-additionalitems. Briefly

The items and additionalItems keywords have been replaced with prefixItems and items where prefixItems has the same functionality as the array-of-schemas for of the old items and the new items keyword has the same functionality as the old additionalItems keyword.


Starting from a task Python function with an argument arg_A: tuple[int, int] = (1, 1), we end up with this kind of JSON Schema:

{
  "additionalProperties": false,
  "properties": {
    "arg_A": {
      "default": [
        1,
        1
      ],
      "maxItems": 2,
      "minItems": 2,
      "prefixItems": [
        {
          "type": "integer"
        },
        {
          "type": "integer"
        }
      ],
      "title": "Arg A",
      "type": "array",
      "description": "Description of arg_A."
    }
  },
  "type": "object",
  "title": "TaskFunction"
}

which currently cannot be loaded in fractal-web, due to error compiling schema Error: strict mode: unknown keyword: "prefixItems".


Since we need to tackle this question on the form-generation side, let's also check whether we should configure ajv differently for the two pydantic_v1/v2 cases, that is by specifying the JSON Schema draft explicitly.