metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
593 stars 94 forks source link

Invalid JSON Schema type generated for `s/tuple` #270

Open cale-at-reify opened 1 year ago

cale-at-reify commented 1 year ago

The current definition for s/tuple is such that transforming (s/tuple ::sort-column ::sort-order) to json-schema results in

"sort-by": {
  "type": {
    "type": "array",
    "items": [
        {
          "type": "array",
          "items": { "type": "string" },
          "description": "A tuple of [axis, column] describing a log-format column"
        },
        { "enum": ["desc", "asc"] }
      ]
  }
}

The correct definition uses anyOf.

"sort-by": {
  "type": {
    "type": "array",
    "items": {
      "anyOf": [
        {
          "type": "array",
          "items": { "type": "string" },
          "description": "A tuple of [axis, column] describing a log-format column"
        },
        { "enum": ["desc", "asc"] }
      ]
    }
  }
}