Neoteroi / mkdocs-plugins

Plugins for MkDocs.
MIT License
128 stars 9 forks source link

[OpenAPI Docs, Question] Support for multi-file specifications #50

Open aremes opened 11 months ago

aremes commented 11 months ago

Hi! My OpenAPI spec gets properly translated into markdown and looks superb in mkdocs. However, since the file is pretty large it's a user-experience nightmare to have it all in one page. I was hoping to split the file (using redoclys openapi split command). This generates a root openapi.yaml file. Including this in an index.md using [OAD(<path-to-openapi.yaml>)] throws the following error:

Error reading page 'index.md': maximum recursion depth exceeded while calling a Python object

Here's the top of the stack trace (the last three lines then keep repeating for a while)

Traceback (most recent call last):
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\mkdocs\__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\mkdocs\commands\build.py", line 322, in build
    _populate_page(file.page, config, files, dirty)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\mkdocs\commands\build.py", line 171, in _populate_page
    page.markdown = config.plugins.on_page_markdown(
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\mkdocs\plugins.py", line 575, in on_page_markdown
    return self.run_event('page_markdown', markdown, page=page, config=config, files=files)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\mkdocs\plugins.py", line 507, in run_event
    result = method(item, **kwargs)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\neoteroi\mkdocs\oad\__init__.py", line 44, in on_page_markdown
    return self.rx.sub(self._replacer, markdown)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\neoteroi\mkdocs\oad\__init__.py", line 31, in _replacer
    handler = OpenAPIV3DocumentationHandler(
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 104, in __init__
    self.doc = self.normalize_data(copy.deepcopy(doc))
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 127, in normalize_data
    return self._transform_data(
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 144, in _transform_data
    clone[key] = self._handle_obj_ref(value, source_path)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 170, in _handle_obj_ref
    return self._transform_data(obj, source_path)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 144, in _transform_data
    clone[key] = self._handle_obj_ref(value, source_path)
  File "C:\Users\idontthinkso\AppData\Local\Programs\Python\Python310\lib\site-packages\openapidocs\mk\v3\__init__.py", line 167, in _handle_obj_ref
    return self._transform_data(sub_fragment, referred_file.parent)

So:

  1. Should there even be support for this?
  2. If not, would you be interested in adding it (i may consider contributing, but my python is rusty so dont hold your breath :)
  3. If supported: What am I dong wrong?
  4. Also if supported: Would that generate .md files for each part or still put it all in a single file?

I wouldnt mind skipping the redocly part altogether if there was an option to instruct your plugin to output the result from a single spec into multiple .md files (i.e. by tag, path, etc .. similarly to what openapi split does.) I havent yet looked into the source and before i do that, i just would like to ask:

Best Regards!