Comments (7)
The schema is indicating that. Perhaps the confusion is that the error is technically coming from the false
subschema of the additionalProperties
. Regardless, the instance fails for the same reason.
from json-everything.
Yes, basically the error message is a bit misleading. Please feel free to update the issue to reflect the actual issue here.
from json-everything.
The error message this library gives is more accurate. It's the subschema of the additionalProperties
that's generating the error, not the keyword itself. Additionally Newtonsoft hasn't updated their output formatting to 2019-09 yet; it just gives an error message.
from json-everything.
Also I am not sure if this is expected but should the 2nd error be present in the errors list ?
schema
{
"$schema": "http://json-schema.org/draft-06/schema#",
"additionalProperties": false,
"properties": {
"firstName": {
"const":"foo"
}
}
}
data
{
"firstName": "bar"
}
outputs
{
"valid": false,
"keywordLocation": "#",
"instanceLocation": "#",
"errors": [
{
"valid": false,
"keywordLocation": "#/properties/firstName/const",
"instanceLocation": "#/firstName",
"error": "Expected value to match given value"
},
{
"valid": false,
"keywordLocation": "#/additionalProperties/$false",
"instanceLocation": "#/firstName",
"error": "All values fail against the false schema"
}
]
}
from json-everything.
Yes, this property is implemented per the specification:
From 9.3.2.3
Validation with "additionalProperties" applies only to the child values of instance names that do not appear in the annotation results of either "properties" or "patternProperties".
So what's the annotation result of properties
? From 9.3.2.1:
The annotation result of this keyword is the set of instance property names matched by this keyword.
This means that only properties from properties
that pass validation produce annotations, and that additionalProperties
applies to the rest.
In your case, firstName
didn't pass #/properties/firstName/const
, so there is no annotation from it. Then #/additionalProperties/$false
must look at it since there's no annotation. This also produces an error.
Honestly, I don't see the point of defining it this way. I, like you, think that the additionalProperties
error is superfluous. But this is what the spec defines, so this is how it's implemented.
from json-everything.
Thanks @gregsdennis for taking the time to explain in detail. I think this, as a consumer of this lib, may be confusing to a lot of developers unless they are aware that this is how the spec defines it. Would be worth mentioning it in the docs somewhere to avoid people raising similar issues in future.
from json-everything.
Yeah, I can probably do something in the docs.
from json-everything.
Related Issues (20)
- Support custom keywords in schema generation HOT 6
- Evaluate JsonRequired Attribute HOT 5
- Model with Nullable value type is invalid HOT 1
- Model is not valid when has integer value as string HOT 1
- that the custom metastructure could not be parsed HOT 4
- How to extend SchemaGenerator for DateTime HOT 7
- JsonSchema.NET DataValidation HOT 10
- Custom `IAttributeHandler` never called HOT 5
- Anchors naming of 2020 still following 2019 rules HOT 5
- Generating a Custom JSON Schema HOT 1
- ArgumentOutOfRangeException thrown when calling JsonSchema's Evaluate methods from multiple threads. HOT 3
- 2020-12 output incorrectly places annotations
- Nullable decimal type removes multipleOf HOT 1
- Boolean applicator keywords must be non-empty HOT 1
- Issues with rendering on docs site HOT 1
- Verified error reporting type HOT 18
- 'Required' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.RequiredAttribute' and 'Json.Schema.Generation.RequiredAttribute'? HOT 22
- Schema exception {"An item with the same key has already been added. Key: Child"} HOT 9
- Possibly wrong return type HOT 10
- Customizing the `format` generated for a field (without attributes) HOT 5
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 json-everything.