Comments (6)
the second document you have specified is invalid;
here allOf
has failed. so any properties evaluated by allOf
are still considered as unevaluated;
only if the validation succeeds, the properties are considered evaluated;
[edit]
the documentation you mentioned clearly says:
unevaluatedProperties works by collecting any properties that are successfully validated when processing the schemas and using those as the allowed list of properties.
from jsonschema.
from spec:
https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#name-unevaluatedproperties
The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated.
but annotation results
are generated only when an instance is valid against schema. see https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#name-annotations
JSON Schema can annotate an instance with information, whenever the instance validates against the schema object containing the annotation, and all of its parent schema objects.
from jsonschema.
to better understand consider following example:
consider following files:
schema.json: ( allOf
is wrapped in not
)
{
"allOf": [ { "not":
{
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
}],
"properties": {
"type": { "enum": ["residential", "business"] }
},
"required": ["type"],
"unevaluatedProperties": false
}
{
"street_address": 123,
"city": "Middletown",
"state": "KY",
"type": "residential"
}
here street_address
is number so allOf
fails which implies not
succeeds. still validator considers that none of the properties are evaluated
see jv
output below:
jv schema.json doc.json
[I#] [S#] doesn't validate with file:///Users/santhosh/gh/santhosh-tekuri/jsonschema/cmd/jv/schema.json#
[I#/street_address] [S#/unevaluatedProperties] not allowed
[I#/city] [S#/unevaluatedProperties] not allowed
[I#/state] [S#/unevaluatedProperties] not allowed
if you want you can also check results at https://www.jsonschemavalidator.net
from jsonschema.
@vassilvk
the second document you have specified is invalid;
Yes, this was the main point.
The second document has one invalid property, and I expect to see a validation error only for that one property.
Seeing validation errors for all the other properties (which are in fact valid) makes no sense and is potentially confusing.
From customer's perspective, the experience is the following:
- They enter a number for street address (which they shouldn't, but they do).
- They get an error correctly indicating that address is not supposed to be a number.
- Then they get messages that address, city, and state are not allowed.
This last bit is technically wrong.
I understand that your goal is to stick to the specification, and that's great.
I am just surprised at how impractical unevaluatedProperties
becomes when it comes to subschemas.
from jsonschema.
in the beginning, this library used to show only single error and stop validation on first error.
later ability to show multiple errors is added.
It is always not trivial to show errors from customer's perspective.
for example when missing a semicolon in a program, compiler shows tons of errors. it is similar situation here.
we can do stop validating keywords that have dependent on other keywords. but it is little complicated to implement and maintain.
from jsonschema.
I understand. Thank you for the quick response and thank you for a great library!
from jsonschema.
Related Issues (20)
- Link in README for YAML playground example is broken HOT 1
- Issue with custom Regex Library HOT 10
- `Compiler.AddResource` for adding pre-compiled schemas HOT 6
- Feature: Adding Context to Validate Method HOT 2
- implementing json.Marshaler interface HOT 9
- Create JSONSchema from Compile()'s result HOT 2
- compiler.go bug in 171
- Invalid JSON schema does not error out HOT 2
- [bug] Not reading from stdin HOT 2
- Missing document file path in validation output when validating multiple documents HOT 5
- Error messages are revealing absolute file paths HOT 1
- YouValidateMe JSON Schema library server project built on this library
- ECMA-262 as the default regex in this library? HOT 1
- jsonschema.Compiler has no field or method CompileRegex HOT 7
- Question: parsing Schema to string HOT 1
- error is missing instanceLocation HOT 1
- Cannot install older version than `@latest` HOT 3
- The latest release doesn't build HOT 2
- Extended the implementation of a new custom validation traversal logic(I'm not sure if there are any other side effects of this)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema.