Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 大摇大摆2 Springfox忽略@ApiModel_Java_Spring_Swagger_Springfox - Fatal编程技术网

Java 大摇大摆2 Springfox忽略@ApiModel

Java 大摇大摆2 Springfox忽略@ApiModel,java,spring,swagger,springfox,Java,Spring,Swagger,Springfox,我正在尝试将Swagger文档添加到使用SpringFox在Spring Boot中创建的端点。端点在功能上不能改变,这意味着我不能真正重构它,但我可以添加任何我想要的注释。我正在进行一个设置,其中端点将空接口作为REST服务的参数。这个接口有许多子类型,这些子类型最终将被发送到端点而不是接口(我只是在示例中显示一个,还有更多),但这并不奇怪,因为它没有受到炫耀的影响。@Data注释来自Lombok,@JsonDeserialize来自Jackson @Controller @RequestMa

我正在尝试将Swagger文档添加到使用SpringFox在Spring Boot中创建的端点。端点在功能上不能改变,这意味着我不能真正重构它,但我可以添加任何我想要的注释。我正在进行一个设置,其中端点将空接口作为REST服务的参数。这个接口有许多子类型,这些子类型最终将被发送到端点而不是接口(我只是在示例中显示一个,还有更多),但这并不奇怪,因为它没有受到炫耀的影响。@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

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注释实际上并没有被读取。所以问题实际上是两个问题:

  • 我如何让swagger理解这个空接口应该被许多子类替换
  • 我到底是如何激怒了强大的春天的,为什么我的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>