Coder Social home page Coder Social logo

Comments (9)

stefk avatar stefk commented on May 22, 2024 1

Thanks :)

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024 1

you're welcome. Thanks for the motivation to improve it :)

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024

On it.

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024

It is a design choice for performance rather than shortcoming :) Required keyword is validated in a single expression (conditions for each property are connected with &&), not in the loop, so ajv has no knowledge of which specific property is missing.

Having said that I agree that one wants to know what exactly is missing, not just that something is missing :)

I'll see how I can improve it without damaging performance. Maybe it should be an option. Or I have another idea...

Thank you for pointing it out.

from ajv.

stefk avatar stefk commented on May 22, 2024

Hi,

I understand performance is an important consideration, but precise error reporting is also really valuable.

I'm currently building a format specification using JSONSchema, and as the multiple schemas involved are subject to many changes at this point, I've set up a test suite automating validation of valid/invalid data samples and generating a primitive documentation above it.

The current error reporting of ajv forces me to make assertions on error messages, which aren't always precise, and the whole approach of relying on message strings is quite fragile. I'd really like to have something like error codes/constants along with better data paths and messages.

@cdmcnamara's proposal:

{ 
  keyword: 'required',
  dataPath: '.amount.value',
  message: 'property value is required' 
}

would allow cleaner assertions on errors like:

keyword === 'required' 
dataPath === '.amount.value

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024

I agree. I have a solution in mind - it will have missing properties in dataPath without affecting performance. If you use allErrors=true then each missing property will create an error (not one error as it is now). If allErrors is not passed it will return the error with the name of the first missing property. Just need a little time for that.

And thanks for using it :)

from ajv.

cdm6a avatar cdm6a commented on May 22, 2024

Thanks for the quick reply! This solution sounds ideal.

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024

done in 0.6.1

from ajv.

epoberezkin avatar epoberezkin commented on May 22, 2024

By the way, the error message for "required" was simply listing all required properties, not just missing ones. So making assertions on it wasn't the right thing to do.

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.