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)
- 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
- Cannot find module 'ajv/dist/compile/codegen' HOT 4
- How can I make a property value depend on the value of another property? HOT 1
- Error using multipleOf with decimals HOT 1
- Using if/then/else fails validation HOT 2
- compileParser does not appear to support properties with type `field?: Record<string, unknown>` via `JTDSchemaType`. HOT 6
- Integers as Discriminators HOT 7
- How can I access `definitions` in schema-store using `$ref`? HOT 1
- DeprecationWarning: The punycode module is deprecated #96 HOT 2
- `maxLength` constraint checking seems to not code (Hindi) unicode characters properly HOT 7
- ajv 8.13.0 upgrade doesn't work with ajv-formats 3.0.1 with TypeScript HOT 4
- compileAsync does not loadSchema a schema that is $refβd by a oneOf with a discriminator HOT 3
- How to return error when the vlaue of field is '' and set the field as required HOT 2
- ajv.compileParser does not exist on type Ajv HOT 1
- ajv schema with key or id "first" already exists HOT 1
- Referencing errors in complex schemas
- Dynamic Error Message in Keyword Compile or Validate Methods HOT 1
- if/then false positive when if-property is undefined. HOT 3
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.