kbuntrock / openapi-maven-plugin

Generate openapi documentation for SpringMVC or JaxRS/JakartaRS projects.
https://kbuntrock.github.io/openapi-maven-plugin/
MIT License
13 stars 8 forks source link

Support Annotations on Getters and Setters #125

Open gerhardj-b opened 2 months ago

gerhardj-b commented 2 months ago

Hi,

in our case, the models have Annotations - like @NotNull - only on the getters and setters, which are public. Since some of the code is auto-generated, we also cannot change that behaviour easily.

Is it possible to take such Annotations into account - specifically when determining the required fields of a model?

kbuntrock commented 2 months ago

Hello.

Surely, it sounds do-able.

To ease my comprehension / the development : could you provide a sample class representative of what you have on your project?

gerhardj-b commented 2 months ago

Thanks for your quick response. I created a sample file that results in the said issue. I will paste it here down below. As I explained earlier, those files are auto-generated, namely with the help of openapi-generator-maven-plugin.

This file also shows another issue I found: A List field always leads to uniqueItems being set to true, although this is not neccessarily true in the source.

@JsonPropertyOrder({
  SampleModel.JSON_PROPERTY_NAME,
  SampleModel.JSON_PROPERTY_DESCRIPTION,
  SampleModel.JSON_PROPERTY_TODOS
})
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class SampleModel {
  public static final String JSON_PROPERTY_NAME = "name";
  private String name;

  public static final String JSON_PROPERTY_DESCRIPTION = "description";
  private String description;

  public static final String JSON_PROPERTY_TODOS = "todos";
  private List<String> todos;

  public SampleModel() {
  }

  public SampleModel name(String name) {

    this.name = name;
    return this;
  }

   /**
   * Get name
   * @return name
  **/
  @jakarta.annotation.Nonnull
  @NotNull

  @JsonProperty(JSON_PROPERTY_NAME)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)

  public String getName() {
    return name;
  }

  @JsonProperty(JSON_PROPERTY_NAME)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)
  public void setName(String name) {
    this.name = name;
  }

  public SampleModel description(String description) {

    this.description = description;
    return this;
  }

   /**
   * Get description
   * @return description
  **/
  @jakarta.annotation.Nullable

  @JsonProperty(JSON_PROPERTY_DESCRIPTION)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public String getDescription() {
    return description;
  }

  @JsonProperty(JSON_PROPERTY_DESCRIPTION)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setDescription(String description) {
    this.description = description;
  }

  public SampleModel todos(List<String> todos) {

    this.todos = todos;
    return this;
  }

  public SampleModel addTodosItem(String todosItem) {
    if (this.todos == null) {
      this.todos = new ArrayList<>();
    }
    this.todos.add(todosItem);
    return this;
  }

   /**
   * Get todos
   * @return todos
  **/
  @jakarta.annotation.Nullable

  @JsonProperty(JSON_PROPERTY_TODOS)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public List<String> getTodos() {
    return todos;
  }

  @JsonProperty(JSON_PROPERTY_TODOS)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setTodos(List<String> todos) {
    this.todos = todos;
  }
kbuntrock commented 2 months ago

Thank you ! I'll be able to have a look on it next week.