首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何注释请求正文来描述示例

如何注释请求正文来描述示例
EN

Stack Overflow用户
提问于 2021-04-12 04:30:53
回答 1查看 30关注 0票数 0

我正在努力正确地描述requestBody。我将此Dto作为请求正文:

代码语言:javascript
代码运行次数:0
运行
复制
public @Data class ContactDto {
@Parameter(description = "Mailadress required if messageType is MAIL")
private String mailAddress;
@Parameter(description = "Phonenumber required if messageType is not MAIL", example = 
"0041791234567")
private String phoneNumber;
@Parameter(description = "Message type which will be used to inform the user", examples = {
        @ExampleObject(name = "SMS", value = "SMS"),
        @ExampleObject(name = "MAIL", value = "MAIL")
})
private MessageType messageType;

}

在控制器中是这样的:

代码语言:javascript
代码运行次数:0
运行
复制
@PostMapping(consumes = "application/json")
public ResponseEntity<Object> createWichtel(@RequestBody() final WichtelDetailsDto wichtelDetailsDto) 
{
    return new ResponseEntity<>(HttpStatus.CREATED);
}

我将Spring与springdoc-openapi-ui一起使用

但是当我打开swagger-ui时,上面的描述并没有显示出来。这里的错误是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-12 04:51:58

只需使用@ApiParam即可

代码语言:javascript
代码运行次数:0
运行
复制
public @Data class ContactDto {
@ApiParam(value = "Mailadress required if messageType is MAIL")
private String mailAddress;
@ApiParam(value = "Phonenumber required if messageType is not MAIL", example = 
"0041791234567")
private String phoneNumber;
@ApiParam(value = "Message type which will be used to inform the user", example = "{(name = \"SMS\", value = \"SMS\")}")
private MessageType messageType;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67049928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档