gpt4 book ai didi

django - drf-spectacular 使用错误的 AutoSchema 来生成 Swagger

转载 作者:行者123 更新时间:2023-12-03 14:52:38 32 4
gpt4 key购买 nike

以前我用的是 drf-yasg但想要更新以使用 OpenAPI 3。我正在尝试切换到 drf-spectacular .关注 instruction ,我跑了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?

最佳答案

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

关于django - drf-spectacular 使用错误的 AutoSchema 来生成 Swagger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64545861/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com