Skip to content

Commit 18855d0

Browse files
authored
Merge pull request #1388 from jkowalleck/feat/validate_rfc3987_non-gpl/rfc3987-syntax
Add support for the `iri` and `iri-reference` formats to the `format-nongpl` extra
2 parents 6aadb8b + 1a6067f commit 18855d0

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

docs/validate.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ Or if you want to avoid GPL dependencies, a second extra is available:
206206
207207
$ pip install jsonschema[format-nongpl]
208208
209-
At the moment, it supports all the available checkers except for ``iri`` and ``iri-reference``.
210-
211209
.. warning::
212210

213211
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.
@@ -230,8 +228,8 @@ Checker Notes
230228
``idn-hostname`` requires idna_
231229
``ipv4``
232230
``ipv6`` OS must have `socket.inet_pton` function
233-
``iri`` requires rfc3987_
234-
``iri-reference`` requires rfc3987_
231+
``iri`` requires rfc3987_ or rfc3987-syntax_
232+
``iri-reference`` requires rfc3987_ or rfc3987-syntax_
235233
``json-pointer`` requires jsonpointer_
236234
``regex``
237235
``relative-json-pointer`` requires jsonpointer_
@@ -249,6 +247,7 @@ Checker Notes
249247
.. _rfc3339-validator: https://pypi.org/project/rfc3339-validator/
250248
.. _rfc3986-validator: https://pypi.org/project/rfc3986-validator/
251249
.. _rfc3987: https://pypi.org/pypi/rfc3987/
250+
.. _rfc3987-syntax: https://pypi.org/pypi/rfc3987-syntax/
252251
.. _uri-template: https://pypi.org/pypi/uri-template/
253252
.. _webcolors: https://pypi.org/pypi/webcolors/
254253

jsonschema/_format.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,31 @@ def is_uri_reference(instance: object) -> bool:
324324
return True
325325
return validate_rfc3986(instance, rule="URI_reference")
326326

327+
with suppress(ImportError):
328+
from rfc3987_syntax import is_valid_syntax as _rfc3987_is_valid_syntax
329+
330+
@_checks_drafts(
331+
draft7="iri",
332+
draft201909="iri",
333+
draft202012="iri",
334+
raises=ValueError,
335+
)
336+
def is_iri(instance: object) -> bool:
337+
if not isinstance(instance, str):
338+
return True
339+
return _rfc3987_is_valid_syntax("iri", instance)
340+
341+
@_checks_drafts(
342+
draft7="iri-reference",
343+
draft201909="iri-reference",
344+
draft202012="iri-reference",
345+
raises=ValueError,
346+
)
347+
def is_iri_reference(instance: object) -> bool:
348+
if not isinstance(instance, str):
349+
return True
350+
return _rfc3987_is_valid_syntax("iri_reference", instance)
351+
327352
else:
328353

329354
@_checks_drafts(

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ format-nongpl = [
6262
"jsonpointer>1.13",
6363
"rfc3339-validator",
6464
"rfc3986-validator>0.1.0",
65+
"rfc3987-syntax>=1.1.0",
6566
"uri_template",
6667
"webcolors>=24.6.0",
6768
]

0 commit comments

Comments
 (0)