[英]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 參數,我會得到一個副本。
pk參數(或任何其他路徑參數)可以使用 YAML 文檔字符串進行記錄,如Django REST Swagger 文檔中所述。 有關屬性列表,您可以參考Swagger 文檔。
請注意,您必須為路徑參數指定paramType: path
。 為了避免您的API-docs的結束了重復的,你可以指定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
"""
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.