Skip to content

Commit 9afa811

Browse files
committed
docs: Add docs for new renderer
Signed-off-by: Stephen Finucane <[email protected]>
1 parent aea54c3 commit 9afa811

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

docs/index.rst

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ It depends on `sphinxcontrib-httpdomain`_, which provides an HTTP domain for des
1414
pip install sphinxcontrib-openapi
1515
1616
17-
How To Use?
18-
===========
17+
Usage
18+
=====
1919

2020
Consider you have the following OpenAPI spec saved at ``specs/openapi.yml``:
2121

@@ -33,10 +33,100 @@ and it will be rendered into something like:
3333
.. openapi:: specs/openapi.yml
3434

3535

36+
Configuration
37+
=============
38+
39+
The extension provides two configuration options.
40+
41+
``openapi_renderers``
42+
A mapping of renderer aliases to the classes.
43+
Two renderer classes are provided but it is possible to define your own renderer class.
44+
This allows you to add support for things like additional type formats or custom extensions (``x``-prefixed attributes).
45+
46+
:Type: A mapping of renderer aliases to the implementation class.
47+
:Default: ``{'httpdomain': sphinxcontrib.openapi.renderers.HttpdomainRenderer, 'httpdomain:old': sphinxcontrib.openapi.renderers.HttpdomainOldRenderer}``
48+
49+
``openapi_default_renderer``
50+
The renderer to use.
51+
This must be one of the renderers defined in ``openapi_renderers``.
52+
53+
:Type: A string corresponding to the alias of a registered renderer.
54+
:Default: ``'httpdomain:old'``
55+
56+
3657
Options
3758
=======
3859

39-
The ``openapi`` directive supports the following options:
60+
The ``openapi`` directive supports different options depending on the renderer in use.
61+
62+
Options for the ``httpdomain`` renderer
63+
---------------------------------------
64+
65+
The following options take a value.
66+
67+
``encoding``
68+
Encoding to be used to read an OpenAPI spec. If not passed, Sphinx's source encoding will be used.
69+
70+
``markup``
71+
The format to use when parsing markup.
72+
73+
:Type: One of ``commonmark``, ``restructuredtext``
74+
:Default: ``commonmark``
75+
76+
``http-methods-order``
77+
The preferred order in which to output HTTP methods.
78+
79+
:Type: An CSV string of HTTP methods.
80+
:Default: ``None``
81+
82+
``response-examples-for``
83+
The response codes to render samples for.
84+
85+
:Type: A sequence of strings, with each string corresponding to a `HTTP status code <https://spec.openapis.org/oas/v3.1.0#http-status-codes>`__ that response examples should be rendered for.
86+
:Default: ``["200", "201", "202", "2XX"]``
87+
88+
``request-parameters-order``
89+
The preferred order in which to output parameters.
90+
91+
:Type: An ordered sequence of strings, with each string corresponding to a `supported parameter type <https://spec.openapis.org/oas/v3.1.0#fixed-fields-9>`__.
92+
:Default: ``None``
93+
94+
``example-preference``
95+
The preferred example format to render for requests and responses.
96+
97+
:Type: An ordered sequence of strings, with each string corresponding to a `supported media type <https://spec.openapis.org/oas/v3.1.0#media-types>`__.
98+
:Default: ``None``
99+
100+
``request-example-preference``
101+
The preferred example format to render for requests. This takes precedence over ``example-preference``.
102+
103+
:Type: An ordered sequence of strings, with each string corresponding to a `supported media type <https://spec.openapis.org/oas/v3.1.0#media-types>`__.
104+
:Default: ``None``
105+
106+
``response-example-preference``
107+
The preferred example format to render for responses. This takes precedence over ``example-preference``.
108+
109+
:Type: An ordered sequence of strings, with each string corresponding to a `supported media type <https://spec.openapis.org/oas/v3.1.0#media-types>`__.
110+
:Default: ``None``
111+
112+
The following options are boolean flags.
113+
114+
``generate-examples-from-schemas``
115+
116+
Whether examples should be generated from the schema if they are not provided in the spec. If unset, examples will not be generated.
117+
118+
:Type: Flag.
119+
120+
``no-json-schema-description``
121+
122+
Whether to disable rendering of JSON schema hints.
123+
124+
:Type: Flag.
125+
126+
Options for the ``httpdomain:old`` renderer
127+
-------------------------------------------
128+
129+
The following options are supported when using the ``httpdomain:old`` renderer:
40130

41131
``encoding``
42132
Encoding to be used to read an OpenAPI spec. If not passed, Sphinx's source encoding will be used.
@@ -123,7 +213,6 @@ When used together, ``exclude`` takes precedence over ``include`` and ``paths``.
123213
124214
Would render the ``head`` method, followed by the ``get`` method, followed by the rest of the methods in their declared ordered.
125215

126-
127216
.. _Sphinx: https://www.sphinx-doc.org/en/master/
128217
.. _OpenAPI: https://github.com/OAI/OpenAPI-Specification
129218
.. _sphinxcontrib-httpdomain: https://sphinxcontrib-httpdomain.readthedocs.io/

0 commit comments

Comments
 (0)