我必须从yaml文件生成代码,在我的swagger maven插件中我放了:
<configOptions>
<java8>true</java8>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<singleContentTypes>true</singleContentTypes>
</configOptions>但是,即使指定为iinterfaceOnly>true,代码生成器也会生成一个具有默认实现的接口,如下所示:
@ApiOperation(value = "", nickname = "billetsFichiersHealthGet", notes = "Obtient l'état de santé de l'API. ", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 200, message = "Erreur", response = Error.class) })
@RequestMapping(value = "/bills/health",
produces = "application/json",
consumes = "",
method = RequestMethod.GET)
default ResponseEntity<Void> billetsFichiersHealthGet() {
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
} else {
log.warn("ObjectMapper or HttpServletRequest not configured in default BilletsApi interface so no example is generated");
}
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}如何禁用默认接口方法的生成,只在接口中定义而不在默认实现中定义。
当我删除以下两个标记时,它可以正常工作
<java8>true</java8>
<dateLibrary>java8</dateLibrary>但是,我的模型使用的是localdatetime,所以我应该在java8上,不能真正删除这两个标记
有什么想法吗?
发布于 2019-11-05 17:24:48
在openapi插件版本4.1.2中,将java8设置为false但将dateLibrary设置为java8可以解决此问题
<java8>false</java8>
<dateLibrary>java8</dateLibrary>发布于 2020-04-06 16:48:42
请尝试:
<configOptions>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<defaultInterfaces>false</defaultInterfaces>
</configOptions>发布于 2020-06-16 01:46:43
如果您需要LocalDateTime支持,并且不需要默认方法实现,则可以使用以下技巧:
<configuration>
...
<typeMappings>
<typeMapping>date=LocalDate</typeMapping>
<typeMapping>date-time=LocalDateTime</typeMapping>
<typeMappings>
<importMappings>
<importMapping>LocalDate=java.time.LocalDate</importMapping>
<importMapping>LocalDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>legacy</dateLibrary>
</configOptions>
<configuration>使用传统日期排除了默认方法,但可以手动将日期映射为java8 dateLibrary格式。它适用于swagger-codegen插件3.0.18。
请注意,请具体说明
<dateLibrary>java8</dateLibrary>
<defaultInterfaces>false</defaultInterfaces>将避免默认实现,但会导致API中的冗余方法(如getRequest()、getObjectMapper()等)。
https://stackoverflow.com/questions/56081153
复制相似问题