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

Array items reference problem #82

Closed
odise opened this issue Mar 6, 2013 · 8 comments
Closed

Array items reference problem #82

odise opened this issue Mar 6, 2013 · 8 comments

Comments

@odise
Copy link

odise commented Mar 6, 2013

Hi,

updated jsonschema to 1.1.0 today and now I'm facing the following problem. Given is a simple schema like this:

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "#",
    "required": false,
    "properties": {
        "record_object": {
            "type": "object",
            "id": "record",
            "properties": {
                "mimetype": {
                    "type": "string"
                 }
            }
        },
        "event_object": {
            "type": "object",
            "id": "event",
            "properties": {
                "actions": {
                    "type": "array",
                    "id": "actions",
                    "items": {
                        "type": "object",
                        "$ref": "#/properties/record_object"
                    }
                }
            }
        } 
    }
}

Trying to validate the following JSON (or any other) raises an exception:

event = { "event_object": {
    "actions": [
        { 
            "mimetype": "test"
        }
    ]
}}

validate(event, schema)
 Traceback (most recent call last):
  File "gsa_schema.py", line 120, in <module>
    validate(event, s) 
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 1301, in validate
    cls(schema, *args, **kwargs).validate(instance)
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 226, in validate
    for error in self.iter_errors(*args, **kwargs):
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 219, in iter_errors
    for error in errors:
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 436, in validate_properties
    for error in self.iter_errors(instance[property], subschema):
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 219, in iter_errors
    for error in errors:
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 436, in validate_properties
    for error in self.iter_errors(instance[property], subschema):
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 219, in iter_errors
    for error in errors:
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 268, in validate_items
    for error in self.iter_errors(item, items):
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 219, in iter_errors
    for error in errors:
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 403, in validate_ref
    with self.resolver.resolving(ref) as resolved:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 1026, in resolving
    document = self.resolve_remote(uri)
  File "/Users/jan/Documents/code/jira/lib/python2.7/site-packages/jsonschema.py", line 1099, in resolve_remote
    result = json.loads(urlopen(uri).read().decode("utf-8"))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 386, in open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 248, in get_type
ValueError: unknown url type: actions

In case I do something wrong here please point me to it. Thanks in advance.
Jan

@gazpachoking
Copy link
Contributor

The 'id' keyword changes the resolution scope of $refs. Your ref becomes actions#/properties/record_object. Perhaps we should be wrapping that in a RefResolutionError though.

@odise
Copy link
Author

odise commented Mar 6, 2013

Alright. removing all id properties helps.

@Julian
Copy link
Member

Julian commented Mar 6, 2013

Yes, that'd do this. We can leave this open so that there's a better error message if you do this, but yeah, the id property is defined by JSON Schema, you can't use it for your own purposes (and expect things to work :D). If you want something like what it looks like you're using it for, there's title and description.

@odise
Copy link
Author

odise commented Mar 6, 2013

I don't use it at all to tell the truth. I think it came in while creating an initial schema via http://www.jsonschema.net/#. Simply removing it fixed my problem ;). Thanks a lot!

@odise odise closed this as completed Mar 6, 2013
@Julian
Copy link
Member

Julian commented Mar 6, 2013

Ouch. I see. I'll send over an email to the author. I'm reopening just so we can change this to a RefResolutionError.

@Julian Julian reopened this Mar 6, 2013
@gazpachoking
Copy link
Contributor

Should we add a cause attribute to RefResolutionError to attach the original exception? What should the message for the RefResolutionError be in these cases?

@gazpachoking
Copy link
Contributor

Also, it seems like we might want some other attributes on the RefResolutionError, at least one that has the ref which caused the error.

@Julian
Copy link
Member

Julian commented Mar 10, 2013

Resolution errors are errors, they're not really things that are expected to happen and to be queried at runtime like ValidationErrors.

So I don't think any sort of information is necessary on them other than a message appropriate for each possible time one can happen that the developer can decypher to see what they did wrong.

@Julian Julian closed this as completed in c8b257b Apr 4, 2013
Julian added a commit that referenced this issue Mar 22, 2015
0b657e8 Merge pull request #86 from kylef/patch-1
1bd4151 [README] JSONSchema.swift uses these tests too
8f86716 Revert "Add jon, JSON parser for the fishshell."
db9c629 Merge pull request #82 from bucaran/patch-1
875fa42 Add jon, JSON parser for the fishshell.
64c556c Merge pull request #81 from s-panferov/patch-1
43105d4 Add new Rust library to the list
aa4d927 Merge pull request #80 from seagreen/implementations
20ef067 Add new haskell implementation.
1274070 Merge pull request #79 from Muscula/json-schema-benchmark
6d8cf45 Merge pull request #78 from JamesNK/patch-1
55c4992 Add json-schema-benchmark to list of users of this test suite
645623d Added Newtonsoft.Json.Schema implementation
a7944d1 Merge pull request #76 from Prestaul/patch-1
5729cdf Added skeemas to list of suite users
4600fe3 Make the implementation list a bit less unwieldy now that it's so long (hooray!)
11d6905 Merge remote-tracking branch 'mafintosh/patch-1' into develop
689b80f Merge pull request #74 from bugventure/develop
c36f888 Add request-validator as a user of the test suite
41876b1 Update README.md
aabcb34 Merge pull request #71 from seagreen/additionalproperties
b3d160b Add tests for additionalProperties by itself.

git-subtree-dir: json
git-subtree-split: 0b657e8b0d21a4099d3ce378ba7208073a9295e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants