Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 Springfox启动程序招摇过市即时处理_Java_Spring Boot_Rest_Swagger_Springfox - Fatal编程技术网

Java Springfox启动程序招摇过市即时处理

Java Springfox启动程序招摇过市即时处理,java,spring-boot,rest,swagger,springfox,Java,Spring Boot,Rest,Swagger,Springfox,我对使用SpringBoot和Springfox启动程序的swagger文档有一个问题 我在我的RESTAPI中使用了java.time.Instant包装在java.util.Optional中,效果很好: @GetMapping("/{subscriptionId}/{variableAlias}") public PaginatedResultDTO<MonitoredVariableDTO> getReportedVariables( @P

我对使用SpringBoot和Springfox启动程序的swagger文档有一个问题

我在我的RESTAPI中使用了java.time.Instant包装在java.util.Optional中,效果很好:

  @GetMapping("/{subscriptionId}/{variableAlias}")
  public PaginatedResultDTO<MonitoredVariableDTO> getReportedVariables(
    @PathVariable String subscriptionId, 
    @PathVariable String variableAlias, 
    Optional<Instant> from, 
    Optional<Instant> to) { ... }
@GetMapping(“/{subscriptionId}/{variableAlias}”)
将公共分页结果设置为getReportedVariables(
@PathVariable字符串subscriptionId,
@PathVariable字符串variableAlias,
可选自,
可选){…}
但由于某些原因,Swagger文档无法正确处理可选类型,并且似乎通过反射将其处理为EpochSeconds和Nano属性,而不是一个字段:

我想让swagger以ISO格式期待的瞬间,就像Spring所做的一样,以及我在失眠中如何使用它:

当我试图移除可选包装时,它似乎起了作用

有没有一种方法可以让这个选项起作用?谢谢你的建议

Spring启动版本:

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

org.springframework.boot
spring启动程序父级
2.3.4.1发布
Springfox启动程序版本

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

伊奥·斯普林福克斯
springfox启动程序
3.0.0

我们遇到了与您完全相同的问题。 我们用这个SpringFox配置解决了这个问题:

@Configuration
@EnableSwagger2
public class SpringfoxConfiguration {

    @Value("${api-doc.version}")
    private String apiInfoVersion;

    @Autowired
    private TypeResolver typeResolver;
    @Bean
    public Docket customDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("xxx")
                //Some other code unrelated to this problem
                .alternateTypeRules(
                        // Rule to correctly process Optional<Instant> variables
                        // and generate "type: string, format: date-time", as for Instant variables,
                        // instead of "$ref" : "#/definitions/Instant"
                        AlternateTypeRules.newRule(
                                typeResolver.resolve(Optional.class, Instant.class),
                                typeResolver.resolve(Date.class), 
                                Ordered.HIGHEST_PRECEDENCE
                        ))
                .genericModelSubstitutes(Optional.class)
                .select()
                //Some more code unrelated to this problem
                .build();
    }
}
@配置
@使能招摇过市2
公共类springfox配置{
@值(${api doc.version}”)
私有字符串版本;
@自动连线
专用类型分解器类型分解器;
@豆子
公共摘要customDocket(){
返回新摘要(DocumentationType.SWAGGER_2)
.集团名称(“xxx”)
//其他一些与此问题无关的代码
.交替阅读(
//正确处理可选变量的规则
//并生成“type:string,format:date-time”,对于即时变量,
//而不是“$ref”:“#/definitions/Instant”
新规则(
typeResolver.resolve(可选的.class,Instant.class),
typeResolver.resolve(日期类),
有序。最高优先级
))
.genericModelSubstitutes(可选.class)
.选择()
//还有一些与此问题无关的代码
.build();
}
}