Swagger 2 Springfox忽略了@ApiModel

问题描述

我正在尝试使用SpringFox将Swagger文档添加到Spring Boot中创建的端点。端点在功能上无法更改,这意味着我无法真正重构它,但可以添加任何所需的注释。我正在进行一种设置,其中端点将空接口作为REST服务的参数。该接口具有许多子类型,这些子类型最终将代替该接口发送到端点(我仅以示例为例,还有更多),但是Swagger并不奇怪。 @Data注释来自Lombok,@ JsonDeserialize来自Jackson。

@Controller
@RequestMapping("/api/myendpoint")
public class MyEndpoint {

     ...

     @SecurityDescriptor(Permission.PLANS_CREATE)
     @ApiOperation(value = "Awesome method",notes = "Permission.PLANS_CREATE\nDoes stuff")
     @PostMapping()
     public ResponseEntity<OutputDTO> makeTheMagicHappen(@RequestBody InputDTO dto) {
         return new ResponseEntity<>(myService.theMagic(dto),HttpStatus.OK);
     }
 ...

}

输入DTO:

@JsonDeserialize(using = SomeDeserializer.class)
@Data
public class InputDTO {
    private Long id;
    private String type;
    private EmptyDTO extension;
}

有问题的界面DTO

public interface EmptyDTO  {
}

与实际的dto一起发送请求,以代替Empty DTO

@Data
public class ActualDTO implements EmptyDTO {

    private String importantString;
    private Integer importantInteger;
}

生成的swaggerui示例如下所示。请注意,扩展名可能被解释为空对象,这可能是由于EmptyDTO接口所致。

{
  "Id": 0,"extension": {},"type": "String"
}

EmptyDTO出现在swaggerui的模型部分中,但ActualDTO却没有。 我尝试在空的dto中添加@ApiModel批注,并将ActualDTO定义为子类型

@ApiModel(subTypes = {ActualDTO.class},description = "Empty DTO")
public interface EmptyDTO  {
}

@ApiModel(parent= EmptyDTO.class,description = "Actual DTO")
@Data
public class ActualDTO implements EmptyDTO {

    private String importantString;
    private Integer importantInteger;
}

这对swaggerui没有任何影响,“ models”部分中仍然没有显示ActualDTO,该扩展示例也未显示端点示例,除了{}之外。

我试图给DTO越来越愚蠢的名字,并将父类和子类型设置为相同的类,只是为了查看swagger ui的变化。但是,无论现在我对ApiModel批注进行多大修改,似乎对swaggerui都没有影响。这使我相信ApiModel批注实际上并未被读取。所以问题实际上是两个问题:

  1. 如何让我大胆地了解这个空接口应该被许多子类取代?
  2. 我是如何激怒了强大的Spring,为什么我的ApiModel批注似乎没有被解析?

这些是正在播放的版本:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
</parent>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>swagger-ui</artifactId>
    <version>2.2.10</version>
</dependency>

解决方法

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

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

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...