9

以前我正在使用drf-yasg但想更新以使用 OpenAPI 3。我正在尝试切换到drf-spectacular. 按照说明运行pip install drf-spectacular,我删除了对drf-yasg包的所有引用,并更新Settings.py如下:

INSTALLED_APPS = [ 
    ...
    "drf_spectacular",
]


REST_FRAMEWORK = {
    "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}

当我使用 CLI 生成架构时,我得到了以下信息AssertionError。如果有人以前遇到过这个问题并有任何见解,将不胜感激!

我正在使用 Python 3.7、Django 3.0、Django Rest Framework 3.11 和 DRF Spectacular 0.10.0。

Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    main()
  File "manage.py", line 19, in main
    execute_from_command_line(sys.argv)
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/drf_spectacular/management/commands/spectacular.py", line 50, in handle
    schema = generator.get_schema(request=None, public=True)
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/drf_spectacular/generators.py", line 187, in get_schema
    paths=self.parse(request, public),
  File "/opt/anaconda3/envs/dev/lib/python3.7/site-packages/drf_spectacular/generators.py", line 160, in parse
    'Incompatible AutoSchema used on View. Is DRF\'s DEFAULT_SCHEMA_CLASS '
AssertionError: Incompatible AutoSchema used on View. Is DRF's DEFAULT_SCHEMA_CLASS pointing to "drf_spectacular.openapi.AutoSchema" or any other drf-spectacular compatible AutoSchema?
4

1 回答 1

2

请将 Django Rest Framework 3.11 更新到 3.12 它将工作。

于 2020-11-06T10:56:51.093 回答