Comments (4)
You are yet another victim of the misunderstanding of how extends
works ;)
extends
adds constraints to a schema, it does not make any attempts to merge schemas at all.
Both of your schemas expect an object instance. So far so good.
The first schema forbids any other members than "foo" to be present, so, when it see "bar", it complains -- rightfully so.
And the second schema forbids any other members than "bar" to be present, so, when it see "foo", it complains -- rightfully so as well.
This is not a bug: this is how it is supposed to work. And this is why the next proposed specification replaces extends
with allOf
, which has the same meaning, without the ambiguities. With allOf
, your schema becomes:
{
"allOf": [
{
"properties": {
"foo": {
"type": "string"
}
},
"additionalProperties": false
},
{
"properties": {
"bar": {
"type": "string"
}
},
"additionalProperties": false
}
]
}
from json-schema-validator.
Doh, well sorry for polluting your tracker then.
Based on that, is there no way using the current spec to accomplish what I'm describing here (instance of A to allow both "foo" and "bar", but an instance of B to only allow "bar")? I love the reuse that $ref gives me, but it sounds like I can't utilize that if I want to restrict the additional properties?
from json-schema-validator.
Doh, well sorry for polluting your tracker then.
No problem... Actually, it is a recurring demand, and JSON Schema currently has no mechanism for that :/ And given the set of current keywords, I don't see how this is possible.
Last time someone had this problem on the group, I suggested that he just ignored properties he didn't want instead of using additionalProperties... I know of no way to achieve what you want. What would actually be needed is indeed schema merging, and it leads to a whole new class of problems!
from json-schema-validator.
Ok, thanks! If it's possible to bring something like this in for consideration on the spec, I would certainly love to see it!
from json-schema-validator.
Related Issues (20)
- Failed validation for no apparent reason?
- Getting java.util.concurrent.ExecutionException while validating
- Error when validating Json against a schema defining oneOf
- Are we planning on supporting draft-07 HOT 1
- Example code on README.md please plus links to examples in src
- Migrate from joda-time to java 8 time API HOT 2
- Improcess error hanling in getJsonSchema - never squash exceptions
- Android app crashes because schema (v4) cannot be found at runtime HOT 2
- Getting NPE when passing null to validate method.
- Has the functionality of the ResolvingSchemaWalker been replaced in more recent versions?
- Conflicting Transitive Dependency Versions for Guava and Jsr305
- Where is pom.xml ? I want to import this library to my local and customize it
- Not compatible with GraalVM
- NoSuchFieldError on signing
- When JSONObject contains JSONArray, JSONArray's object can not be validated
- draftv4/schema is different between json-schema-validator 2.2.14 and json-schema-core 1.2.14 HOT 2
- release new version HOT 2
- How can we get Error Message with the error path appended?
- Obtain JUST the message from a ValidationMessage?
- BUG: ECMA262 valid pattern throws an exception
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-schema-validator.