How shutdown openapi in sanic-ext

because of openapi in sanic-ext didn't have a Authentication mode . So It not safe to generate the docs , everybody can see through http:/example.com/docs .

So I want to disable the autodoc , I did as the document asys https://sanic.dev/zh/plugins/sanic-ext/openapi/ui.html but It seems not work and raise an eeror. look below

# openapi configration
OAS_AUTODOC = False
OAS_UI_REDOC = False
OAS_UI_SWAGGER = False
raise error
[2022-10-19 08:14:02 +0800] [777332] [INFO]
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │                                  Sanic v22.9.0                                  │
  │                         Goin' Fast @ http://0.0.0.0:8000                        │
  ├───────────────────────┬─────────────────────────────────────────────────────────┤
  │                       │     mode: debug, single worker                          │
  │     ▄███ █████ ██     │   server: sanic, HTTP/1.1                               │
  │    ██                 │   python: 3.8.10                                        │
  │     ▀███████ ███▄     │ platform: Linux-5.4.0-128-generic-x86_64-with-glibc2.29 │
  │                 ██    │ packages: sanic-routing==22.8.0, sanic-ext==22.9.0      │
  │    ████ ████████▀     │                                                         │
  │                       │                                                         │
  │ Build Fast. Run Fast. │                                                         │
  └───────────────────────┴─────────────────────────────────────────────────────────┘

[2022-10-19 08:14:02 +0800] [777332] [DEBUG] Starting a process: Sanic-Server-0-0
Process Sanic-Server-0-0:
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/dist-packages/sanic/worker/serve.py", line 106, in worker_serve
    return _serve_http_1(
  File "/usr/local/lib/python3.8/dist-packages/sanic/server/runners.py", line 230, in _serve_http_1
    loop.run_until_complete(app._startup())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/usr/local/lib/python3.8/dist-packages/sanic/app.py", line 1494, in _startup
    self.ext._display()
  File "/usr/local/lib/python3.8/dist-packages/sanic_ext/bootstrap.py", line 114, in _display
    label = extension.render_label()
  File "/usr/local/lib/python3.8/dist-packages/sanic_ext/extensions/base.py", line 58, in render_label
    label = self.label()
  File "/usr/local/lib/python3.8/dist-packages/sanic_ext/extensions/openapi/extension.py", line 25, in label
    return self._make_url()
  File "/usr/local/lib/python3.8/dist-packages/sanic_ext/extensions/openapi/extension.py", line 41, in _make_url
    f"{self.app.url_for(name, _external=_external, _server=_server)}"
  File "/usr/local/lib/python3.8/dist-packages/sanic/app.py", line 585, in url_for
    raise URLBuildError(
sanic.exceptions.URLBuildError: Endpoint with name `openapi.index` was not found
/usr/lib/python3.8/multiprocessing/process.py:331: RuntimeWarning: coroutine 'Loop.create_server' was never awaited
  traceback.print_exc()
[2022-10-19 08:14:07 +0800] [777332] [ERROR] Not all workers are ack. Shutting down.
[2022-10-19 08:14:07 +0800] [777332] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/sanic/mixins/startup.py", line 851, in serve
    manager.run()
  File "/usr/local/lib/python3.8/dist-packages/sanic/worker/manager.py", line 63, in run
    self.monitor()
  File "/usr/local/lib/python3.8/dist-packages/sanic/worker/manager.py", line 99, in monitor
    self.wait_for_ack()
  File "/usr/local/lib/python3.8/dist-packages/sanic/worker/manager.py", line 139, in wait_for_ack
    sys.exit(1)
SystemExit: 1
[2022-10-19 08:14:07 +0800] [777332] [INFO] Server Stopped

I think what you want is this.

app.config.OAS = False
1 Like

Thank you very much ,It work.
on the offical page ,https://sanic.dev/zh/plugins/sanic-ext/openapi/autodoc.html#yaml-%E7%BA%A7%E6%93%8D%E4%BD%9C-operation-level-yaml
It doesn’t update yet. never mind

Unfortunately our translations are a bit behind. Hopefully that will be resolved.

1 Like