Skip to content

Instantly share code, notes, and snippets.

@alexkreidler
Created April 1, 2021 22:05
Show Gist options
  • Save alexkreidler/c9c051496933ca80bb46de46e67e46c1 to your computer and use it in GitHub Desktop.
Save alexkreidler/c9c051496933ca80bb46de46e67e46c1 to your computer and use it in GitHub Desktop.

Things the Uniforms JSON Schema parser doesn't like

General issues with anyOf handling: vazco/uniforms#863

Array inside anyOf

Error: Invariant Violation: Field not found in schema: "domainDash.0"

{
  "domainDash": {
    "anyOf": [
      {
        "description": "An array of alternating [stroke, space] lengths for dashed domain lines.",
        "items": {
          "type": "number"
        },
        "type": "array"
      },
      {
        "$ref": "#/definitions/ExprRef"
      }
    ]
  }
}

Replace with

{
  "domainDash": {
    "description": "An array of alternating [stroke, space] lengths for dashed domain lines.",
    "items": {
      "type": "number"
    },
    "type": "array"
  }
}

See e.g. vazco/uniforms#91

The reason this happens is that the _compiledschema doesn't know how to handle it an array when it runs into an error so it doesn't create the first element which the library needs.

Multiple Types

Error: Invariant Violation: Unsupported field type: boolean,number

{
  "labelFlush": {
    "description": "Indicates ...",
    "type": ["boolean", "number"]
  }
}
{
  "labelFlush": {
    "description": "Indicates ...",
    "type": "number"
  }
}

See vazco/uniforms#756

Others

When some definitions had a $schema key set, another error.

Also, something about cannot be represented by null when an anyOf has null as the first option. That's from vazco/uniforms#863, because Uniforms only looks at the type of the first option.

Best to remove "type": nulls then, although they do have semantic importance.

Nested anyOfs e.g. tickColor

Error: unknown format "color-hex" ignored in schema at path "#/definitions/HexColor" Just delete

Uncaught Invariant Violation: Field not found in schema: "axis.values.0" also delete

{
                "values": {
                    "anyOf": [
                        {
                            "items": {
                                "type": "number"
                            },
                            "type": "array"
                        },
                        {
                            "items": {
                                "type": "string"
                            },
                            "type": "array"
                        },
                        {
                            "items": {
                                "type": "boolean"
                            },
                            "type": "array"
                        },
                        {
                            "items": {
                                "$ref": "#/definitions/DateTime"
                            },
                            "type": "array"
                        }
                    ],
                    "description": "Explicitly set the visible axis tick values."
                },
}

Transforms

In anyOf Remove type: Null, ExprRef and Condition* if present. Jump up one if only one element in anyOf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment