[英]django-rest-framework and swagger api documentation
I looked at django-rest-swagger project and I want to use it to document api for my project. 我看了一下django-rest-swagger项目,我想用它来为我的项目记录api。 But there is some questions on how to do it.
但是如何做到这一点还有一些问题。
How to use help_text attribute on model or serializer? 如何在模型或序列化器上使用help_text属性? In the documentation it said: "Field help_text property is used to create the description from the serializer or model.".
在文档中它说:“字段help_text属性用于从序列化器或模型创建描述。” But api documentation contains only field names and field types and there is no default values description (in this example for field colour) eg
但api文档仅包含字段名称和字段类型,并且没有默认值描述(在此示例中为字段颜色),例如
Response Class CigarSerializer { name (string), url (url, optional), colour (string), price (decimal), length (integer), gauge (integer), notes (string), id (integer, optional), manufacturer (field) }
Can I include help_text attribute in api documentation? 我可以在api文档中包含help_text属性吗?
Can I include serializer doc string in api documentation? 我可以在api文档中包含序列化器文档字符串吗?
Your Serializer definition above isn't correct. 上面的Serializer定义不正确。 Here's how you should define your Serializer with
help_text
: 以下是使用
help_text
定义Serializer的help_text
:
class CigarSerializer(serializers.ModelSerializer):
url = fields.URLField(source='get_absolute_url', read_only=True, help_text="this is where you add help text")
...
class Meta:
model = models.Cigar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.