Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jinja2.exceptions.UndefinedError: 'components' is undefined #9

Closed
MathKlim opened this issue May 5, 2022 · 4 comments
Closed

jinja2.exceptions.UndefinedError: 'components' is undefined #9

MathKlim opened this issue May 5, 2022 · 4 comments

Comments

@MathKlim
Copy link

MathKlim commented May 5, 2022

Hi !

I tried this new add-on for mkdocs and mkdocs-material, with a swagger.json documentation coming from some AzureML endpoint API, and I get the following error when trying to serve my doc.

mkdocs serve
INFO     -  Building documentation...
INFO     -  Cleaning site directory
/home/vorph/.local/lib/python3.9/site-packages/openapidocs/mk/v3/__init__.py:204: UserWarning: Missing section in components. A security scheme referenced in a path item is not configured.
  warnings.warn(
ERROR    -  Error reading page 'azure_ml/lesson4.md': 'components' is undefined
Traceback (most recent call last):
  File "/home/vorph/.local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/vorph/.local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/vorph/.local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/vorph/.local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/vorph/.local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/vorph/.local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/__main__.py", line 181, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 63, in serve
    config = builder()
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 58, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 292, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 170, in _populate_page
    page.markdown = config['plugins'].run_event(
  File "/home/vorph/.local/lib/python3.9/site-packages/mkdocs/plugins.py", line 102, in run_event
    result = method(item, **kwargs)
  File "/home/vorph/.local/lib/python3.9/site-packages/neoteroi/mkdocsoad/__init__.py", line 42, in on_page_markdown
    return self.rx.sub(self._replacer, markdown)
  File "/home/vorph/.local/lib/python3.9/site-packages/neoteroi/mkdocsoad/__init__.py", line 32, in _replacer
    return handler.write(data)
  File "/home/vorph/.local/lib/python3.9/site-packages/openapidocs/mk/v3/__init__.py", line 326, in write
    return self._writer.write(
  File "/home/vorph/.local/lib/python3.9/site-packages/openapidocs/mk/jinja.py", line 104, in write
    return template.render(data, **kwargs)
  File "/home/vorph/.local/lib/python3.9/site-packages/jinja2/environment.py", line 1291, in render
    self.environment.handle_exception()
  File "/home/vorph/.local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/vorph/.local/lib/python3.9/site-packages/openapidocs/mk/v3/views_mkdocs/layout.html", line 17, in top-level template code
    {%- if components.schemas %}
  File "/home/vorph/.local/lib/python3.9/site-packages/jinja2/environment.py", line 474, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'components' is undefined
make: *** [makefile:3: docs] Error 1

I did follow the recommendations by enabling pymdownx and adding the extra css.

plugins:
  - search:
      lang: fr
  - neoteroi.mkdocsoad:
      use_pymdownx: true

extra_css:
  - stylesheets/mkdocsoad.css

markdown_extensions:
  - pymdownx.highlight:
      linenums: true
      anchor_linenums: true
  - pymdownx.inlinehilite
  - pymdownx.superfences
  - pymdownx.snippets
  - pymdownx.tabbed:
      alternate_style: true

If I remove [OAD(./includes/swagger.json)] from the markdown file where I put it, the doc is served without any problem.

My mkdocs packages seem to be up to date.

vorph@677d86b35cc5:~/formationML$ pip freeze | grep mkdoc
mkdocs==1.3.0
mkdocs-autorefs==0.4.1
mkdocs-material==8.2.13
mkdocs-material-extensions==1.0.3
mkdocstrings==0.18.1
mkdocstrings-python-legacy==0.2.2
neoteroi-mkdocs==0.0.4

Do you need any other infos that might be useful ?

@RobertoPrevato
Copy link
Member

Hi @MathKlim,
Thank You for reporting this issue. I don't need any more information, I already reproduced the error and I am fixing it.

I'll let you know, leaving a comment here, when it's fixed in PyPi and how to update to make it working.

I expected this kind of bugs reports because I didn't have the time to test many scenarios of OpenAPI specification files.

@RobertoPrevato
Copy link
Member

@MathKlim
Can you please try to run:

pip install -U essentials-openapi

to upgrade this package to 1.0.1? The bug you reported should be fixed now. The code wasn't handling properly the situation of missing components property from the OAD specification.

@MathKlim
Copy link
Author

MathKlim commented May 5, 2022

Did the pip install, there is no more problem.

fixed

Thanx !

@RobertoPrevato
Copy link
Member

Thank You for letting me know. 😃 I see you get the "Other responses" text without more responses to show - I'll look into this.
I'm still improving the package, because the OAD specification has so many options. Right now I'm looking into support for splitting spec files #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants