【问题标题】:django-rest-swagger nested serializers with readonly fields not rendered properlydjango-rest-swagger 嵌套序列化程序,只读字段未正确呈现
【发布时间】: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


【解决方案1】:

1. 请使用drf-yasg 获取文档。

2.您可以在我的一个存储库Kirpi 中找到它的实现,并了解如何使用它。

3. 如果你在 3. ;有问题,请告诉我。

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 2015-04-17
    • 1970-01-01
    相关资源
    最近更新 更多