Skip to content

programmatically decide which property is missing when using 'required' in Draft4Validator #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arianvp opened this issue Nov 27, 2015 · 1 comment

Comments

@arianvp
Copy link

arianvp commented Nov 27, 2015

In the Draft3Validator we could easily determine programatically which required field was missing by looking at ValidationError.

Draft3 set the attribute that was missing in path. That way we could programatically see what property was missing:

def properties_draft3(validator, properties, instance, schema):
    if not validator.is_type(instance, "object"):
        return

    for property, subschema in iteritems(properties):
        if property in instance:
            for error in validator.descend(
                instance[property],
                subschema,
                path=property,
                schema_path=property,
            ):
                yield error
        elif subschema.get("required", False):
            error = ValidationError("%r is a required property" % property)
            error._set(
                validator="required",
                validator_value=subschema["required"],
                instance=instance,
                schema=schema,
            )
            error.path.appendleft(property)
            error.schema_path.extend([property, "required"])
            yield error

In Draft4 however, these attributes aren't set anymore:

def required_draft4(validator, required, instance, schema):
    if not validator.is_type(instance, "object"):
        return
    for property in required:
        if property not in instance:
            yield ValidationError("%r is a required property" % property)

Is there a way to get the old behaviour back?

@Julian
Copy link
Member

Julian commented Nov 27, 2015

Hey. At the moment no unfortunately, see #119, would love a patch if you would like. Cheers.

@Julian Julian closed this as completed Nov 27, 2015
Julian added a commit that referenced this issue Jun 17, 2019
e68ff511 Straight up copy Draft 7 tests to Draft 2019-06.
1bd999ac Merge pull request #263 from juxt/master
a43c1d17 Add second Clojure implementation
eadeacb0 Merge pull request #262 from leadpony/fix-ref
3aa8d8fc Fix $ref value as properly percent-encoded.
8feaea4f The test suite schema is draft 4, not draft3 anymore.

git-subtree-dir: json
git-subtree-split: e68ff51148e0acd3476ea6937689552d3dc34a3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants