Skip to content

Cannot get the validation result with self-reference schema #13

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

Closed
lmichel opened this issue Dec 21, 2016 · 5 comments
Closed

Cannot get the validation result with self-reference schema #13

lmichel opened this issue Dec 21, 2016 · 5 comments

Comments

@lmichel
Copy link

lmichel commented Dec 21, 2016

Steve,

I'm trying to validate the following JSON node:

{
"data": {"xxx": 5},
"tree": {"values: "zzz"}
}

against this schema:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "tree": { "$ref": "#/definitions/tree" }
  },
  "definitions": {
    "tree": {
      "type": "object",
      "properties": {
        "value": { "type": "string" },
        "branches": {
          "type": "array",
          "items": { "$ref": "#/definitions/tree" },
          "minItems": 1
        }
      },
      "required": ["value"]
    }
  }
}

The node is not valid since $tree has no member named "value" (confirmed by http://www.jsonschemavalidator.net/)
My code is like this:

        Set<ValidationMessage> errors = schema.validate(node);
        for(ValidationMessage validationMessage : errors ) {
        	System.out.println("Message : " + validationMessage);
        }       

with both node and schema created by methods XXXFromClasspath of the class BaseJsonSchemaValidatorTest (I made those methods public for this purpose)
The output is

13:18:27.422 [main] DEBUG com.networknt.schema.TypeValidator - validate( {"data":{"xxx":5},"tree":{"values":"zzz"}}, {"data":{"xxx":5},"tree":{"values":"zzz"}}, $)
13:18:27.432 [main] DEBUG c.n.schema.PropertiesValidator - validate( {"data":{"xxx":5},"tree":{"values":"zzz"}}, {"data":{"xxx":5},"tree":{"values":"zzz"}}, $)
13:20:13.264 [main] DEBUG com.networknt.schema.RefValidator - validate( {"values":"zzz"}, {"data":{"xxx":5},"tree":{"values":"zzz"}}, $.tree)
13:20:43.758 [main] DEBUG com.networknt.schema.TypeValidator - validate( {"values":"zzz"}, {"data":{"xxx":5},"tree":{"values":"zzz"}}, $.tree)
13:20:45.852 [main] DEBUG c.n.schema.PropertiesValidator - validate( {"values":"zzz"}, {"data":{"xxx":5},"tree":{"values":"zzz"}}, $.tree)

No error is detected!!
Did I do something wrong?
I tried to follow with a debugger. My understanding is that the error is detected but at some point one of the stacked validate() invocations generate a null message (I'm not sure at all!).

@lmichel
Copy link
Author

lmichel commented Dec 21, 2016

A bit further: the validation only fails when the schema contains a self-reference. If I remove it:

{
	"type": "object",
	"properties": {
		"name": {
			"type": "string"
		},
		"tree": {
			"$ref": "#/definitions/tree"
		}
	},
	"required": [
		"name","tree"
	],
	"definitions": {
		"tree": {
			"type": "object",
			"properties": {
				"value": {
					"type": "string"
				},
				"branches": {
					"type": "array",
					"items": {
						"type": "string"
					},
					"minItems": 1
				}
			},
			"required": [
				"value"
			]
		}
	}
}

The validator reports a correct message for the following node:

{
  "name": "xxx",
  "tree": { }
}

something like

Message : $.tree.value: is missing but it is required

@stevehu
Copy link
Contributor

stevehu commented Jan 9, 2017

More information can be found in #12 as the root cause is to support nested reference.

@stevehu stevehu changed the title Cannot get the validation result Cannot get the validation result with self-reference schema Feb 10, 2017
@stevehu
Copy link
Contributor

stevehu commented Jun 25, 2019

@lmichel We have made a lot of changes regarding the reference. Could you please test it again? Thanks.

@lmichel
Copy link
Author

lmichel commented Jun 26, 2019

I'm now a bit far from this issue, although still interested. I'll check this ASAP

@stevehu
Copy link
Contributor

stevehu commented Aug 7, 2019

This issue has been resolved by @davidvisiedo in #180

@stevehu stevehu closed this as completed Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants