【问题标题】:Django rest framework field descriptions blankDjango rest 框架字段描述空白
【发布时间】:2017-12-31 00:02:07
【问题描述】:

在 Django rest 框架中,我正在使用 AutoSchema 类创建一个文档页面。对于选定的 API 端点,我使用 manual_fields 为各个字段添加文档条目。这些条目按预期出现在文档页面上,在漂亮的表格中,但“描述”列是空白的,即使我在 coreapi.Field() 构造函数中包含了描述 arg。如何让描述出现在表格中?

这是一个示例字段定义:

class FooList(APIView):
''' List the Foos
'''              
schema = AutoSchema(
    manual_fields=[
    coreapi.Field(
        name='format',
    location='query',
    description='The format in which to return results. One of: api, json',
    required=False),
        ]
    )

def get(request, format=None):
    ...

【问题讨论】:

    标签: django-rest-framework


    【解决方案1】:

    使用 coreschema 模块来描述 api-shcema/ 或 api-docs/ 将正确显示的字段。示例:

    schema=coreschema.String(title='Format', description='The format in which to return results. One of: api, json'),
    
    schema = AutoSchema(
            manual_fields=[
            coreapi.Field(
                name='format',
                location='query',
                schema=coreschema.String(description='The format in which to return results. One of: api, json'),
                required=False),
                ]
            )
    

    【讨论】:

    • 您需要添加一些关于它如何形成答案的描述。指出您解决的问题。否则,它看起来就像从问题中复制的文本。
    猜你喜欢
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 2018-01-15
    • 2013-03-06
    • 1970-01-01
    相关资源
    最近更新 更多