[2.0.0-beta4] EnumPropType: Enumerations with anyOf and const

Created on 23 June 2024, about 1 year ago
Updated 20 September 2024, 10 months ago

Problem/Motivation

Following [2.0.0-alpha3] EnumPropType: Labelled enumerations Fixed and the introduction of meta:enum

We need to cover this syntax too:

props:
  type: object
  properties:
    position:
      anyOf:
        - { "const": "top", "title": "Top"}
        - { "const": "bottom", "title": "Secondary"}

A bit more verbose and complicated, but JSON schema native and compliant.

Proposed resolution

We can do it in SchemaManager/Canonicalizer

If anyOfof oneOfis found, and every value is a const or an enum with only one item

, we transform it to:

{
      "type": ["string", "number", "integer"],
      "enum": [...],
      "meta:enum": {...}
}

However, we may need to split Canonicalizer::canonicalize() into 2 public methods:

  • one used for prop loading, with resolveQuirks(), the $schema["type"] = "integer" issue, and the "anyOF + const" we wnat to add. The changes to the schema are "persistent".
  • one used only for the compatibility checker. The changes to the schema are "volatile".
📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024