Integration created

How to validate with Hibernate Validator


Hibernate Validator is a validation framework that integrates with the Java Bean Validation API. It is used in WebPortal API to validate incoming requests from OpenApi specifications.

How to use Hibernate Validator

In OpenApi specifications you can define validation rules for each field.
For example, you can define that the field should be a number win min and max values or that it should be a string with a minimum length of 3 characters. \

      type: object
      description: Object Document
        - id
        - documentNo
          type: integer
          format: int32
          type: string
          minLength: 3
          maxLength: 10

When you generate the code from OpenApi specifications, you will get a DTO class with validation annotations.

    @Schema(name = "Document", description = "Object Document")
    @Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
    public class DocumentDto {

        private Integer id;

        private String documentNo;

        setId(Integer id) {
        this.id = id;

        @Size(min=3, max=10)
        setDocumentNo(String documentNo) {
            this.documentNo = documentNo;

These annotations are validated by Hibernate Validator during the request processing.