[英]how to specify example value on drf-yasg swagger_auto_schema request_body?
I everyone.我大家。 My question is similar to the one planted here , but in this case I would like to do the same with the request_body parameter.我的问题与种植在这里的问题相似,但在这种情况下,我想对 request_body 参数做同样的事情。 How can I add an example value for the request_body parameter, similary as it is done there with the response parameter?如何为 request_body 参数添加示例值,类似于使用 response 参数在此处完成的操作? Thanks for your attention and your help感谢您的关注和帮助
You should use the example parameter.您应该使用示例参数。 Look at this example:看这个例子:
request_schema_dict = openapi.Schema(
title=_("Update order"),
type=openapi.TYPE_OBJECT,
properties={
'ordered_items': openapi.Schema(type=openapi.TYPE_ARRAY, description=_('Ordered items list'),
items=openapi.Schema(type=openapi.TYPE_OBJECT, description=_('Ordered item'),
properties={
'item': openapi.Schema(type=openapi.TYPE_STRING, description=_('Item id'), example="123*123*0001"),
'quantity': openapi.Schema(type=openapi.TYPE_NUMBER, description=_('Ordered quantity'), example=12.33),
'sequence_number': openapi.Schema(type=openapi.TYPE_INTEGER,
description=_('Sequence of item inclusion in the order.'), example=1),
}
)
),
'status': openapi.Schema(type=openapi.TYPE_STRING, description=_('Order status'), example=1, enum=[0,1,2,3,4,5]),
'invoicing_date': openapi.Schema(type=openapi.TYPE_STRING, description=_('Invoice date'),
example="2022-05-27T12:48:07.256Z", format="YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]"),
'invoice_number': openapi.Schema(type=openapi.TYPE_STRING, description=_('Invoice number'), example="123456789"),
'note': openapi.Schema(type=openapi.TYPE_STRING, description=_('Client user note'), example=_("Client user note")),
'agent_note': openapi.Schema(type=openapi.TYPE_STRING, description=_('Agent note'), example=_("Agent note")),
}
)
@swagger_auto_schema(request_body=request_schema_dict, responses={200: 'Order updated.'})
def put(self, request, id):
..............
This will generate the following output on swagger:这将在 swagger 上生成以下输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.