Giter Site home page Giter Site logo

Silence error about json-schema HOT 6 CLOSED

justinrainbow avatar justinrainbow commented on July 28, 2024
Silence error

from json-schema.

Comments (6)

justinrainbow avatar justinrainbow commented on July 28, 2024

Could you provide some example data?

from json-schema.

 avatar commented on July 28, 2024

Hi,

I have not kept: I tested "json-schema" at work, but I used another solution to validate the json.

Memory, nothing happens when I call the method "check" with tables instead of stdclass. When I say "nothing happens", I mean that no exception is thrown, the getErrors () method returns an empty array.

I think it's "dangerous", I usually test with fake, so I knew it was not normal. Aside from that, once past a stdclass, I managed to validate my json, it seems to work well :)

Thank you! I "star"!

from json-schema.

justjico avatar justjico commented on July 28, 2024

Quick example:

This should be invalid as the input vars are incorrectly formatted, i.e. missing json_decode(). However, it validates!

<?php

require_once 'vendor/autoload.php';

// Validate ...


$_Input = '
{
"id": 1,
"tags": ["home", "green"]
}
';
$_Schema = '
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acmes catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string",
"required": true
}
}
}
';
$validator = new \JsonSchema\Validator();
$validator->check($_Input, $_Schema);

if (!$validator->isValid()) {
    foreach ($validator->getErrors() as $error) {
        $exceptionMessage .= sprintf("[%s] %s\n", $error['property'], $error['message']);
    }
    throw new \Exception($exceptionMessage);
}
echo "valid";

from json-schema.

 avatar commented on July 28, 2024

Yes,

Same if $_Input and $_Schema are json_decode($_Input, true) and json_decode($_Schema, true)

from json-schema.

mchiocca avatar mchiocca commented on July 28, 2024

Hello. Note that the json-schema implementation doesn't support draft-04 of the JSON Schema specification. I have resolved all of the draft-03 bugs and issues with Pull Request #41 with the exception of $ref, $schema, and id. Plus, I have fixed a few other issues as well. Merging #41 will be a big step towards supporting draft-03. #41 may also fix this issue as well. I would have to check that.

from json-schema.

bighappyface avatar bighappyface commented on July 28, 2024

#41 was merged May 28, 2013

from json-schema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.