0

In my company, we are would like to recommend OpenAPI and using the design first approach to API development. We would also like to use the OpenAPI Generator to generated server stubs and DTOs from OpenAPI specs.

We are using the OpenAPI Generator maven plugin as our projects are Java based.

It seems though that the autogenerated code (server stubs, DTOs, etc) always end up in the /target folder and there is no way to configure it to write to the /src directory out of the box.

Since this behavior is by design and since the plugin was intended to behave this way by it's creators, my question is: are we not supposed to keep the autogenerated code in the /src folder? Is that code not meant to be committed and versioned along with the rest of the project code?

Any hints would be appreciated.

Nullbeans
  • 139
  • 6

1 Answers1

3

Typically, generated code is not committed into a repository. Only the input files needed to generate the code are. The generation is done as part of a build process, especially if it's fast. In cases where generation is extremely slow would I consider alternatives.

Generating the artifacts should be one of the first things that a developer does upon checking out the project. This would produce local copies that do not need to be regenerated unless a new, fresh copy is checked out or if the inputs to the generator change or if the generator itself changes. Generation should also be part of any automated build process to ensure that the rest of the build process is working with the most recent artifacts based on the inputs and the generator.

Thomas Owens
  • 85,641
  • 18
  • 207
  • 307