Comments (9)
+1 for this issue -- I expected the first scenario above to work also. @tdegrunt Do you agree here?
from jsonschema.
I can see the benefit, but I'm having trouble locating information on this. I've checked http://json-schema.org/latest/json-schema-core.html#anchor7 . This project aims to be a faithful follower of the json-schema.org. If you can find any pointers/info, please let me know. /cc @ACubed
from jsonschema.
@tdegrunt I am not familiar with JSON Schema but I was reading some examples and I am not sure whether I missunderstood how to use the "required" keyword.
Now I am confused because I think I can accomplish what I was looking for doing something like
"use strict";
var Validator = require('jsonschema').Validator;
var v = new Validator();
var subSchema = {
"id": "/subSchema",
"type": "object",
"properties": {
"prop1": { "type": "string" },
"prop2": { "type": "string" }
},
"required": [ "prop1", "prop2" ]
};
var schema = {
"id": "/schema",
"type": "object",
"properties": {
"prop1": { "$ref": "/subSchema"},
"prop2": { "type": "string" }
},
"required": [ "prop1", "prop2" ]
};
var anotherSchema = {
"id": "/schema",
"type": "object",
"properties": {
"prop1": { "$ref": "/subSchema"},
"prop2": { "type": "string" }
},
"required": [ "prop2" ]
};
var p = {
"prop1": {
"prop1": "Hello",
"prop2": "World"
},
"prop2": "Hello World"
};
var p1 = {
"prop2": "Hello World"
};
v.addSchema(subSchema, '/subSchema');
console.log(v.validate(p, schema));
console.log(v.validate(p1, schema));
console.log(v.validate(p, anotherSchema));
console.log(v.validate(p1, anotherSchema));
@jaysw can you test if this approach fits your use case?
from jsonschema.
I don't think that required:true
on a property is a defined feature of json schema... The required: []
array of required properties is and works fine with this library today although both seem to work under some circumstances.
from jsonschema.
@Prestaul I do agree. I don't know how I didn't notice the required: []
at first glance.
from jsonschema.
@PauloASilva, you were right that this library seems to support required:true
in some circumstances and it is demonstrated in the example in the readme. @tdegrunt, would it be wise to not feature this feature in the readme?
from jsonschema.
required:true
is how JSON Schema draft-3 was defined, so it's allowed in the library for historical reasons.
In the next draft, we'll likely be abandoning the keyword altogether and getting "requiredProperties" in addition to the list of optional "properties".
from jsonschema.
@PauloASilva Does #100 I merged from @Prestaul fix your issue? If so, feel free to close this. Thanks!
from jsonschema.
Documentation update is enough to clarify how to deal with required
. I'm closing this issue.
Thanks,
from jsonschema.
Related Issues (20)
- How to set throwAll?
- Base URI does not work. HOT 1
- Validate throw error with `additionalProperties: true` HOT 1
- JSON Schema for a list of objects that must contain one of three default props HOT 1
- Getting an Error with Schema <'+ourBase+'> already exists with different definition HOT 10
- Compile a Schema including all of it's referenced Schemas into one final Schema? HOT 5
- Rewrite doesn't always work
- Provide path to schema in ValidationError HOT 6
- v1.4.1 does not support chrome 49 HOT 4
- Cannot find module 'url' HOT 7
- TypeScript readonly arrays?
- How to enforce `enum` validation on a specific property? HOT 1
- Date as custom type HOT 2
- Deeper arrays are not being validated HOT 1
- Validation errors in firefox not constructing properly HOT 1
- Nested Schema in the definitions object unsupported attribute when allowUnknownAttributes is set to false
- Support for unevaluatedProperties
- validation error reported onOf object incorrectly HOT 3
- v.validate() on a specific property of a schema? HOT 1
- OpenHarmony support
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.