Openapi generator use validation annotation on getter not on field
10:02 25 Jan 2024

I have open api spec and try generate java code from it using this tool. All works fine except that validation annotation like @Valid, @NotNull is used for getter methods not for fields. And so when I try use this classes in controller and check validation it is not work. What should I do that this annotation used on fields?

This is one of my component

"Request": {
        "type": "object",
        "properties": {
          "fieldOne": {
            "type": "string",
            "example": "test"
          },
          "fieldTwo": {
            "$ref": "#/components/schemas/Data"
          }
        },
        "required": [
          "fieldOne",
          "fieldTwo"
        ]
      }

and this is my settings in build.gradle.kts

openApiGenerate {
    generatorName.set("spring")
    openApiGenerators.include.set(listOf("spring"))

    configOptions.set(mapOf(
        "dateLibrary" to "java8",
        "interfaceOnly" to "true",
        "useTags" to "true"
    ))
}

I use java 21, openapi 3.0.0 and org.openapi.generator 7.2.0

java gradle openapi openapi-generator