Arrays with polymorphic objects that are built up with $refs

84 views
Skip to first unread message

Karl Koster

unread,
Oct 15, 2014, 4:43:38 PM10/15/14
to json-schem...@googlegroups.com
I am using the most recent stable version of json-schema-validator and have run into a problem. When I have polymorphic objects in an array and those objects contains refs to definitions in the schema, if they use the same ref I get a "node visited more than once exception" on the second schema validation in the array. For instance, the following schema would issue this error when iterating over within the AnyOfValidator on the second schema validation. Pardon me if I got my braces imbalanced, copying/pasting from and editor makes an awful mess.

{
   
"type":"array",
         "minItems":1,
         "items":{
       "type":"object",
       
"anyOf":[
           
{
             
"type":"object",
                              "$ref":"#/definitions/obj1"
           
},
           
{
             
"type":"object",
                              "$ref":"#/definitions/obj2"
           
}
       
]
         },
    "additionalProperties":false,
    "definitions":{
              "obj1":{
                        "description":"Object 1",
           "required":[
               
"property1",
               
"property2",
               
"property3"],
           "properties":{
               
"property1":{
                   
"type":"object",
                                         "$ref":"#/definitions/obj3"
               
},
               
"property2":{
                   
"type":"string"
               },
               
"property3":{
                   
"type":"string"
               }
                     "additionalProperties":false
               },
       "obj2":{
                        "description":"Object 2",

           "required":[
               
"property1",
               
"property2",
               
"property3",
                                "property4"],
           "properties":{
               
"property1":{
                   
"type":"object",
                                         "$ref":"#/definitions/obj3"
               
},
               
"property2":{
                   
"type":"string"
               },
               
"property3":{
                   
"type":"string"
               },
               
"property4":{
                   
"type":"string"
               }
                        "additionalProperties":false
       },

       "obj3":{
           "type":"object",
                        "description":"Object 3",
           "required":[
               
"propertyA",
               
"propertyB"
           ],
           
"properties":{
               
"propertyA":{
                   
"type":"integer",
                   
"minimum":0
               
},
               
"propertyB":{
                   
"type":"string",
               
}
           
}
       
}
        }
}



Francis Galiegue

unread,
Oct 15, 2014, 8:08:10 PM10/15/14
to Karl Koster, json-schem...@googlegroups.com
Hello,

On Wed, Oct 15, 2014 at 10:43 PM, Karl Koster <karl....@gmail.com> wrote:
> I am using the most recent stable version of json-schema-validator and have
> run into a problem. When I have polymorphic objects in an array and those
> objects contains refs to definitions in the schema, if they use the same ref
> I get a "node visited more than once exception" on the second schema
> validation in the array. For instance, the following schema would issue this
> error when iterating over within the AnyOfValidator on the second schema
> validation. Pardon me if I got my braces imbalanced, copying/pasting from
> and editor makes an awful mess.
>

[snip]

Uh... You may have found a bug here. The logic for "node visited more
than once" is a "recent" addition and while it has been tested, some
use cases may be missing.

Can you try and strip your schema and reproduce the bug, along with sample code?

Thank you in advance,
--
Francis Galiegue, fgal...@gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)

Karl Koster

unread,
Oct 16, 2014, 6:43:39 AM10/16/14
to Francis Galiegue, json-schem...@googlegroups.com
Francis:

The schema I pasted was representative of the problem. Attempting to validate data that complies with that schema should reproduce the results. The problem seemed to be in the path pointer used for the second $ref indirection. It failed to include the array index or the referring entity as part of the path. It just had the dependency's path. I am making a partial guess as I have not rooted around too deeply in the code.

Karl
--
Karl Koster
karl....@gmail.com

Francis Galiegue

unread,
Oct 16, 2014, 6:51:50 AM10/16/14
to Karl Koster, json-schem...@googlegroups.com
Hello,

On Thu, Oct 16, 2014 at 12:16 PM, Karl Koster <karl....@gmail.com> wrote:
> Francis:
>
> The schema I pasted was representative of the problem. Attempting to
> validate data that complies with that schema should reproduce the results.
> The problem seemed to be in the path pointer used for the second $ref
> indirection. It failed to include the array index or the referring entity as
> part of the path. It just had the dependency's path. I am making a partial
> guess as I have not rooted around too deeply in the code.
>


Can you please paste the error message?

Thanks,

Karl Koster

unread,
Oct 16, 2014, 7:33:03 AM10/16/14
to json-schem...@googlegroups.com, karl....@gmail.com
Francis:

I will do this as time permits. However, I would have create a new example since I have moved past/worked around this. I simply declare all types inline and it works without issue.

Karl
Reply all
Reply to author
Forward
0 new messages