[英]How to generate client code using with swagger-codegen-plugin (maven)?
[英]remove default implementation while generating code using swagger-codegen maven plugin
我必须从 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 上并且不能真正删除这两个标签
任何的想法 ?
将 java8 设置为 false 但将 dateLibrary 设置为 java8 在 openapi 插件版本 4.1.2 中起作用
<java8>false</java8>
<dateLibrary>java8</dateLibrary>
请尝试:
<configOptions>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<defaultInterfaces>false</defaultInterfaces>
</configOptions>
如果您需要 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>
使用旧的 dateLibrary 排除默认方法,但可以手动将日期映射到 java8 日期格式。 它适用于 swagger-codegen 插件 3.0.18。
请注意,指定
<dateLibrary>java8</dateLibrary>
<defaultInterfaces>false</defaultInterfaces>
将避免默认实现,但会导致 API 中的冗余方法(如getRequest()
、 getObjectMapper()
等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.