Giter Club home page Giter Club logo

Comments (6)

santhosh-tekuri avatar santhosh-tekuri commented on May 28, 2024

@vassilvk

the second document you have specified is invalid;

here allOf has failed. so any properties evaluated by allOf are still considered as unevaluated;
only if the validation succeeds, the properties are considered evaluated;

[edit]

the documentation you mentioned clearly says:

unevaluatedProperties works by collecting any properties that are successfully validated when processing the schemas and using those as the allowed list of properties.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 28, 2024

from spec:

https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#name-unevaluatedproperties

The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated.

but annotation results are generated only when an instance is valid against schema. see https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#name-annotations

JSON Schema can annotate an instance with information, whenever the instance validates against the schema object containing the annotation, and all of its parent schema objects.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 28, 2024

to better understand consider following example:

consider following files:

schema.json: ( allOf is wrapped in not )

{
  "allOf": [ { "not":
    {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  }],
  "properties": {
    "type": { "enum": ["residential", "business"] }
  },
  "required": ["type"],
  "unevaluatedProperties": false
}
{
  "street_address": 123,
  "city": "Middletown",
  "state": "KY",
  "type": "residential"
}

here street_address is number so allOf fails which implies not succeeds. still validator considers that none of the properties are evaluated

see jv output below:

jv schema.json doc.json
[I#] [S#] doesn't validate with file:///Users/santhosh/gh/santhosh-tekuri/jsonschema/cmd/jv/schema.json#
  [I#/street_address] [S#/unevaluatedProperties] not allowed
  [I#/city] [S#/unevaluatedProperties] not allowed
  [I#/state] [S#/unevaluatedProperties] not allowed

if you want you can also check results at https://www.jsonschemavalidator.net

from jsonschema.

vassilvk avatar vassilvk commented on May 28, 2024

@vassilvk
the second document you have specified is invalid;

Yes, this was the main point.
The second document has one invalid property, and I expect to see a validation error only for that one property.
Seeing validation errors for all the other properties (which are in fact valid) makes no sense and is potentially confusing.

From customer's perspective, the experience is the following:

  • They enter a number for street address (which they shouldn't, but they do).
  • They get an error correctly indicating that address is not supposed to be a number.
  • Then they get messages that address, city, and state are not allowed.

This last bit is technically wrong.
I understand that your goal is to stick to the specification, and that's great.
I am just surprised at how impractical unevaluatedProperties becomes when it comes to subschemas.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 28, 2024

in the beginning, this library used to show only single error and stop validation on first error.

later ability to show multiple errors is added.

It is always not trivial to show errors from customer's perspective.

for example when missing a semicolon in a program, compiler shows tons of errors. it is similar situation here.

we can do stop validating keywords that have dependent on other keywords. but it is little complicated to implement and maintain.

from jsonschema.

vassilvk avatar vassilvk commented on May 28, 2024

I understand. Thank you for the quick response and thank you for a great library!

from jsonschema.

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.