Comments (6)
Apologies but I am not sure I understand the problem here. Can you provide some example code of the issue on https://runkit.com ?
from ajv.
Hi Jason.
I was stuck on this for several days before I solved the issue. Now I am having trouble reproducing the issue. This is frustrating. Can you close this issue and I will reopen it if I run into it again?
from ajv.
Looks like I can
from ajv.
Okay got it. Here is the Runkit link.
So the reason this is a problem is that I have an algorithm that automatically combs through the schema and picks out keywords. If I have a keyword (like id
) that is pre-defined, I will have to add additional logic to exclude keywords already built into Ajv when I am telling AJV to look for a keyword it already looks for. I am not telling it to make a change to what it already does, just that I want to make sure it is included as a keyword.
As a workaround, I tell my code to take all the keywords that are in my schema, take them out of AJV, so I can put them back in and then take them out again at the end of the test.
This is truncated as I have the function encapsulated in another library. You can find the function here named: schemaCorresponds
.
function schemaCorresponds(subject, alias, target, bool=true){
const description = getCounter() + alias + does(bool) + `correspond to response`
const correspondsTo = () => {
it(description, () => {
const ajv = new Ajv()
let validate
let valid
decompileKeywords(ajv, target) // Remove any keywords AJV already knows
compileKeywords(ajv, target) // Comb through the target schema and add the keywords
validate = ajv.compile(target)
valid = validate(subject)
bool
? expect(valid).to.be.true
: expect(valid).to.be.false
if (!valid && bool) {console.log(validate.errors)}
decompileKeywords(ajv, target) // Remove the keywords I added to AJV
})
count()
}
correspondsTo()
}
Please let me know this makes sense. I am still a pretty fresh, self taught coder. There is a lot I still have to learn.
from ajv.
Thanks for the example, that makes it much easier to understand what you are talking about. Unfortunately I would say this is something we would definitely not want to change. With a library like AJV that is used by millions, the fact that it throws in any given situation is something that possible thousands could be relying upon within their code. We are also against adding options for things like this, it may seem low cost to add an option to configure it not to throw, but but every option adds complexity and increases the overall footprint of the code.
Question though, why can't you try catch the addKeyword
call if what you preferred was that it just warned?
from ajv.
Good point. Even small changes have big ramifications at scale.
That's a good idea, I didn't think of that. Thanks!
from ajv.
Related Issues (20)
- `oneOf` with coercion produces the wrong coerced value HOT 2
- Change Linter HOT 2
- Why regex pattern not works ? HOT 1
- Runtime discriminator to be able to support useDefaults within anyOf/oneOf HOT 1
- Unexpected behavior with removeAdditional and minProperties HOT 2
- Default export broken for typescript moduleResolution node16 HOT 10
- Contains object property with unknown key matching a schema HOT 1
- Distinction between addVocabulary and addKeyword in the docs
- Documentation dead links HOT 1
- Ref within def does not act consistently
- JSONSchemaType $ref doesn't work in array type. HOT 5
- oneOf returns unwanted errors HOT 1
- Description key set as boolean returns error that it must be string HOT 2
- Validate and infer JSON Schema validated data type: introducing type providers HOT 3
- JTD schema parser errors on empty properties field HOT 1
- Implement x-inOrder subschema for in order or sequential processing HOT 3
- additionalProperties shouldn't affect TypeScript types from JTDDataType HOT 10
- option compile from addKeyword doesn't change on a remove and then add again HOT 1
- OneOf validation issue HOT 1
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.