Skip to content

Commit 1b88925

Browse files
committed
Experiment with autoapi for generating explicit API documentation.
Ref: #590
1 parent ac29e07 commit 1b88925

10 files changed

+79
-7
lines changed

docs/conf.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from importlib import metadata
2+
from pathlib import Path
23
import os
34
import re
45
import sys
56

7+
ROOT = Path(__file__).parent.parent
8+
PACKAGE_SRC = ROOT / "jsonschema"
9+
610
# If extensions (or modules to document with autodoc) are in another directory,
711
# add these directories to sys.path here. If the directory is relative to the
812
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -27,6 +31,7 @@
2731
"sphinx.ext.viewcode",
2832
"sphinx_autodoc_typehints",
2933
"sphinxcontrib.spelling",
34+
"autoapi.extension",
3035
"jsonschema_role",
3136
]
3237

@@ -252,3 +257,27 @@ def entire_domain(host):
252257
# -- Options for sphinxcontrib-spelling -----------------------------------
253258

254259
spelling_word_list_filename = "spelling-wordlist.txt"
260+
261+
# -- Options for autoapi --------------------------------------------------
262+
263+
suppress_warnings = [
264+
"autoapi.python_import_resolution",
265+
"autoapi.toc_reference",
266+
]
267+
autoapi_root = "api"
268+
autoapi_ignore = [
269+
"*/_[a-z]*.py",
270+
"*/__main__.py",
271+
"*/benchmarks/*",
272+
"*/cli.py",
273+
"*/tests/*",
274+
]
275+
autoapi_options = [
276+
"members",
277+
"undoc-members",
278+
"show-module-summary",
279+
"imported-members",
280+
]
281+
282+
autoapi_type = "python"
283+
autoapi_dirs = [PACKAGE_SRC]

docs/creating.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ Creating or Extending Validator Classes
77
=======================================
88

99
.. autofunction:: create
10+
:noindex:
1011

1112
.. autofunction:: extend
13+
:noindex:
1214

1315
.. autofunction:: validator_for
16+
:noindex:
1417

1518
.. autofunction:: validates
19+
:noindex:
1620

1721

1822
Creating Validation Errors

docs/errors.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ When an invalid instance is encountered, a `ValidationError` will be
88
raised or returned, depending on which method or function is used.
99

1010
.. autoexception:: ValidationError
11+
:noindex:
1112

1213
The information carried by an error roughly breaks down into:
1314

@@ -123,6 +124,7 @@ In case an invalid schema itself is encountered, a `SchemaError` is
123124
raised.
124125

125126
.. autoexception:: SchemaError
127+
:noindex:
126128

127129
The same attributes are present as for `ValidationError`\s.
128130

@@ -229,6 +231,7 @@ failed when validating a given instance, you probably will want to do so using
229231
`jsonschema.exceptions.ErrorTree` objects.
230232

231233
.. autoclass:: jsonschema.exceptions.ErrorTree
234+
:noindex:
232235
:members:
233236
:special-members:
234237
:exclude-members: __dict__,__weakref__
@@ -362,9 +365,11 @@ to guess the most relevant error in a given bunch.
362365

363366

364367
.. autofunction:: best_match
368+
:noindex:
365369

366370

367371
.. function:: relevance(validation_error)
372+
:noindex:
368373

369374
A key function that sorts errors based on heuristic relevance.
370375

@@ -404,3 +409,4 @@ to guess the most relevant error in a given bunch.
404409

405410

406411
.. autofunction:: by_relevance
412+
:noindex:

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.. module:: jsonschema
2+
:noindex:
3+
24
.. include:: ../README.rst
35

46

@@ -13,6 +15,7 @@ Contents
1315
references
1416
creating
1517
faq
18+
api/index
1619

1720

1821
Indices and tables

docs/references.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ Resolving JSON References
66
.. currentmodule:: jsonschema
77

88
.. autoclass:: RefResolver
9+
:noindex:
910
:members:
1011

1112
.. autoexception:: RefResolutionError
13+
:noindex:
1214

1315
A JSON reference failed to resolve.

docs/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ file:.#egg=jsonschema
22
furo
33
lxml
44
sphinx
5+
sphinx-autoapi
56
sphinx-autodoc-typehints
67
sphinxcontrib-spelling

docs/requirements.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
alabaster==0.7.12
88
# via sphinx
9+
astroid==2.12.2
10+
# via sphinx-autoapi
911
attrs==22.1.0
1012
# via jsonschema
1113
babel==2.10.3
@@ -25,9 +27,13 @@ idna==3.3
2527
imagesize==1.4.1
2628
# via sphinx
2729
jinja2==3.1.2
28-
# via sphinx
30+
# via
31+
# sphinx
32+
# sphinx-autoapi
2933
file:.#egg=jsonschema
3034
# via -r docs/requirements.in
35+
lazy-object-proxy==1.7.1
36+
# via astroid
3137
lxml==4.9.1
3238
# via -r docs/requirements.in
3339
markupsafe==2.1.1
@@ -46,6 +52,8 @@ pyrsistent==0.18.1
4652
# via jsonschema
4753
pytz==2022.1
4854
# via babel
55+
pyyaml==6.0
56+
# via sphinx-autoapi
4957
requests==2.28.1
5058
# via sphinx
5159
snowballstemmer==2.2.0
@@ -56,9 +64,12 @@ sphinx==5.1.1
5664
# via
5765
# -r docs/requirements.in
5866
# furo
67+
# sphinx-autoapi
5968
# sphinx-autodoc-typehints
6069
# sphinx-basic-ng
6170
# sphinxcontrib-spelling
71+
sphinx-autoapi==1.9.0
72+
# via -r docs/requirements.in
6273
sphinx-autodoc-typehints==1.19.0
6374
# via -r docs/requirements.in
6475
sphinx-basic-ng==0.0.1a12
@@ -77,5 +88,9 @@ sphinxcontrib-serializinghtml==1.1.5
7788
# via sphinx
7889
sphinxcontrib-spelling==7.6.0
7990
# via -r docs/requirements.in
91+
unidecode==1.3.4
92+
# via sphinx-autoapi
8093
urllib3==1.26.11
8194
# via requests
95+
wrapt==1.14.1
96+
# via astroid

docs/spelling-wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ recurses
2828
regex
2929
repr
3030
sensical
31+
submodule
32+
submodules
3133
subschema
3234
subschemas
3335
subscopes

docs/validate.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The simplest way to validate an instance under a given schema is to use the
1313
:func:`validate` function.
1414

1515
.. autofunction:: validate
16+
:noindex:
1617

1718
.. [#] For information on creating JSON schemas to validate
1819
your data, there is a good introduction to JSON Schema
@@ -28,6 +29,7 @@ The Validator Protocol
2829
classes should adhere to.
2930

3031
.. autoclass:: jsonschema.protocols.Validator
32+
:noindex:
3133
:members:
3234

3335
All of the `versioned validators <versioned-validators>` that are included with
@@ -54,6 +56,7 @@ versions.
5456
:members:
5557

5658
.. autoexception:: jsonschema.exceptions.UndefinedTypeCheck
59+
:noindex:
5760

5861
Raised when trying to remove a type check that is not known to this
5962
TypeChecker, or when calling `jsonschema.TypeChecker.is_type`
@@ -102,6 +105,7 @@ existing `TypeChecker` or create a new one. You may then create a new
102105
103106
104107
.. autoexception:: jsonschema.exceptions.UnknownType
108+
:noindex:
105109

106110
.. _versioned-validators:
107111

@@ -114,16 +118,22 @@ that each validator class provides see the `Validator` protocol,
114118
which each included validator class implements.
115119

116120
.. autoclass:: Draft202012Validator
121+
:noindex:
117122

118123
.. autoclass:: Draft201909Validator
124+
:noindex:
119125

120126
.. autoclass:: Draft7Validator
127+
:noindex:
121128

122129
.. autoclass:: Draft6Validator
130+
:noindex:
123131

124132
.. autoclass:: Draft4Validator
133+
:noindex:
125134

126135
.. autoclass:: Draft3Validator
136+
:noindex:
127137

128138

129139
For example, if you wanted to validate a schema you created against the
@@ -174,7 +184,6 @@ validation can be enabled by hooking in a format-checking object into an
174184
:exclude-members: cls_checks
175185

176186
.. attribute:: checkers
177-
178187
A mapping of currently known formats to tuple of functions that
179188
validate them and errors that should be caught. New checkers can be
180189
added and removed either per-instance or globally for all checkers
@@ -197,6 +206,7 @@ validation can be enabled by hooking in a format-checking object into an
197206

198207

199208
.. autoexception:: FormatError
209+
:noindex:
200210
:members:
201211

202212

jsonschema/protocols.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import jsonschema
3131

3232
from jsonschema.exceptions import ValidationError
33-
from jsonschema.validators import RefResolver
3433

3534
# For code authors working on the validator protocol, these are the three
3635
# use-cases which should be kept in mind:
@@ -54,9 +53,10 @@ class Validator(Protocol):
5453
will validate with. It is assumed to be valid, and providing
5554
an invalid schema can lead to undefined behavior. See
5655
`Validator.check_schema` to validate a schema first.
57-
:argument resolver: an instance of `jsonschema.RefResolver` that will be
58-
used to resolve :validator:`$ref` properties (JSON references). If
59-
unprovided, one will be created.
56+
:argument resolver: an instance of
57+
`jsonschema.validators.RefResolver` that will be used to resolve
58+
:validator:`$ref` properties (JSON references). If unprovided, one
59+
will be created.
6060
:argument format_checker: an instance of `jsonschema.FormatChecker`
6161
whose `jsonschema.FormatChecker.conforms` method will be called to
6262
check and see if instances conform to each :validator:`format`
@@ -89,7 +89,7 @@ class Validator(Protocol):
8989
def __init__(
9090
self,
9191
schema: dict | bool,
92-
resolver: RefResolver | None = None,
92+
resolver: jsonschema.RefResolver | None = None,
9393
format_checker: jsonschema.FormatChecker | None = None,
9494
) -> None:
9595
...

0 commit comments

Comments
 (0)