3

I'm working with Swagger to generate the API of my application. Swagger is an API specification language that can be used by a code generator to generate code stubs for your application. Obviously you have to complete these stubs with some business/controller logic.

Given that the code generation is an iterative process as new services are added or there are changes in parameters does anyone have any best practices for working with this code. An obvious idea is to externalize all the user written code and just add a method call to this logic but are there other ways of handling this? The target system is Java/Spring.

Tulains Córdova
  • 39,570
  • 13
  • 100
  • 156

1 Answers1

2

As far as I know, the solution you describe is a very common pattern. It works essentially because OOP languages have mechanisms for separating the implementation from an abstraction of this implementation, which is exactly the problem you are facing.

So typically, with Java, interfaces are generated and developers manually creates classes that implement these interfaces, in such a way that, when the code is automatically generated again, and as long as the interfaces has not been modified, it can exploit the classes without any extra manual changes.

In particular, this is how Yakindu proceeds for generating applications from state charts. The fact that Yakindu relies on interfaces it generates (and therefore controls) greatly facilitates the diagram/code base (co)evolution.

mgoeminne
  • 1,158