Java 大摇大摆2 Springfox忽略@ApiModel
我正在尝试将Swagger文档添加到使用SpringFox在Spring Boot中创建的端点。端点在功能上不能改变,这意味着我不能真正重构它,但我可以添加任何我想要的注释。我正在进行一个设置,其中端点将空接口作为REST服务的参数。这个接口有许多子类型,这些子类型最终将被发送到端点而不是接口(我只是在示例中显示一个,还有更多),但这并不奇怪,因为它没有受到炫耀的影响。@Data注释来自Lombok,@JsonDeserialize来自JacksonJava 大摇大摆2 Springfox忽略@ApiModel,java,spring,swagger,springfox,Java,Spring,Swagger,Springfox,我正在尝试将Swagger文档添加到使用SpringFox在Spring Boot中创建的端点。端点在功能上不能改变,这意味着我不能真正重构它,但我可以添加任何我想要的注释。我正在进行一个设置,其中端点将空接口作为REST服务的参数。这个接口有许多子类型,这些子类型最终将被发送到端点而不是接口(我只是在示例中显示一个,还有更多),但这并不奇怪,因为它没有受到炫耀的影响。@Data注释来自Lombok,@JsonDeserialize来自Jackson @Controller @RequestMa
@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
public interface EmptyDTO {
}
以及发送请求的实际dto,而不是空dto
@Data
public class ActualDTO implements EmptyDTO {
private String importantString;
private Integer importantInteger;
}
由此产生的swaggerui示例如下所示。请注意,扩展被解释为空对象,可能是因为EmptyDTO接口
{
"Id": 0,
"extension": {},
"type": "String"
}
EmptyTo显示在swaggerui的模型部分,但ActualTo不显示。
我尝试向空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没有影响,ActualDTO仍然没有显示在models部分中,端点示例也没有显示扩展的{}之外的任何内容
我试着给DTO起越来越愚蠢的名字,并将父类和子类型设置为同一个类,只是为了在swagger ui上看到变化。但似乎没有任何东西对招摇过市有影响,不管我现在把ApiModel注释搞砸了多少。这让我相信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>
org.springframework.boot
spring启动程序父级
2.1.8.1发布
伊奥·斯普林福克斯
springfox-Swagger 2
2.9.2
伊奥·斯普林福克斯
springfox招摇过市用户界面
2.9.2
org.webjars
大摇大摆的用户界面
2.2.10
<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>