Coder Social home page Coder Social logo

Comments (16)

epoberezkin avatar epoberezkin commented on June 12, 2024

That's what is there in the link you posted (and that's how you can use it):

{
  "type": "object",
  "properties": {
    "size": {
      "type": "number",
      "minimum": 4,
      "errorMessage": {
        "type": "Size must be a number",
        "minimum": "Size cannot be less than 4"
      }
    }
  }
}

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

It wasn't working before. I must have missed something. Thanks!

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

When a type error occurs, the other errors are triggered too. Is there a better way to show only type error message other than going through the errors list and looking for type errors?

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

I don't understand. What's the schema/data and what are the messages? When you say "triggered" what exactly do you mean?

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

If I validate { size: 'abc' } in the above example, it will return both type and minimum error.

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

It doesn't for me: https://runkit.com/esp/593d4c73c899fe001280d79c

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

"minimum" etc. is only validated for numbers, it should not generate any errors if the data is not a number.

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

My mistake, it seems that my application is converting strings to NaN.

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

Should it still trigger both type and minimum errors?

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

for NaN? Yes, because typeof NaN is "number".

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

Yes, but why is it generating a type error?

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

it doesn't for me: https://runkit.com/esp/593d4c73c899fe001280d79c

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

See ajv-validator/ajv#182

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

Thanks for the link to the discussion. I'm testing a lot of different types and the type and minimum error were both generated when "type": "integer" with { size: NaN }.

{
  "type": "object",
  "properties": {
    "size": {
      "type": "integer",
      "minimum": 4,
      "errorMessage": {
        "type": "Size must be an integer",
        "minimum": "Size cannot be less than 4"
      }
    }
  }
}

from ajv-errors.

epoberezkin avatar epoberezkin commented on June 12, 2024

NaN is not an integer. But minimum applies to it because it is a number.

from ajv-errors.

superandrew213 avatar superandrew213 commented on June 12, 2024

Ok got it. A bit confusing though.

from ajv-errors.

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.