Git Product home page Git Product logo

Comments (7)

gregsdennis avatar gregsdennis commented on May 17, 2024 1

The schema is indicating that. Perhaps the confusion is that the error is technically coming from the false subschema of the additionalProperties. Regardless, the instance fails for the same reason.

from json-everything.

nabinked avatar nabinked commented on May 17, 2024

Yes, basically the error message is a bit misleading. Please feel free to update the issue to reflect the actual issue here.

from json-everything.

gregsdennis avatar gregsdennis commented on May 17, 2024

The error message this library gives is more accurate. It's the subschema of the additionalProperties that's generating the error, not the keyword itself. Additionally Newtonsoft hasn't updated their output formatting to 2019-09 yet; it just gives an error message.

from json-everything.

nabinked avatar nabinked commented on May 17, 2024

Also I am not sure if this is expected but should the 2nd error be present in the errors list ?
schema

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "additionalProperties": false,
  "properties": {
    "firstName": {
      "const":"foo"
    }
  }
}

data

{
  "firstName": "bar"
}

outputs

{
  "valid": false,
  "keywordLocation": "#",
  "instanceLocation": "#",
  "errors": [
    {
      "valid": false,
      "keywordLocation": "#/properties/firstName/const",
      "instanceLocation": "#/firstName",
      "error": "Expected value to match given value"
    },
    {
      "valid": false,
      "keywordLocation": "#/additionalProperties/$false",
      "instanceLocation": "#/firstName",
      "error": "All values fail against the false schema"
    }
  ]
}

from json-everything.

gregsdennis avatar gregsdennis commented on May 17, 2024

Yes, this property is implemented per the specification:

From 9.3.2.3

Validation with "additionalProperties" applies only to the child values of instance names that do not appear in the annotation results of either "properties" or "patternProperties".

So what's the annotation result of properties? From 9.3.2.1:

The annotation result of this keyword is the set of instance property names matched by this keyword.

This means that only properties from properties that pass validation produce annotations, and that additionalProperties applies to the rest.

In your case, firstName didn't pass #/properties/firstName/const, so there is no annotation from it. Then #/additionalProperties/$false must look at it since there's no annotation. This also produces an error.

Honestly, I don't see the point of defining it this way. I, like you, think that the additionalProperties error is superfluous. But this is what the spec defines, so this is how it's implemented.

from json-everything.

nabinked avatar nabinked commented on May 17, 2024

Thanks @gregsdennis for taking the time to explain in detail. I think this, as a consumer of this lib, may be confusing to a lot of developers unless they are aware that this is how the spec defines it. Would be worth mentioning it in the docs somewhere to avoid people raising similar issues in future.

from json-everything.

gregsdennis avatar gregsdennis commented on May 17, 2024

Yeah, I can probably do something in the docs.

from json-everything.

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.