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

[Java] Add an option to not generate equals/hashcode/toString

Open cyChop opened this issue 2 years ago • 0 comments

Description

The pojo.mustache template used for Java models always includes equals, hashcode and toString methods. There may be occurrences when they are not relevant, or we don't want them generated (the toString might reveal confidential information if the model is logged, the equals on all fields might not be relevant…).

Swagger-codegen version

3.0.47, not a regression as far as I can tell.

Command line used for generation

(using maven plugin)

Steps to reproduce

Generate for language java, spring, or logically any java-derived language.

Related issues/PRs

I couldn't find any.

Suggest a fix/enhancement

The simplest way to circumvent this would be to add an option not to generate those methods, or two separate options, maybe:

  • generateToString (default: true)
  • generateEqualsAndHashCode (default: true)

I suppose it could be handled in AbstractJavaCodegen.java + pojo.mustache.

cyChop avatar Oct 17 '23 06:10 cyChop