【发布时间】:2015-07-06 05:22:56
【问题描述】:
我正在使用 django-rest-framework 构建一个 API,并开始使用 django-rest-swagger 获取文档。 我有一个带有一些只读字段的嵌套序列化程序,如下所示:
# this is the nested serializer
class Nested(serializers.Serializer):
normal_field = serializers.CharField(help_text="normal")
readonly_field = serializers.CharField(read_only=True,
help_text="readonly")
# this is the parent one
class Parent(serializers.Serializer):
nested_field = Nested()
在生成的文档中,页面的 Parameters 部分中的嵌套序列化程序使用 field 数据类型呈现,并且没有给出关于其内容的提示,它们就像其他字段。
现在您可以在那里看到问题,因为我想通知用户有一个只读字段不应作为嵌套数据的一部分发送,但我看不到这样做的方法。
理想的情况是在数据类型列中包含模型描述,就像 响应类 section。
有什么合适的方法吗?
【问题讨论】:
-
django-rest-swagger 不再被维护。使用 drf-yasg
标签: python django django-rest-framework documentation-generation