Django休息框架字段描述空白

时间:2017-12-31 00:02:08

标签: django-rest-framework

在Django休息框架中,我正在使用AutoSchema类创建文档页面。对于选定的API端点,我使用manual_fields为各个字段添加文档条目。这些条目按照预期在漂亮的表中显示在doc页面上,但“Description”列是空白的,即使我在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):
    ...

1 个答案:

答案 0 :(得分:6)

使用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),
            ]
        )