Swagger UI 不会在 POST 中使用 Spring Boot

问题描述

我正在使用 swagger-ui 3.0.0 版和 Spring boot 2.5.2 版,我正在尝试记录我的 REST Api,但我坚持使用 POST 请求,因为 swagger ui 没有为 POST 参数生成 JSON它将它生成为字符串字段。

这是我的控制器:-

@RequestMapping(value = "/message",produces = { "application/json;charset=utf-8" },consumes = { "application/json;charset=utf-8" },method = RequestMethod.POST) 
ResponseEntity<?> createMessage( @RequestBody Message message);

这是我的模型:-

@ApiModel(description = "")
@Validated
public class Message {
    
      @ApiModelProperty(required = true,value = "")
      @NotNull
      @JsonProperty("code")
      private Integer code = null;
      
      @ApiModelProperty(required = true,value = "")
      @NotNull
      @JsonProperty("message")
      private String message = null;

以下是swagger ui为此代码生成的图像:-

actual swagger ui image

但我希望它看起来像这个带有对象 JOSN 的 POST 参数(这是别人的代码):-

expected swagger ui

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)