Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flaneuse opened this issue Sep 16, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@flaneuse
Copy link
Collaborator

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

  • Alert the user that the property has a syntax error and hasn't been saved
  • It'd be nice to have a JSON formatter/beautifier down the road... JSON is hard to write with all the nesting, in a small window. Incorporate some sort of JSON linter?
@flaneuse flaneuse added the bug Something isn't working label Sep 16, 2022
@flaneuse
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants