sphinx-contrib / openapi

OpenAPI (fka Swagger) spec renderer for Sphinx.
https://sphinxcontrib-openapi.readthedocs.io
BSD 2-Clause "Simplified" License
109 stars 79 forks source link

Allow anyOf in schema #146

Open cedricbonhomme opened 8 months ago

cedricbonhomme commented 8 months ago

Hello !

I am using the new release with the fix from the PR #143 and there is still an issue iwht anyOf attribute.

Example:

$ make doc 
python contrib/openapi.py
rm -Rf docs/_build
sphinx-build docs/ docs/_build/html
Running Sphinx v4.5.0
making output directory... done
checking bibtex cache... out of date
parsing bibtex file /home/cedric/git/SCANDAL/scandale/docs/refs.bib... parsed 8 entries
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 6 source files that are out of date
updating environment: [new config] 6 added, 0 changed, 0 removed
reading sources... [ 50%] formats                                                                                                                                                                         
Exception occurred:
  File "/home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/openapi/openapi31.py", line 305, in _get_type_from_schema
    for t in schema["anyOf"]:
KeyError: 'anyOf'
The full traceback has been saved in /tmp/sphinx-err-x_7m9qol.log, if you want to report the issue to the developers.

Below is the log file of the execution:

$ cat /tmp/sphinx-err-_2fr90vn.log
# Sphinx version: 4.5.0
# Python version: 3.10.13 (CPython)
# Docutils version: 0.17.1 release
# Jinja2 version: 3.0.3
# Last messages:
#   parsing bibtex file /home/cedric/git/SCANDAL/scandale/docs/refs.bib...
#   parsed 8 entries
#   building [mo]: targets for 0 po files that are out of date
#   building [html]: targets for 6 source files that are out of date
#   updating environment:
#   [new config]
#   6 added, 0 changed, 0 removed
#   reading sources... [ 16%] architecture
#   reading sources... [ 33%] deployment
#   reading sources... [ 50%] formats
# Loaded extensions:
#   sphinx.ext.mathjax (4.5.0) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.4) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (2.0.1) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.13) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/alabaster/__init__.py
#   sphinx.ext.autodoc.preserve_defaults (1.0) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx/ext/autodoc/preserve_defaults.py
#   sphinx.ext.autodoc.type_comment (4.5.0) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx/ext/autodoc/type_comment.py
#   sphinx.ext.autodoc (4.5.0) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx/ext/autodoc/__init__.py
#   sphinx_autodoc_typehints (unknown version) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx_autodoc_typehints/__init__.py
#   sphinxcontrib.mermaid (4.5.0) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/mermaid.py
#   sphinxcontrib.bibtex (2.6.1) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/bibtex/__init__.py
#   sphinxcontrib.httpdomain (unknown version) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/httpdomain.py
#   sphinxcontrib.openapi (0.8.3) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/openapi/__init__.py
#   sphinx_book_theme (unknown version) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinx_book_theme/__init__.py
#   pydata_sphinx_theme (unknown version) from /home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/pydata_sphinx_theme/__init__.py
Traceback (most recent call last):
.
.
.
.
  File "/home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/openapi/renderers/_httpdomain_old.py", line 55, in render_restructuredtext_markup
    yield from openapihttpdomain(spec, **self._options)
  File "/home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/openapi/openapi31.py", line 314, in _httpresource
    type_ = _get_type_from_schema(param["schema"])
  File "/home/cedric/.cache/pypoetry/virtualenvs/scandale-YR99gNwR-py3.10/lib/python3.10/site-packages/sphinxcontrib/openapi/openapi31.py", line 305, in _get_type_from_schema
    for t in schema["anyOf"]:
KeyError: 'anyOf'

The openapi.json file has been generated by FastAPI. See here. Swagger UI and redoc UI are working fine.

cedricbonhomme commented 8 months ago

The OpenAPI file used is this one: https://github.com/scandale-project/scandale/blob/main/docs/_static/openapi.json

cedricbonhomme commented 8 months ago

It is also possible to see the logs on ReadTheDocs: https://readthedocs.org/projects/scandale/builds/22900095/

cedricbonhomme commented 8 months ago

I've just proposed a fix to this issue. Could you see if it can be accepted ? Thanks !

dlvilla commented 4 months ago

This caused a failure for me as well. The solution above fixed it. A new release with this fix will help me use sphinxcontrib.openapi

pankajrlal commented 2 months ago

What is the plan to release this fix, @cedricbonhomme ?

dlvilla commented 1 month ago

This caused a failure for me as well. The solution above fixed it. A new release with this fix will help me use sphinxcontrib.openapi

Still waiting for this to be fixed!