如何使用 Django REST Swagger 记录 pk 参数(或其他路径参数)?
How can I document the pk parameter (or other path parameters) with Django REST Swagger?
有没有办法记录 Django REST Framework 自动生成的 pk 参数(通过扩展 ViewSet)?
ViewSet 中的示例函数:
class MyViewSet(viewsets.ViewSet):
@detail_route(url_path='mypath')
def myapi(self):
"""
first_param -- Param 1
"""
pass
如果我在 YAML 文档字符串中添加 pk 参数,我得到了一个副本。
可以使用 YAML 文档字符串记录 pk 参数(或任何其他路径参数),如 documentation of Django REST Swagger. For the list of attributes you can refer to the Swagger documentation.
中所述
请注意,您必须为路径参数指定 paramType: path
。为避免重复出现在您的 api-docs 中,您可以按照 here.
中的说明指定 parameters_strategy: replace
示例:
@detail_route(url_path='mypath')
def myapi(self, request, **kwargs):
"""
Endpoint documentation.
---
parameters_strategy: replace
parameters:
- name: pk
description: "Primary Key"
required: true
type: string
paramType: path
"""
有没有办法记录 Django REST Framework 自动生成的 pk 参数(通过扩展 ViewSet)?
ViewSet 中的示例函数:
class MyViewSet(viewsets.ViewSet):
@detail_route(url_path='mypath')
def myapi(self):
"""
first_param -- Param 1
"""
pass
如果我在 YAML 文档字符串中添加 pk 参数,我得到了一个副本。
可以使用 YAML 文档字符串记录 pk 参数(或任何其他路径参数),如 documentation of Django REST Swagger. For the list of attributes you can refer to the Swagger documentation.
中所述请注意,您必须为路径参数指定 paramType: path
。为避免重复出现在您的 api-docs 中,您可以按照 here.
parameters_strategy: replace
示例:
@detail_route(url_path='mypath')
def myapi(self, request, **kwargs):
"""
Endpoint documentation.
---
parameters_strategy: replace
parameters:
- name: pk
description: "Primary Key"
required: true
type: string
paramType: path
"""