I have generated the code from swagger.yaml file using swagger code-gen in spring.
Now I have updated the swagger.yaml file for my API and added few more HTTP operations.
Will it be possible to update the existing code generated previously automatically without merging it manually?
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
Having the same issue, I found the solution to start with by applying git
I just start with this approach but it seems to work at least for php-slim where only one file (index.php) is changed when regenerating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With