Update code generated by Swagger code-gen

I guess you are talking about the Controllers generated by codegen, that you have then implemented. They are overwritten after each generation, which means you will have to manually merge the code to add the changes every time... which is really annoying.

Well the best workflow I could find was to use the interfaceOnly option to generate only the model and interface classes in the target directory, and then manually create the controllers that implement those interfaces.

Lets say you update your API specification file with one more GET operation, the interface is regenerated with that new operation and you will just have to adjust your controller to implement that new method (super quick and easy with modern IDE), everything else remain the same and you have more control over your code (splitting controllers in different folders...etc...).

Here is config I used for the 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>./api-contract/petstore.yml</inputSpec>
                <language>spring</language>
                <configOptions>
                    <sourceFolder>swagger</sourceFolder>
                    <java8>true</java8>
                    <interfaceOnly>true</interfaceOnly>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

You can check a complete example project using Spring Boot with swagger-codegen-maven-plugin here.

Cheers