Coder Social home page Coder Social logo

jsonschema's People

Watchers

 avatar

jsonschema's Issues

Nested Arrays aren't valided correctly

What steps will reproduce the problem?
1. Use schema with an array of objects that have an array of objects as a
property
2. Top array has 3 objects, the 2nd level arrays have 8, 9, and 9 objects

What is the expected output? What do you see instead?
A valid schema. Instead errors are generated for arr[3-8], "arr[3] is
missing and it is not optional". It appears to be a scope problem with the
l var in the for loops inside the checkProp function. I added var l about
line 106 and this appears to have fixed the problem.

if(schema.items){
    //added to fix scope problem looping over arrays
    var l;
    if(schema.items instanceof Array){
        for(i=0,l=value.length; i<l; i++){
            errors.concat(checkProp(value[i],schema.items[i],path,i));
        }
    }else{
        console.debug(value.length);
        for(i=0,l=value.length; i<l; i++){
            errors.concat(checkProp(value[i],schema.items,path,i));
        }
    }                           
}

What version of the product are you using? On what operating system?
b3 on windows in firefox 3

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 28 Apr 2009 at 4:20

Unnecessary comma in jsonschema-b4.js, line 212

What steps will reproduce the problem?
When opening the jsonschematest.html-file in the browser, there is an 
error because of a unnecessary comma at line 212 in jsonschema-b4.js.
It seems to me that the comma is there because of a function in the lines 
213 - 216 that was commented out later without removing the comma.

Solution:
Remove the comma.

Original issue reported on code.google.com by [email protected] on 29 Oct 2009 at 4:32

Python shebang in Modules

Grettings,

I have noticed your modules have Python shebang lines at the start 
(#!/usr/bin/env). Shebangs should only be present in executables that will be 
ran, not in modules that will being loaded.

In order to follow Fedora packaging requirements I was asked to remove these 
shebangs (see document below):

http://fedoraproject.org/wiki/PackageMaintainers/Packaging_Tricks#Remove_shebang
_from_Python_libraries

It would be great if in future releases this shebang was already removed.

Thanks
Jeffrey-


Original issue reported on code.google.com by [email protected] on 27 Jan 2011 at 6:45

Command line client for JavaScript JSON Schema validator

I wrote validate.js, a simple command line client to validate JSON files
with    jsonschema.js. I only tested with jsonschema-b4.js because it's the
latest version. You can use the client with a JavaScript Shell like Rhino:

Usage: js validate.js <schemafile> <objectfile[s]>

Original issue reported on code.google.com by [email protected] on 9 Jun 2009 at 9:46

Attachments:

maxDecimal not working

^ is not the correct operator....
on the check you should use (around line 165):

if (typeof schema.maxDecimal == 'number' && (value *
Math.pow(10,schema.maxDecimal))%1) {
  addError("may only have " + schema.maxDecimal + " digits of decimal places");
}



Original issue reported on code.google.com by [email protected] on 5 Dec 2008 at 2:25

minLength and maxLength are not working.

near line 144 should be:

if (schema.maxLength && typeof value == 'string' && (value.length >
schema.maxLength))
    addError("may only be " + schema.maxLength + " characters long");
if (schema.minLength && typeof value == 'string' && (value.length <
schema.minLength))
    addError("must be at least " + schema.minLength + " characters long");

There were value.maxLength checks. But this does not exists. :)


Original issue reported on code.google.com by [email protected] on 4 Dec 2008 at 9:24

Invalid data passes as valid

What steps will reproduce the problem?
1. Load attached file in Firefox, check console.

What is the expected output? What do you see instead?
Expect "invalid", see "valid"

What version of the product are you using? On what operating system?
jsonschema-b4.js firefox 3.5

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 27 Jan 2010 at 7:02

Attachments:

Type "object" allows arrays

What steps will reproduce the problem?

JSONSchema.validate([1], {"type":"object"}).valid

What is the expected output? What do you see instead?

Expected output is false but instead true is returned.

What version of the product are you using? On what operating system?

jsonschema-b4.js

Original issue reported on code.google.com by [email protected] on 25 Jul 2010 at 2:15

jsonschema doesn't recognize more than 10 digits for integers or numbers

What steps will reproduce the problem?
1. Define a property in the schema with type 'integer' or 'number', such as
{'type':'number'}
2. Give the property a value of 12345678901 (integer of eleven digits)
3. Validate the value 


What is the expected output? What do you see instead?

Expected output:
>>> jsonschema.validate(12345678911, {'type':'number'})
>>> jsonschema.validate(12345678911, {'type':'integer'})


Actual output:
...
  File "jsonschema/validator.py", line 108, in validate_type
    raise ValueError("Value %r for field '%s' is not of type %r" % (value,
fieldname, fieldtype))
ValueError: Value 12345678911L for field '_data' is not of type 'number'


What version of the product are you using? On what operating system?
jsonschema-0.2a, OSX Leopard, Python 2.5.1


Please provide any additional information below.
I fixed this bug by adding types.LongType to the _typesmap (validator.py,
line 20) as follows:
-------
    "integer": [types.IntType, types.LongType],
    "number": [types.IntType, types.FloatType, types.LongType],
-------

Original issue reported on code.google.com by [email protected] on 9 Jun 2009 at 2:39

disallow is not working

when you have a disallow property, its not working because of the following
check:

if (schema.disallow && !checkType(schema.disallow,value).length)
  addError(" disallowed value was matched");

The following:

!checkType(schema.disallow,value).length

is not enougth because althought the checkType function only returns an
array of errors, it has a call for the checkProp method that register some
erros on another scope. 

I see two solutions for this, I guess the best one is to make the checkProp
and checkObj return arrays of errors, but it involves a lot more refactoring. 

The second one, that I did in the php implementation for now, is to just
supress the erros or to ignore the errors registered by the disallow´s call
to check prop. 

Here is the PHP code I have used for this now, its very easy to port:

    if(array_key_exists('disallow',$schema)) {
      $errorsBeforeDisallowCheck = self::$errors;
      $response = self::checkType($schema->disallow, $value, $path);
      // check if had any response AND if changed the 'global' errors.
      if(
        ( count($errorsBeforeDisallowCheck) == count(self::$errors) )  &&
        !count($response)
      ) {
        self::adderror($path," disallowed value was matched");
      }
      else {
        // return the global errors to its state before the check
        self::$errors = $errorsBeforeDisallowCheck;
      }
    }



Original issue reported on code.google.com by [email protected] on 5 Dec 2008 at 9:06

Arrays/Objects with circular references cause infinite recursion in jsonschema-b4.js

Issue

What steps will reproduce the problem?

1. Create an object/array with a circular reference, either direct or
indirect.  For example, a pair of instances of schemas in the extension
example in the Extending and Referencing section of the JSON Schema Proposal.

2. Attempt to validate the instance using an appropriate schema (again I
used the schema in the Extending and Referencing section of the JSON Schema
Proposal).


What is the expected output? What do you see instead?

The expected output is, of course, an object indicating whether or not the
instance is valid.  Instead, an error is thrown by Firefox indicating that
there has been "Too much recursion".


What version of the product are you using? On what operating system?

jsonschema-b4.js, Firefox 3.5.1, Windows Vista


Please provide any additional information below.

I've solved this problem in the attached files by simply adding, in
checkProp, a __jvSeen__ property to each object encountered without it and
returning from checkProp for objects that have it.  In order to remove
these properties without having to traverse the entire object/array I added
an array to the _validate method wherein I register an object the first
time it is encountered.  At the end of the _validate method I simply loop
through this array and call delete on the __jvSeen__ property.

The relevant changes occur on lines: 60, 64-68, and 248-250.  Note that
these lines are with respect to the file jsonschema-b4.2.js which I have
attached.  I've made some other changes in that file as well which will
cause the line numbers to be different from those in jsonschema-b4.js.  

Just to note those changes here in case you would like to integrate them
(obviously these changes only reflect my preferences):

- The JSONSchema namespace has been changed to JSON.schema to mirror the
implementation in the Dojo library.  The "property" property in the error
object has been changed to "path" and to the path has been added the root
($) indicator.  
- A problem with the additionalProperties restriction applying to tuple
types has been resolved (which I'll post another issue for).
- The additionalProperties restriction with respect to tuple types has been
changed to additionalItems to be consistent with the rest of the proposal
using the word items where tuple types are concerned also, in my opinion,
reducing confusion. This would also make a more rigorous validation of
schema extensions possible as the rules necessary to validate
additionalProperties with respect to objects would be different than those
when applying it to arrays (validating the schema itself rather than an
instance of the schema).
- The text of the usage/summaries has been reflowed as the previous flow
was getting on my nerves, X-D.

Thoughts

I haven't done any performance tests so I don't know what the impacts are
of this solution in that regard.

It may be better to use a randomly generated property name pre/suffixed by
__ instead of jvSeen to ensure that an existing property is not
overwritten.  I'm not sure of the necessity of this, however.  The __
prefix ensures, according to the current code, that the property will be
ignored in terms of validation.

Files Attached

crjsTest.html (My test html file)
json-ref.js  (crjsTest.html makes use of this.  I restructured the parse
method into parse and resolveRefs to allow references in objects to be
resolved without having to convert the object to a string and then back to
an object.  I also switched the namespace to JSON.ref to mirror the Dojo
implementation.)
jsonschema-b4.2.js (crjsTest.html makes use of this.  My fixed implementation)


Sorry for all the modifications, these files are for my personal use and as
such I've modified them to my tastes.

Original issue reported on code.google.com by [email protected] on 3 Aug 2009 at 10:14

Attachments:

extra code to treat schema as array found

Schemas can be arrays? I undersand not, if so the following looks like
extra code used when schema could be an array (near line 60).:

if (schema instanceof Array) {
    if (!(value instanceof Array)) {
        return [{property:path,message:"An array tuple is required"}];
    }
    for (i =0; i < schema.length; i++) {
        errors2.concat(checkProp(value[i],schema[i],path,i));
    }
    return errors2;
}



Original issue reported on code.google.com by [email protected] on 5 Dec 2008 at 7:28

setup.py tries to download a file that doesn't exist

What steps will reproduce the problem?
0. Have Python 2.6 installed.
1. Download jsonschema-0.2a.tar.gz and unzip it.
2. Run "python setup.py install"

What is the expected output? What do you see instead?
urllib2.HTTPError: HTTP Error 404: Not Found
It looks like the url it's trying to download is 
http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c8-py2.6.egg

What version of the product are you using? On what operating system?
0.2a (I think this is the most current version?)
Ubuntu 10.10
Python 2.6.6

Please provide any additional information below.
Checking the link that the script outputs, it looks like there's only 0.6c9, 
0.6c10 or 0.6c11 for Python 2.6. I'm guessing you can fix this by requiring a 
newer version but when I tried just changing the default version in 
ez_setup.py, it installed but I couldn't run the tests. Anyway, it's not super 
important for me because I don't really need the library installed, but I 
figured it was probably worth bringing up.

Original issue reported on code.google.com by [email protected] on 19 Sep 2011 at 5:19

Tuple typing not working.

The following:

{
  "tupleTyping":[2,"a"]
} 

will validate (incorrectly) with the following tupletyping schema:

{
  "type":"object",
  "properties":{
    "tupleTyping":{
      "type":"array",
      "items":[
        {"type":"string"},
        {"type":"number"}
      ] 
    }
  }
} 


I solved that with the following (near line 102):

if (schema.items) {
  if(schema.items instanceof Array) {
    for (var i =0,l=value.length; i < l; i++) {
        errors2.concat(checkProp(value[i],schema.items[i],path,i));
    }
  }
  else {
    for (var i =0,l=value.length; i < l; i++) {
        errors2.concat(checkProp(value[i],schema.items,path,i));
    }   
  }                     
}

And I think the (line 78) following code might be useless, because it looks
like it is from an old tuple typing implementation:

if (type instanceof Array) {
    var unionErrors=[];
    for (var j = 0; j < type.length; j++) // a union type 
        if (!(unionErrors=checkType(type[j],value)).length)
            break;
    if (unionErrors.length)
        return unionErrors;
}

Original issue reported on code.google.com by [email protected] on 4 Dec 2008 at 5:33

Tuple types not validated properly when using additionalProperties restriction

What steps will reproduce the problem?
1. Create schema:
{
    "type": "array",
    "items": [{"type": "string"}, {"type": "integer"}],
    "additionalItems": {"type": "object"}
}
and an instance:
["abc", 123, "def"]

2. Attempt to validate the instance using the schema.


What is the expected output? What do you see instead?

Expected: An object indicating the instance is invalid according to the schema.
Instead: The returned object indicates the instance is valid.


What version of the product are you using? On what operating system?

jsonschema-b4.js, Firefox 3.5.1, Windows Vista


Please provide any additional information below.

My solution is on lines 142-152 of the attached file jsonschema-b4.2.js.
Note that additionalProperties is changed to additionalItems in this
solution.  Simply changing it back to additionalProperties would bring the
implementation back into conformance with the proposal.


Attached Files

jsonSchemaTest.html (My test html file)
jsonschema-b4.2.js (The implementation modified with the solution to this
issue, another issue I posted, a modification of the additionalProperties
to additionalItems restriction, as well as some other modifications for
personal preference which don't affect conformance to the JSON Schema proposal)

Original issue reported on code.google.com by [email protected] on 3 Aug 2009 at 10:50

Attachments:

Python 2.4 problems

If these lines will be changed:

    # We need to know if the field exists or if it's just Null
    fieldexists = True
    try:
      value = x[fieldname]
    except KeyError:
      fieldexists = False
    finally:
      value = x.get(fieldname)

to 

    # We need to know if the field exists or if it's just Null
    fieldexists = fieldname in x
    value = x.get(fieldname)

Then jsonschema will work in Python 2.4

Cheers
Petr Kobalíček

Original issue reported on code.google.com by kobalicek.petr on 24 Nov 2008 at 2:37

Problems with the spec

First, at least one of the example schemas are not valid javascript. in
particular

{"description":"A person",
 "type":"object",

 "properties": {
    "name": {"type":"string"},
    "born" : {"type":["integer","string"], allow for a numeric year, or a
full date
          "minimum":1900, min/max for when a numberic value is used
          "maximum":2010,

          "format":"date-time", format when a string value is used
          "optional":true}
    ],
    "gender" : {"type":"string",
                "options":[

                   {"value:"male","label":"Guy"},

                   {"value":"female","label":"Gal"}]},
    "address" : {"type":"object",
                 "properties":{

                    "street":{"type":"string"},
                    "city":{"type":"string"},
                    "state":{"type":"string"}
                   }
                 }

  }
}

Please notice the extra bracket. 

Furthermore, if you attempt to fix this schema and then validate, the
validator complains that it is not valid schema (the error array contains
one object who's message is " Invalid schema/property definition". here is
my fixed version:

{
    "description": "A person",
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        },
        "born": {
            "type": ["integer", "string"],
            "minimum": 1900,
            "maximum": 2010,
            "format": "date-time",
            "optional": true
        },
        "gender": {
            "type": "string",
            "options": [
                {"value": "male","label":"Guy"}, 
                {"value": "female","label":"Gal"}
            ]
        },
        "address" : {
            "type": "object",
            "properties": {
                "street": {"type":"string "},
                "city": {"type":"string "},
                "state": {"type":"string "}
            }
        }
    }
}

This looks valid to me.

It would be nice to see some more examples and perhaps even a test case or
three.

Original issue reported on code.google.com by [email protected] on 25 Jan 2010 at 8:21

Null allowed on union types without explicit null declaration

If you validate

{
  "stringOrNumber":null
}

with the schema

{
  "type":"object",
  "properties":{
    "stringOrNumber":{"type":["string","number"]}
  }
}

It shuld not be valid, but the js is saying it is. 

there is an 

if (value !== null) {

on line 92 

that prevents a null propertie to get into the checkType and then it is not
validated. 

I just removed the check and it worked, passing on the other test cases I
have, but they are not yet complete, so there might be a reason for the
check I could not find yet. 


Original issue reported on code.google.com by [email protected] on 4 Dec 2008 at 12:32

error reporting for union-type-definition inside array type

Minor issue:
What steps will reproduce the problem?
1. Validate an instance document containing the property: 
     "width" : "10A%"

   using a schema schema containing the definition:

   "width" : {"type":["number",{"type":"string","pattern":"\\d+%"}]}


2. Correctly fails (this was fixed in jsonschema_b3.js) but only reports
   failure to match last union-type-def 

What is the expected output? What do you see instead?

Python validator outputs...
value '10A%' for field 'width' is not of type ['number', {'pattern':
'\\d+%', 'type': 'string'}]

Javascript validator outputs...
Validation error for: width message: does not match the regex pattern \d+%

Both messages are correct, the python message is a bit 'more correct' 



What version of the product are you using? On what operating system?
jsonschems_b2.js

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 22 Apr 2009 at 8:59

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.