Giter Site home page Giter Site logo

Comments (6)

Julian avatar Julian commented on September 21, 2024

https://python-jsonschema.readthedocs.io/en/stable/faq/#my-schema-specifies-format-validation-why-do-invalid-instances-seem-valid

from jsonschema.

JakeSummers avatar JakeSummers commented on September 21, 2024

Thanks for the link @Julian . Follow up question for you.

The doc you linked only discusses Draft 2019-09 and below. It looks like json-schema 2020-12 introduced a new term: format-assertion:

image

Link

image

Link

Is it correct that you do not currently support format-assertion?

from jsonschema.

Julian avatar Julian commented on September 21, 2024

Supporting it via what mechanism?

from jsonschema.

JakeSummers avatar JakeSummers commented on September 21, 2024

Supporting it via what mechanism?

Any mechanism 😄 .

I would like to validate that the data inside my strings is correctly formatted as a date-time.

from jsonschema.

Julian avatar Julian commented on September 21, 2024

I literally linked you to the docs to do so :)

from jsonschema.

JakeSummers avatar JakeSummers commented on September 21, 2024

Thanks, I see it now.

The solution is hidden in the See also box here:

image

For anyone else running into the same issue, the fix is pretty simple:

@@ -3,6 +3,7 @@ import json
 import pytest
 from jsonschema import validate
 from jsonschema.exceptions import ValidationError
+from jsonschema.validators import Draft202012Validator


 @pytest.mark.parametrize(
@@ -79,4 +80,7 @@ def test_date_format():
     """)

     with pytest.raises(ValidationError):
-        validate(example, schema)
+        validate(example,
+                 schema,
+                 format_checker=Draft202012Validator.FORMAT_CHECKER,
+                 )

Link to doc on solution: https://python-jsonschema.readthedocs.io/en/stable/validate/#validating-formats

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.