opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
568 stars 58 forks source link

Validation in a custom definition property is not throwing any error #119

Closed franckweb closed 2 years ago

franckweb commented 2 years ago

I'm trying to validate employee id to be an integer but the following does not throw any errors.

Data:

{
    "id": 824,
    "employee": {
        "id": "text"
    }
}

Schema:

{
    "type": "object",
    "properties": {
        "id": {
            "type": "integer",
            "minimum": 1
        },
        "employee": {
            "$ref": "#/$defs/employee"
        }
    },
    "$defs": {
        "employee": {
            "type": "object",
            "title": "Employee",
            "·properties": {
                "id": {
                    "type": "integer"
                }
            },
        }
    }
}

And when I add "required": ["id", "name"] inside "employee" definition I do get following error as expected since "name" property is not present:

array(1) {
  ["/employee"]=>
  array(1) {
    [0]=>
    string(42) "The required properties (name) are missing"
  }
}

Note: The "id" of the first object does validate integer vs string type.

Any idea why this is happening? I'm trying to do a clean POC for Opis Json Schema. Any help appreciated.

franckweb commented 2 years ago

Fixed! "properties" key inside "employee" had an extra space. Looks like Prettier did not format it correctly!