sphinx-contrib / openapi

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

0.7.0 - sphinx-build raises AttributeError #122

Closed kylerws closed 2 years ago

kylerws commented 2 years ago

Unable to run sphinx-build after adding openapi directive to source files. Sphinx raises an Attribute Error for module collections.

Exception occurred:
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\utils.py", line 38, in _do_resolve
    if isinstance(node, collections.Mapping) and '$ref' in node:
AttributeError: module 'collections' has no attribute 'Mapping'

Versions:

# Sphinx version: 4.3.1
# Python version: 3.10.0 (CPython)
# Docutils version: 0.17.1 release
# Jinja2 version: 3.0.2

Full traceback:

#   sphinxcontrib.openapi (None) from C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\__init__.py
Traceback (most recent call last):
  File "C:\Users\ ... \env\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "C:\Users\ ... \env\lib\site-packages\sphinx\application.py", line 344, in build
    self.builder.build_update()
  File "C:\Users\ ... \env\lib\site-packages\sphinx\builders\__init__.py", line 294, in build_update
    self.build(to_build,
  File "C:\Users\ ... \env\lib\site-packages\sphinx\builders\__init__.py", line 308, in build
    updated_docnames = set(self.read())
  File "C:\Users\ ... \env\lib\site-packages\sphinx\builders\__init__.py", line 415, in read
    self._read_serial(docnames)
  File "C:\Users\ ... \env\lib\site-packages\sphinx\builders\__init__.py", line 436, in _read_serial
    self.read_doc(docname)
  File "C:\Users\ ... \env\lib\site-packages\sphinx\builders\__init__.py", line 476, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "C:\Users\ ... \env\lib\site-packages\sphinx\io.py", line 189, in read_doc
    pub.publish()
  File "C:\Users\ ... \env\lib\site-packages\docutils\core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "C:\Users\ ... \env\lib\site-packages\sphinx\io.py", line 109, in read
    self.parse()
  File "C:\Users\ ... \env\lib\site-packages\docutils\readers\__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "C:\Users\ ... \env\lib\site-packages\sphinx\parsers.py", line 101, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 170, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "C:\Users\ ... \env\lib\site-packages\docutils\statemachine.py", line 239, in run
    context, next_state, result = self.check_line(
  File "C:\Users\ ... \env\lib\site-packages\docutils\statemachine.py", line 451, in check_line
    return method(match, context, next_state)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 2769, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\ ... \env\lib\site-packages\docutils\statemachine.py", line 239, in run
    context, next_state, result = self.check_line(
  File "C:\Users\ ... \env\lib\site-packages\docutils\statemachine.py", line 451, in check_line
    return method(match, context, next_state)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 2342, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 2354, in explicit_construct
    return method(self, expmatch)
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 2096, in directive
    return self.run_directive(
  File "C:\Users\ ... \env\lib\site-packages\docutils\parsers\rst\states.py", line 2146, in run_directive
    result = directive_instance.run()
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\directive.py", line 124, in run
    for line in openapihttpdomain(spec, **self.options):
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\openapi20.py", line 191, in openapihttpdomain
    utils.normalize_spec(spec, **options)
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\utils.py", line 57, in normalize_spec
    spec = _resolve_refs(options.get('uri', ''), spec)
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\utils.py", line 49, in _resolve_refs
    return _do_resolve(spec)
  File "C:\Users\ ... \env\lib\site-packages\sphinxcontrib\openapi\utils.py", line 38, in _do_resolve
    if isinstance(node, collections.Mapping) and '$ref' in node:
AttributeError: module 'collections' has no attribute 'Mapping'
kylerws commented 2 years ago

Closing, as the issue was pip defaulting to install version 0.6.0.

Fix was to require version 0.7.0 and specify the mistune library version to 0.8.4 as mentioned here: #121