如何在Django REST Swagger 2中记录参数?

时间:2021-07-13 19:37:50

I used to specify the parameters using YAML Docstring, but they have now been deprecated. I have tried using coreapi.Field, as follows:

我曾经使用YAML Docstring指定参数,但是现在不赞成使用它们。我试过使用coreapi。字段,如下所示:

coreapi.Field(
    name='id',
    type='integer',
    required=True,
    location='query'
)

but it only works withViewSet.list, and not with, say, ViewSet.create. According to this report, this has been an on-going issue. The solution provided in the comments are quite hackish to me. I hope someone has already found (or came up with) a neater solution or alternative, perhaps a plugin or something.

但它只对viewset有效。列表,而不是ViewSet.create。根据这份报告,这是一个持续的问题。在评论中提供的解决方案对我来说是很陈腐的。我希望有人已经找到(或想出)一个更整洁的解决方案或替代方案,也许是一个插件什么的。

1 个解决方案

#1


1  

May be this is so late, but just for some help, you have to override the Schema generator to customize it, this doc explains django rest swagger 2 integration step by step: Django Rest Swagger 2 comprehensive documentation

可能这么晚了,但是为了帮助您,您必须重写模式生成器来定制它,这个文档一步一步地解释django rest的集成2:django rest虚张声势2全面的文档

you may think it a bit hacky but works perfectly fine.

你可能会觉得有点乱,但效果很好。

#1


1  

May be this is so late, but just for some help, you have to override the Schema generator to customize it, this doc explains django rest swagger 2 integration step by step: Django Rest Swagger 2 comprehensive documentation

可能这么晚了,但是为了帮助您,您必须重写模式生成器来定制它,这个文档一步一步地解释django rest的集成2:django rest虚张声势2全面的文档

you may think it a bit hacky but works perfectly fine.

你可能会觉得有点乱,但效果很好。