biothings / discovery-app

The Data Discovery Engine project by the CD2H Data working-group
http://discovery.biothings.io
Apache License 2.0
4 stars 9 forks source link

[bug-ish] Improperly formatted JSON text doesn't trigger error in Common Validation #191

Open flaneuse opened 1 year ago

flaneuse commented 1 year ago

Describe the bug In the schema editor, I'm creating Common Validation properties. It's a bit tricky to hand-write .json and easy to introduce errors. When there's a typo/json-syntax error, a SyntaxError is created in the console, but the user has no indication that there's something wrong w/ the the input. It's easy to assume that the definition was saved -- when it wasn't.

To Reproduce Steps to reproduce the behavior: Try to declare this as a validation object ;).

{
  "anyOf": [{
      "@type": "Person",
      "description": "Reusable person definition",
      "properties": {
        "affiliation": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "sameAs": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": ["name"],
          "optional": ["sameAs", "url"]
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "familyName": {
          "type": "string"
        },
        "givenName": {
          "type": "string"
        },
        "identifier": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      },
      "required": [
        "name"
      ],
      "recommended: ["
      familyName ", "
      givenName ", "
      identifier "],
      "optional": ["affiliation", "email", "role", "title", "url"]
      "type": "object"
    },
    {
      "items": {
        "@type": "Person",
        "description": "Reusable person definition",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "type": "array"
    },
    {
      "@type": "Organization",
      "description": "Reusable organization definition",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    {
      "items": {
        "@type": "Organization",
        "description": "Reusable organization definition",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "type": "array"
    }
  ]
}

Error output You get console errors like:

editor:1 Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 7

Uncaught SyntaxError: Unexpected token 'f', ..."mended: ["familyName"... is not valid JSON

Expected behavior

flaneuse commented 1 year ago

(i'm missing a " and ,, which is easy enough to debug (albeit annoying), but i had to figure out the error was there first.