Skip to content

Commit 8e43f78

Browse files
committed
Experiment with autoapi for generating explicit API documentation.
Ref: #590
1 parent 9c79837 commit 8e43f78

File tree

10 files changed

+78
-4
lines changed

10 files changed

+78
-4
lines changed

docs/conf.py

Lines changed: 30 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.
@@ -25,6 +29,8 @@
2529
"sphinx.ext.intersphinx",
2630
"sphinx.ext.napoleon",
2731
"sphinx.ext.viewcode",
32+
33+
"autoapi.extension",
2834
"sphinx_autodoc_typehints",
2935
"sphinx_json_schema_spec",
3036
"sphinxcontrib.spelling",
@@ -252,3 +258,27 @@ def entire_domain(host):
252258
# -- Options for sphinxcontrib-spelling -----------------------------------
253259

254260
spelling_word_list_filename = "spelling-wordlist.txt"
261+
262+
# -- Options for autoapi --------------------------------------------------
263+
264+
suppress_warnings = [
265+
"autoapi.python_import_resolution",
266+
"autoapi.toc_reference",
267+
]
268+
autoapi_root = "api"
269+
autoapi_ignore = [
270+
"*/_[a-z]*.py",
271+
"*/__main__.py",
272+
"*/benchmarks/*",
273+
"*/cli.py",
274+
"*/tests/*",
275+
]
276+
autoapi_options = [
277+
"members",
278+
"undoc-members",
279+
"show-module-summary",
280+
"imported-members",
281+
]
282+
283+
autoapi_type = "python"
284+
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 may 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__
@@ -361,9 +364,11 @@ to guess the most relevant error in a given bunch.
361364

362365

363366
.. autofunction:: best_match
367+
:noindex:
364368

365369

366370
.. function:: relevance(validation_error)
371+
:noindex:
367372

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

@@ -403,3 +408,4 @@ to guess the most relevant error in a given bunch.
403408

404409

405410
.. autofunction:: by_relevance
411+
: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,6 +2,7 @@ file:.#egg=jsonschema
22
furo
33
lxml
44
sphinx
5+
sphinx-autoapi
56
sphinx-autodoc-typehints
67
sphinx-json-schema-spec
78
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
3339
# -r docs/requirements.in
@@ -48,6 +54,8 @@ pyrsistent==0.18.1
4854
# via jsonschema
4955
pytz==2022.2.1
5056
# via babel
57+
pyyaml==6.0
58+
# via sphinx-autoapi
5159
requests==2.28.1
5260
# via sphinx
5361
snowballstemmer==2.2.0
@@ -58,10 +66,13 @@ sphinx==5.1.1
5866
# via
5967
# -r docs/requirements.in
6068
# furo
69+
# sphinx-autoapi
6170
# sphinx-autodoc-typehints
6271
# sphinx-basic-ng
6372
# sphinx-json-schema-spec
6473
# sphinxcontrib-spelling
74+
sphinx-autoapi==1.9.0
75+
# via -r docs/requirements.in
6576
sphinx-autodoc-typehints==1.19.2
6677
# via -r docs/requirements.in
6778
sphinx-basic-ng==0.0.1a12
@@ -82,5 +93,9 @@ sphinxcontrib-serializinghtml==1.1.5
8293
# via sphinx
8394
sphinxcontrib-spelling==7.6.0
8495
# via -r docs/requirements.in
96+
unidecode==1.3.4
97+
# via sphinx-autoapi
8598
urllib3==1.26.11
8699
# via requests
100+
wrapt==1.14.1
101+
# via astroid

docs/spelling-wordlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ValidationError
77
# 0th, sigh...
88
th
99
callables
10+
# non-codeblocked cls from autoapi
11+
cls
1012
deque
1113
dereferences
1214
deserialize
@@ -33,6 +35,8 @@ regex
3335
repr
3436
runtime
3537
sensical
38+
submodule
39+
submodules
3640
subschema
3741
subschemas
3842
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
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`
@@ -109,6 +112,7 @@ existing `TypeChecker` or create a new one. You may then create a new
109112

110113

111114
.. autoexception:: jsonschema.exceptions.UnknownType
115+
:noindex:
112116

113117
.. _versioned-validators:
114118

@@ -121,16 +125,22 @@ that each validator class provides see the `Validator` protocol,
121125
which each included validator class implements.
122126

123127
.. autoclass:: Draft202012Validator
128+
:noindex:
124129

125130
.. autoclass:: Draft201909Validator
131+
:noindex:
126132

127133
.. autoclass:: Draft7Validator
134+
:noindex:
128135

129136
.. autoclass:: Draft6Validator
137+
:noindex:
130138

131139
.. autoclass:: Draft4Validator
140+
:noindex:
132141

133142
.. autoclass:: Draft3Validator
143+
:noindex:
134144

135145

136146
For example, if you wanted to validate a schema you created against the
@@ -181,7 +191,6 @@ validation can be enabled by hooking in a format-checking object into an
181191
:exclude-members: cls_checks
182192

183193
.. attribute:: checkers
184-
185194
A mapping of currently known formats to tuple of functions that
186195
validate them and errors that should be caught. New checkers can be
187196
added and removed either per-instance or globally for all checkers
@@ -204,6 +213,7 @@ validation can be enabled by hooking in a format-checking object into an
204213

205214

206215
.. autoexception:: FormatError
216+
:noindex:
207217
:members:
208218

209219

jsonschema/protocols.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import jsonschema
3232

3333
from jsonschema.exceptions import ValidationError
34-
from jsonschema.validators import RefResolver
3534

3635
# For code authors working on the validator protocol, these are the three
3736
# use-cases which should be kept in mind:
@@ -103,7 +102,7 @@ class Validator(Protocol):
103102
def __init__(
104103
self,
105104
schema: Mapping | bool,
106-
resolver: RefResolver | None = None,
105+
resolver: jsonschema.RefResolver | None = None,
107106
format_checker: jsonschema.FormatChecker | None = None,
108107
) -> None:
109108
...

0 commit comments

Comments
 (0)