Search code examples
springspring-bootspring-data-jpaspring-restswagger-maven-plugin

How to validate the fields in spring rest controller for the model created by swagger code generator?


We are using swagger code generator tool to create model and that model is using as spring boot rest api input payload and how to validate that generated model class similar to @valid annotation


Solution

  • If auto generated swagger class doesn't have any validation logic/annotations, need to copy properties/values to entity class object that having validation annotations and create validation factory and call the validate() from validator interface.