Giter VIP home page Giter VIP logo

Comments (6)

jasoniangreen avatar jasoniangreen commented on May 25, 2024

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.

GeorgeSchafer avatar GeorgeSchafer commented on May 25, 2024

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.

GeorgeSchafer avatar GeorgeSchafer commented on May 25, 2024

Looks like I can

from ajv.

GeorgeSchafer avatar GeorgeSchafer commented on May 25, 2024

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.

jasoniangreen avatar jasoniangreen commented on May 25, 2024

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.

GeorgeSchafer avatar GeorgeSchafer commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.