在Django的Swagger上显示请求正文的不同示例

时间:2020-06-02 13:26:49

标签: python django swagger swagger-ui

我正在尝试为Swagger显示不同内容类型的不同示例。我为对应的视图使用以下方法装饰器:

DBS=subset(RatingScores,RatingScores$Condition=="Disfluent"&RatingScores$QuoteType=="BS")
FBS=subset(RatingScores,RatingScores$Condition=="Fluent"&RatingScores$QuoteType=="BS")
DMo=subset(RatingScores,RatingScores$Condition=="Disfluent"&RatingScores$QuoteType=="Motiv")
FMo=subset(RatingScores,RatingScores$Condition=="Fluent"&RatingScores$QuoteType=="Motiv")

我希望能够同时接收'text / plain''application / json'类型,并且我想分别为它们显示不同的示例。当我添加ggscatter(DMo, x = "Rating", y = "Correct", add = "reg.line",point = F,color = "green", conf.int = F, cor.coef = TRUE, cor.method = "pearson", title = "Disfluent Mo", xlab = "Rating", ylab = "CRT Score") 字段时,我能够获得from drf_yasg.utils import swagger_auto_schema from django.utils.decorators import method_decorator from drf_yasg import openapi test_decorator = method_decorator(name='post', decorator=swagger_auto_schema( tags=['Models'], responses={ "200": ModelListSerializer, "400": "Validation Error", "403": "Permission Error", "404": "Not Found Error", }, consumes={'text/plain', 'application/json'} )) 的下拉列表。 据我了解,不可能为consumes字段提供列表或字典。我在Parameter content type中看到了here,您可以在内容字段中定义示例。 我尝试将以下内容传递给request_body字段:

Request and Response Body Examples
request_body

是否可以将它们组合在一起?

我正在使用:

request_body=Schema(
    type=openapi.TYPE_STRING,
    example='Test string',
    content='text/plain'
)

0 个答案:

没有答案