编程语言
首页 > 编程语言> > java-如何避免在swagger codegen接口中实现默认方法?

java-如何避免在swagger codegen接口中实现默认方法?

作者:互联网

我想避免由Maven插件swagger代码生成的接口中的“默认”实现.
例如,使用petstore swagger:http://petstore.swagger.io/v2/swagger.json

我使用maven插件生成接口:

            <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>./src/main/resources/swagger/api.yml</inputSpec>
                        <language>spring</language>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <configOptions>
                            <interfaceOnly>true</interfaceOnly>
                            <java8>true</java8>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我使用默认的方法实现生成类似PetApi.java的接口:

    default ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true )  @Valid @RequestBody Pet body) {
    // do some magic!
    return new ResponseEntity<Void>(HttpStatus.OK);
    }

我想避免它喜欢

    ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true )  @Valid @RequestBody Pet body);

有可能做到吗?

解决方法:

通过“ spring”语言,“ java8”参数既用于表示使用默认接口,也用于表示对Java8的一般使用,例如使用Java8日期库时.
相关门票:
https://github.com/swagger-api/swagger-codegen/issues/8045
https://github.com/swagger-api/swagger-codegen/issues/5614

标签:maven,interface,swagger,codegen,java
来源: https://codeday.me/bug/20191109/2011223.html