how to avoid default method implementation in swagger codegen interface?

awat picture awat · May 4, 2018 · Viewed 7.6k times · Source

I would like to avoid "default" implementation in interface generate by the maven plugin swagger codegen. For example, with petstore swagger : http://petstore.swagger.io/v2/swagger.json

I generate interface with maven plugin :

            <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>

I generate interface like PetApi.java with default implementation of methods :

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

I would like to avoid it like

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

Is it possible to do it ?

Update March 2020:

According to new OpenAPI Tool openapi-generator
There is an option with spring (language is DEPRECATED, use generatorName)

skipDefaultInterface

https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/spring.md

Answer

Roman Sinyakov picture Roman Sinyakov · Sep 13, 2018

With a "spring" language the "java8" parameter is used both to signal use of the default interface and to signal general use of Java8, e.g. when the Java8 date library is used.
Related tickets:
https://github.com/swagger-api/swagger-codegen/issues/8045
https://github.com/swagger-api/swagger-codegen/issues/5614