Skip to content

jsv4 always validates #24

Description

@sgoendoer

EDIT:

The methods isValid() and validate() actually expect both the $data and the $schema parameter to be json. This should perhaps be stated in readme.md!?

The example below works with

$result = Jsv4::validate(json_decode($json), json_decode($schema));
var_dump($result);

$result = Jsv4::isValid(json_decode($json), json_decode($schema));
var_dump($result);

This might be related to issue #18: The following will always return true:

<?php 

require_once(__DIR__ . '/../src/Lib/jsv4/jsv4.php');

$schema = '{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://jsonschema.net/x",
    "type": "object",
    "properties":
    {
        "objectID":
        {
            "id": "http://jsonschema.net/x",
            "type": "string"
        }
    },
    "required": [
        "objectID"
    ]
}';

$json = '{';

$result = Jsv4::validate($json, $schema);
var_dump($result);

$result = Jsv4::isValid($json, $schema);
var_dump($result);

?>

What it returns:

object(Jsv4)#1 (6) {
 ["data":"Jsv4":private]=>
  string(1) "{"
  ["schema":"Jsv4":private]=>
  string(242) "{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://jsonschema.net/x",
    "type": "object",
    "properties":
    {
        "objectID":
        {
            "id": "http://jsonschema.net/x",
            "type": "string"
        }
    },
    "required": [
        "objectID"
    ]
}"
  ["firstErrorOnly":"Jsv4":private]=>
  bool(false)
  ["coerce":"Jsv4":private]=>
  bool(false)
  ["valid"]=>
  bool(true)
  ["errors"]=>
  array(0) {
  }
}
bool(true)

note that $json is not even a valid json, left alone a json matching to the schema.

Tested on PHP 5.6.12 (cli) (built: Aug 7 2015 11:29:31)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions