java - 使用 swagger-codegen maven 插件生成代码时删除默认实现

标签 java maven-plugin swagger-codegen

我必须从 yaml 文件生成代码,在我放置的 swagger maven 插件中:

<configOptions>
  <java8>true</java8>
  <sourceFolder>src/main/java</sourceFolder>
  <interfaceOnly>true</interfaceOnly>
  <dateLibrary>java8</dateLibrary>
  <singleContentTypes>true</singleContentTypes>
</configOptions>

即使它说 iinterfaceOnly>true 但是 codegen 生成一个接口(interface),默认实现如下:

@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);
    }

如何禁用默认接口(interface)方法的生成,只在接口(interface)中定义而不是默认实现。

当我删除以下两个标签时它会起作用

<java8>true</java8> 
<dateLibrary>java8</dateLibrary>

但是我的模型正在使用 localdatetime,所以我应该在 java8 上并且不能真正删除这两个标签

有什么想法吗?

最佳答案

请尝试:

<configOptions>
    <dateLibrary>java8</dateLibrary>
    <java8>true</java8>
    <defaultInterfaces>false</defaultInterfaces>
</configOptions>

https://github.com/swagger-api/swagger-codegen/issues/8833

关于java - 使用 swagger-codegen maven 插件生成代码时删除默认实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56081153/

相关文章:

java - Java 中的调用者信息

java - 我可以自己编译java吗?

java - maven 无法下载 jacoco 0.7.10-SNAPSHOT jar

java - 如何正确使用从 swagger 规范生成的服务器 stub ?

Java 的 Jersey、RESTful API 和 JSONP

java - ChromeDriver 无法导航到 eclipse 中的 URL

java - 为什么使用if语句或assertj比较相同的对象值总是给出错误?

maven-plugin - Clover 0% Coverage with multiple source directories + build-helper-maven-plugin

java - Swagger 为默认响应正文生成太长的常量

json - 如何为从 swagger 生成的特定 POJO 生成 @JsonInclude(value = JsonInclude.Include.NON_NULL) ?