Comments (5)
Reproduction:
import Ajv from "ajv";
const ajv = new Ajv({ allErrors: false, verbose: true, $data: true });
const annotationschema = {
type: "object",
properties: {
pos: {type: "string"},
lemma: {type: "string"},
verbform: {type: "string", enum: ["fin", "inf"]},
tense: {type: "string"},
gender: {type: "string"}
},
required: ["pos", "lemma", "verbform"],
allOf: [
{
if: {properties: {verbform: {const: "fin"}}},
then: {required: ["tense"], properties: {gender: {not: {}}}}
}
]
};
const annotation = {
pos: "verb",
lemma: "something"
// verbform: "inf" // toggle this to see the error magically disappear, even tho the if condition is just as false.
};
const validate = ajv.compile(annotationschema);
const valid = validate(annotation);
console.log(valid);
console.log(validate.errors);
from ajv.
Hi @LazerJesus, thanks for brining this to our attention. After playing around with your example for a bit it does indeed look like a bug to me. I can even pass an empty object and it still complains about missing tense
. I will look into it.
from ajv.
schema in "if" says that when verbForm is present it should be "fin" but it doesn't require that it's present.
So in the absense of verbForm the schema in "if" passes validation, and schema in "then" is applied.
meaning that the if: { properties: { verbform: { const: "fin" } } } is somehow true for { pos: 'verb' } ?!
That's exactly how JSON schema spec is supposed to work 🤷♂️
If you make this property required, it will be "false", but it's not implied.
from ajv.
Ah yes of course, I was thrown by the fact that the outer schema has "verbform"
in the required
array, but the if
schema is treated separately so will need it's own required
.
{
if: {
properties: {verbform: {const: "fin"}},
required: ["verbform"],
},
then: {required: ["tense"]},
}
from ajv.
Indeed that solves it. thank you for the information.
i must say tho, that its very counterintuitive and seems to conflict with logic.
since the statementif: { properties: { verbform: { const: "fin" } } }
is true, the logical branch to execute is then
.
adding the qualifier required
doesnt, for me, change the proposition.
the verbform
either is, or is not fin
.
that being said, ill just add the qualifier and thats that ✌️ all the best
from ajv.
Related Issues (20)
- Add `validateSchema` "strict" mode HOT 6
- Is this repo alive? HOT 1
- console.log cannot be used as a default HOT 1
- Replace fast-deep-equal with dequal HOT 1
- Getting "Invalid regular expression /<myRegex>/" error while compiling HOT 1
- Change empty string to `undefined` before validation HOT 3
- Catch Enum Errors value HOT 4
- RE2 integration incorrectly typed HOT 2
- `regexp` should be wrapped in try/catchs HOT 6
- Add `sideEffects: false` flag to `package.json` to allow tree-shaking HOT 5
- Add support for comments inside JSON HOT 3
- serializing Infinity creates invalid JSON HOT 5
- Unexpected behaviour of unevaluatedProperties when used with dependentSchemas HOT 1
- Picking or Omiting Certain Properties From a Schema Definition to make another definition HOT 1
- Replace `uri-js` abandoned dependency HOT 3
- [feature request] Add more formats and support for `qt-*` keys HOT 1
- Allow it to work on edge (e.g. cloudflare workers) HOT 4
- Any object is valid HOT 5
- removeAdditional not workig as expected
- type `JSONSchemaType` cannot be resolved in generic/nonresolved context
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 ajv.