Skip to content

Commit 68fad03

Browse files
authored
Merge pull request #989 from python-jsonschema/api
Enable dedicated API documentation page(s)
2 parents 9c79837 + 1ad00c8 commit 68fad03

File tree

13 files changed

+91
-15
lines changed

13 files changed

+91
-15
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/faq.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The JSON object ``{}`` is simply the Python `dict` ``{}``, and a JSON Schema lik
8585

8686
The :kw:`$ref` keyword is a single notable exception.
8787

88-
Specifically, in the case where `jsonschema` is asked to `resolve a remote reference <RefResolver>`, it has no choice but to assume that the remote reference is serialized as JSON, and to deserialize it using the `json` module.
88+
Specifically, in the case where `jsonschema` is asked to `resolve a remote reference <jsonschema.validators.RefResolver>`, it has no choice but to assume that the remote reference is serialized as JSON, and to deserialize it using the `json` module.
8989

9090
One cannot today therefore reference some remote piece of YAML and have it deserialized into Python objects by this library without doing some additional work.
9191

@@ -104,7 +104,7 @@ How do I configure a base URI for $ref resolution using local files?
104104

105105
`jsonschema` supports loading schemas from the filesystem.
106106

107-
The most common mistake when configuring a :class:`~jsonschema.RefResolver`
107+
The most common mistake when configuring a `jsonschema.validators.RefResolver`
108108
to retrieve schemas from the local filesystem is to give it a base URI
109109
which points to a directory, but forget to add a trailing slash.
110110

@@ -212,8 +212,8 @@ be valid under the schema.)
212212

213213
See the above-linked document for more info on how this works,
214214
but basically, it just extends the :kw:`properties` keyword on a
215-
`jsonschema.Draft202012Validator` to then go ahead and update all the
216-
defaults.
215+
`jsonschema.validators.Draft202012Validator` to then go ahead and update
216+
all the defaults.
217217

218218
.. note::
219219

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

0 commit comments

Comments
 (0)