Comments (6)
@ri0ter ValidationError#name
is the property you're looking for. e.g.
validate("instance", {type:"number"}).errors[0].name // "type"
from jsonschema.
Not really, for the schema I mentioned in my first message, with input:
{
foo: '',
},
I get 3 errors:
[
{
"path": [
"foo"
],
"property": "instance.foo",
"message": "does not meet minimum length of 2",
"schema": {
"type": "string",
"minLength": 2
},
"instance": "",
"name": "minLength",
"argument": 2,
"stack": "instance.foo does not meet minimum length of 2"
},
{
"path": [],
"property": "instance",
"message": "does not match allOf schema [subschema 0] with 1 error[s]:",
"schema": {
...
},
"instance": {
"foo": ""
},
"name": "allOf",
"argument": {
...
},
"stack": "instance does not match allOf schema [subschema 0] with 1 error[s]:"
},
{
"path": [
"foo"
],
"property": "instance.foo",
"message": "does not meet minimum length of 1",
"schema": {
"minLength": 1
},
"instance": "",
"name": "minLength",
"argument": 1,
"stack": "instance.foo does not meet minimum length of 1"
}
]
As you can see you cannot differentiate what's the source of first and last error.
from jsonschema.
Can you please describe the exact information you're expecting?
Maybe you're looking for the "path" property? An empty array indicates an error in the root. The "foo" item indicates it is within that property in the instance.
from jsonschema.
Or if you need to know which subschema is applied, the "schema" property in the error is a reference to the original schema.
from jsonschema.
Well, the path property describes the instance and subschema is not telling me where it came from, I could try to match the subschema, but that would require deep compare and doesn't guarantee me what I search for.
What I would expect is something like the path, but related to schema. Referring to my example it would be:["property", "foo"]
, ["allOf"]
and ["allOf","property", "foo"]
.
from jsonschema.
@ri0ter Ok, that makes sense. Let's call this property "schemaPath" and have it work similar to "path".
The best you can do right now is you can use strict equality ===
to determine if the schema that produced the error is some schema that you have a reference to. For example, you could try:
const schema = {
type: 'object',
properties: {
foo: { type: 'string', minLength: 2 },
bar: { type: 'array' },
},
allOf: [
{
properties: {
foo: {
minLength: 1,
},
},
}
]
};
const result = validate({
foo: '',
}, schema);
result.errors[0].schema === schema.properties.foo; // true
result.errors[0].schema === schema.allOf[0].properties.foo; // false
from jsonschema.
Related Issues (20)
- 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
- pattern does not work when use a regexp with attributes HOT 1
- Validation error (Not supporting anyOf property)
- $id is incompatible with allowUnknownAttributes: false
- Unable to update the git submodules HOT 1
- [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities. HOT 1
- bug?: Object literal may only specify known properties, and 'default' does not exist in type 'Schema' HOT 1
- Vite Module "url" has been externalized for browser compatibility HOT 1
- Validator does not honor "nullable" property for `type: "string", enum: [...]` HOT 2
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.