title: Swagger codegen plugin generates constraints on getters
body: <p>i am using spring boot and swagger to generate model and delegates using swagger first approach. The problem is that constraints such as <code>@NotNull</code>, <code>@Size</code> are placed on getter methods and not on the fields. Thats why i can pass random value for example to email field. Please help me solve this problem. Here is my pom.xml: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>https://maven.apache.org/xsd/maven-4.0.0.xsd">
      4.0.0
      
          org.springframework.boot
          spring-boot-starter-parent
          2.3.0.M4
           
      
      com.niko
      slicer-db
      0.0.1-SNAPSHOT
      slicer-db
      Database for slicer system</p>
  
  <pre><code>&lt;properties&gt;
      &lt;java.version&gt;14&lt;/java.version&gt;
      &lt;swagger-annotations.version&gt;1.6.1&lt;/swagger-annotations.version&gt;
      &lt;mapstruct.version&gt;1.3.1.Final&lt;/mapstruct.version&gt;
      &lt;maven-processor-plugin.version&gt;3.3.3&lt;/maven-processor-plugin.version&gt;
      &lt;swagger-codegen-maven-plugin.version&gt;3.0.19&lt;/swagger-codegen-maven-plugin.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.liquibase&lt;/groupId&gt;
          &lt;artifactId&gt;liquibase-core&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
          &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
          &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
          &lt;artifactId&gt;mapstruct&lt;/artifactId&gt;
          &lt;version&gt;${mapstruct.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
          &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;
          &lt;version&gt;${mapstruct.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.swagger&lt;/groupId&gt;
          &lt;artifactId&gt;swagger-annotations&lt;/artifactId&gt;
          &lt;version&gt;${swagger-annotations.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;io.swagger.codegen.v3&lt;/groupId&gt;
              &lt;artifactId&gt;swagger-codegen-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${swagger-codegen-maven-plugin.version}&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;server-delegate-generation&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;generate&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;inputSpec&gt;${project.basedir}/src/conf/swagger/slicer-db.yaml&lt;/inputSpec&gt;
                          &lt;language&gt;spring&lt;/language&gt;
                          &lt;library&gt;spring-boot&lt;/library&gt;
                          &lt;generateApiTests&gt;false&lt;/generateApiTests&gt;
                          &lt;generateModelTests&gt;false&lt;/generateModelTests&gt;
                          &lt;generateApiDocumentation&gt;false&lt;/generateApiDocumentation&gt;
                          &lt;generateModelDocumentation&gt;false&lt;/generateModelDocumentation&gt;
                          &lt;generateSupportingFiles&gt;false&lt;/generateSupportingFiles&gt;
                          &lt;apiPackage&gt;${project.groupId}.slicer.db.api&lt;/apiPackage&gt;
                          &lt;modelPackage&gt;${project.groupId}.slicer.db.model&lt;/modelPackage&gt;
                          &lt;invokerPackage&gt;${project.groupId}.slicer.db.invoker&lt;/invokerPackage&gt;
                          &lt;configOptions&gt;
                              &lt;java8&gt;false&lt;/java8&gt;
                              &lt;dateLibrary&gt;offsetdatetime&lt;/dateLibrary&gt;
                              &lt;delegatePattern&gt;true&lt;/delegatePattern&gt;
                          &lt;/configOptions&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.bsc.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-processor-plugin&lt;/artifactId&gt;
              &lt;version&gt;${maven-processor-plugin.version}&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;process&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;process&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;phase&gt;generate-sources&lt;/phase&gt;
                      &lt;configuration&gt;
                          &lt;processors&gt;
                              &lt;processor&gt;org.mapstruct.ap.MappingProcessor&lt;/processor&gt;
                          &lt;/processors&gt;
                          &lt;outputDirectory&gt;${basedir}/target/generated-sources-mappers&lt;/outputDirectory&gt;
                          &lt;compilerArguments&gt;-source 14 -target 14&lt;/compilerArguments&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;spring-milestones&lt;/id&gt;
          &lt;name&gt;Spring Milestones&lt;/name&gt;
          &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
      &lt;/repository&gt;
  &lt;/repositories&gt;
  &lt;pluginRepositories&gt;
      &lt;pluginRepository&gt;
          &lt;id&gt;spring-milestones&lt;/id&gt;
          &lt;name&gt;Spring Milestones&lt;/name&gt;
          &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
      &lt;/pluginRepository&gt;
  &lt;/pluginRepositories&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is example from swagger file:</p>
  
  <pre><code>userPostDto:
    type: object
    required:
      - firstName
      - lastName
      - password
      - email
    properties:
      firstName:
        type: string
        maxLength: 20
      lastName:
        type: string
        maxLength: 20
      password:
        type: string
        pattern: '^[a-z0-9_-]{6,18}$'
      email:
        type: string
        pattern: '^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$'
  </code></pre>
  
  <p>Gerated java class example:
  <a href="https://i.stack.imgur.com/QzP65.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QzP65.png" alt="Generated java code"></a></p>