Skip to content

Add support for the iri and iri-reference formats to the format-nongpl extra #1388

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/validate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ Or if you want to avoid GPL dependencies, a second extra is available:

$ pip install jsonschema[format-nongpl]

At the moment, it supports all the available checkers except for ``iri`` and ``iri-reference``.

.. warning::

It is your own responsibility ultimately to ensure you are license-compliant, so you should be double checking your own dependencies if you rely on this extra.
Expand All @@ -230,8 +228,8 @@ Checker Notes
``idn-hostname`` requires idna_
``ipv4``
``ipv6`` OS must have `socket.inet_pton` function
``iri`` requires rfc3987_
``iri-reference`` requires rfc3987_
``iri`` requires rfc3987_ or rfc3987-syntax_
``iri-reference`` requires rfc3987_ or rfc3987-syntax_
``json-pointer`` requires jsonpointer_
``regex``
``relative-json-pointer`` requires jsonpointer_
Expand All @@ -249,6 +247,7 @@ Checker Notes
.. _rfc3339-validator: https://pypi.org/project/rfc3339-validator/
.. _rfc3986-validator: https://pypi.org/project/rfc3986-validator/
.. _rfc3987: https://pypi.org/pypi/rfc3987/
.. _rfc3987-syntax: https://pypi.org/pypi/rfc3987-syntax/
.. _uri-template: https://pypi.org/pypi/uri-template/
.. _webcolors: https://pypi.org/pypi/webcolors/

Expand Down
25 changes: 25 additions & 0 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,31 @@ def is_uri_reference(instance: object) -> bool:
return True
return validate_rfc3986(instance, rule="URI_reference")

with suppress(ImportError):
from rfc3987_syntax import is_valid_syntax as _rfc3987_is_valid_syntax

@_checks_drafts(
draft7="iri",
draft201909="iri",
draft202012="iri",
raises=ValueError,
)
def is_iri(instance: object) -> bool:
if not isinstance(instance, str):
return True
return _rfc3987_is_valid_syntax("iri", instance)

@_checks_drafts(
draft7="iri-reference",
draft201909="iri-reference",
draft202012="iri-reference",
raises=ValueError,
)
def is_iri_reference(instance: object) -> bool:
if not isinstance(instance, str):
return True
return _rfc3987_is_valid_syntax("iri_reference", instance)

else:

@_checks_drafts(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ format-nongpl = [
"jsonpointer>1.13",
"rfc3339-validator",
"rfc3986-validator>0.1.0",
"rfc3987-syntax>=1.1.0",
"uri_template",
"webcolors>=24.6.0",
]
Expand Down
Loading