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

Cannot use "constructor" as object property name #223

Open
Robbendebiene opened this issue Oct 21, 2022 · 0 comments
Open

Cannot use "constructor" as object property name #223

Robbendebiene opened this issue Oct 21, 2022 · 0 comments

Comments

@Robbendebiene
Copy link

Robbendebiene commented Oct 21, 2022

schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "required": [ "answer" ],
    "additionalProperties": false,
    "properties": {
      "answer": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "constructor": {
            "type": "object"
          }
        }
      }
    }
  }
}

json

[
   {
      "answer": {
         "constructor": {
            "key": "value"
         }
      }
   },
   {
      "answer": {}
   }
]

The above json is deemed invalid. Both array entries should be valid, however ajv deems the last entry to be invalid: data/1/answer/constructor must be object

At first it seems like ajv treats the constructor property as a required property. However if I rename the property from constructor to constructor2 everything works as expected. (see Recording)

command: ajv validate -s schema.json -d data.json --spec=draft2020 --errors=text
version: [email protected]

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

No branches or pull requests

1 participant