首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用swagger-codegen maven插件生成代码时删除默认实现

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

Stack Overflow用户
提问于 2019-05-11 00:02:04
回答 3查看 2.4K关注 0票数 5

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

代码语言:javascript
复制
<configOptions>
  <java8>true</java8>
  <sourceFolder>src/main/java</sourceFolder>
  <interfaceOnly>true</interfaceOnly>
  <dateLibrary>java8</dateLibrary>
  <singleContentTypes>true</singleContentTypes>
</configOptions>

但是,即使指定为iinterfaceOnly>true,代码生成器也会生成一个具有默认实现的接口,如下所示:

代码语言:javascript
复制
@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);
    }

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

当我删除以下两个标记时,它可以正常工作

代码语言:javascript
复制
<java8>true</java8> 
<dateLibrary>java8</dateLibrary>

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

有什么想法吗?

EN

回答 3

Stack Overflow用户

发布于 2019-11-05 17:24:48

在openapi插件版本4.1.2中,将java8设置为false但将dateLibrary设置为java8可以解决此问题

代码语言:javascript
复制
<java8>false</java8> 
<dateLibrary>java8</dateLibrary>
票数 0
EN

Stack Overflow用户

发布于 2020-04-06 16:48:42

请尝试:

代码语言:javascript
复制
<configOptions>
    <dateLibrary>java8</dateLibrary>
    <java8>true</java8>
    <defaultInterfaces>false</defaultInterfaces>
</configOptions>

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

票数 0
EN

Stack Overflow用户

发布于 2020-06-16 01:46:43

如果您需要LocalDateTime支持,并且不需要默认方法实现,则可以使用以下技巧:

代码语言:javascript
复制
<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。

请注意,请具体说明

代码语言:javascript
复制
<dateLibrary>java8</dateLibrary>
<defaultInterfaces>false</defaultInterfaces>

将避免默认实现,但会导致API中的冗余方法(如getRequest()getObjectMapper()等)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56081153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档