0

In a very big Java app with lot's of DTOs, I want to export to an external project only the DTOs that are relevant to REST calls, and even better to export a part of them (the minimum required for REST calls).

The project uses Swagger and I am wondering if it is possible to take the output of Swagger (uses Java DTOs to create JSON\YAML files), which have the exact content I need, as an input to generate new Java DTO files. The generated files will be only those needed for REST and I will be able to easily export them.

Is this possible? If not, what is the best approach to do that?

Itai
  • 23
  • 4
  • 1
    I wouldn't go by swagger. You may export a DTO from you current project into YAML, then when you regenerate the code may not be exactly the same (members may not be final, if there was a custom toString you'd lose it etc.). If your old project is dead, simply copy/paste the files into the new project. If the DTO is really common between the two projects, then create a data module containing only the DTO and make both projects depend on it (that is the cleanest way to go IMO) – Matteo NNZ Aug 29 '22 at 06:44

1 Answers1

0

Maybe check out swagger.generator.io where you can generate a whole client library (including DTO classes) for your specified swagger definition file. For documentation please refer to their github page. You can also do the generation of the API client locally utizing the swagger codegen tools.

yezper
  • 693
  • 3
  • 12