user5365075
user5365075

Reputation: 2279

Swagger package javax.validation.constraints does not exist

I'm having trouble building swagger Java clients using swagger-codegen and Maven. It's building on my CI using Java 1.8 and Maven 3.6. I'm seeing this:

... package javax.validation.constraints does not exist
... package javax.validation does not exist

The relevant part of my config is:

{
  "library": "resttemplate",
  "configOptions": {
    "dateLibrary": "java8"
  },
  "useBeanValidation": true
}

And the command I use to generate the api is:

java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -o ./generated/ -c swagger-java-config.json

I would expect this error to occur with Java 11. Also, I don't see the required imports in the official resttemplate library pom.xml template for the Java client.

Upvotes: 1

Views: 2566

Answers (1)

user5365075
user5365075

Reputation: 2279

The problem comes from "useBeanValidation": true in the configuration. This option is only available for generated servers, not clients. The java -jar swagger-codegen.jar config-help -L java will show this option as it does not discriminate on the library chosen (in your case resttemplate). The templates specific to resttemplate do not alter the code outputted by the java language templates.

Upvotes: 2

Related Questions