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.

5
  • How long does the generation process take? My in experience, generation is a quick process, so it can be done as part of the build process, before compilation (for compiled languages). This means you wouldn't commit to source control. You would, however, commit the inputs to the generator.
    – Thomas Owens
    Commented May 31, 2023 at 12:21
  • The generation is very fast and can happen during the build process. Usually those generated files end up in the target folder where they don't get committed to the repository. However, those files are referenced by other files in the repository, so your project would locally be "broken" until you built the project.
    – Nullbeans
    Commented May 31, 2023 at 12:40
  • @Nullbeans don't understand that: "your project would locally be "broken" until you built the project". If you build your project, it generates the files and works. If you don't build/run your project, it can't be broken, because it isn't run.
    – jwsc
    Commented May 31, 2023 at 13:08
  • 1
    @jwsc I think "broken" means errors in an IDE due to missing source files that are produced as part of the generation process.
    – Thomas Owens
    Commented May 31, 2023 at 13:15
  • Exactly. So broken means syntax errors due to missing files.
    – Nullbeans
    Commented May 31, 2023 at 14:58

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.