0

The POST API takes a payload with couple of fields where one of them is a write only field. The class has lombok @Data annotation to generate setters/getters and the write only field is annotated with @Getter(AccessLevel.NONE). Since lombok is used, the fields are annotated with @Schema with proper description.

@Data
public class Query {

    @Schema(description = "List of filter conditions separated by comma.")
    private String filter;

    @Schema(description = "Desired page number (starting from 1).")
    @Getter(AccessLevel.NONE)
    private int page;

    // other fields
}

Unfortunately, the given description is ignored by Swagger, and Swagger UI is showing "writeOnly: true" instead of the description mentioned in the @Schema annotation of the field.

enter image description here

I tried the solution mentioned here by adding lombok.config with below line, but no luck.

lombok.copyableAnnotations += io.swagger.v3.oas.annotations.media.Schema

However, if I add an explicit setter method with @Schema annotation (instead of mentioning at field level), it is getting honoured and Swagger generates the documentation as expected.

@Data
public class Query {

    @Schema(description = "List of filter conditions separated by comma.")
    private String filter;

    @Getter(AccessLevel.NONE)
    private int page;

    // other fields

    @Schema(description = "Desired page number (starting from 1).")
    public void setPage(int page){
        this.page = page;
    }
}

enter image description here

I am wondering, (a) why lombok is not copying the @Schema to the setter method? (b) why Swagger generating the documentation with hardcoded "writeOnly: true"?

vinodpthmn
  • 1,062
  • 14
  • 28

0 Answers0