swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[JAXRS-CXF] Add constructors to POJOs

Open shpandrak opened this issue 8 years ago • 3 comments

Before this change, POJOs where generated without regular constructors.This would mean you have to use the default constructor and setters or builder-style methods. This is problematic when trying to make changes to the swagger file by adding required fields. Before the change, the model consumer code will compile even when the callers does not supply all required fields when constructing a model object. After the change, such addition will break the compilation and by that move important model validation from runtime to compile time. For that reason, Our project code style requires use of constructors, and that is the motivation for this contribution. This change adds a regular constructor to all POJOs, and specifically to the generated models.

shpandrak avatar Oct 15 '17 07:10 shpandrak

As already said in #4686, if we have a constructor with required params, then the empty one shall be removed. Also the "all params" constructor should be a cli option. The required params should also be annotated with NotNull

cbornet avatar Oct 15 '17 18:10 cbornet

@shpandrak thanks for the PR. Do you need help adding the CLI option as mentioned by @cbornet ?

wing328 avatar Nov 02 '17 13:11 wing328

@shpandrak thanks for the PR. Do you need help adding the CLI option as mentioned by @cbornet ?

I was planning to do that, though would appreciate help if possible :)

shpandrak avatar Nov 03 '17 07:11 shpandrak