Java 使用swagger codegen maven插件生成代码时删除默认实现
我必须从yaml文件生成代码,在我的swagger maven插件中,我放了:Java 使用swagger codegen maven插件生成代码时删除默认实现,java,maven-plugin,swagger-codegen,Java,Maven Plugin,Swagger Codegen,我必须从yaml文件生成代码,在我的swagger maven插件中,我放了: <configOptions> <java8>true</java8> <sourceFolder>src/main/java</sourceFolder> <interfaceOnly>true</interfaceOnly> <dateLibrary>java8</dateLibrary>
<configOptions>
<java8>true</java8>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<singleContentTypes>true</singleContentTypes>
</configOptions>
真的
src/main/java
真的
爪哇8
真的
即使它说iinterfaceOnly>true,但是codegen会生成一个带有默认实现的接口,如下所示:
@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);
}
@ApiOperation(value=”“,昵称=“billetsFichiersHealthGet”,notes=“obcent l'tat de santéde l'API.”,tags={})
@ApiResponses(值={
@ApiResponse(代码=200,message=“OK”),
@ApiResponse(code=200,message=“Erreur”,response=Error.class)})
@请求映射(value=“/bills/health”,
products=“application/json”,
消耗=”,
method=RequestMethod.GET)
默认响应属性BilletShiersHealthGet(){
if(getObjectMapper().isPresent()和&getAcceptHeader().isPresent()){
}否则{
log.warn(“ObjectMapper或HttpServletRequest未在默认BilletsApi接口中配置,因此未生成示例”);
}
返回新的响应状态(HttpStatus.NOT_IMPLEMENTED);
}
我怎样才能禁用默认接口方法的生成,而只在接口中定义而不是默认实现
当我删除以下两个标记时,它会起作用
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
true
爪哇8
然而,我的模型使用的是localdatetime,所以我应该使用java8,不能真正删除这两个标记
有什么想法吗?将java8设置为false,但将dateLibrary设置为java8可以在openapi插件版本4.1.2中实现这一点
<java8>false</java8>
<dateLibrary>java8</dateLibrary>
false
爪哇8
请尝试:
<configOptions>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<defaultInterfaces>false</defaultInterfaces>
</configOptions>
爪哇8
真的
假的
如果您需要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>
...
日期=本地日期
日期时间=本地日期时间
LocalDate=java.time.LocalDate
LocalDateTime=java.time.LocalDateTime
真的
遗产
使用遗留dateLibrary不包括默认方法,但可以手动将日期映射为java8日期格式。
它适用于swagger codegen插件3.0.18
请注意,请说明
<dateLibrary>java8</dateLibrary>
<defaultInterfaces>false</defaultInterfaces>
java8
假的
将避免默认实现,但会导致API中的冗余方法(如getRequest()
,getObjectMapper()
等)