Why is swagger-codegen generating project with missing dependencies?
Running:
java -jar swagger-codegen-cli.jar generate -l java -i swagger.json
Generates a project with this for example:
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2021-04-27T18:37:06.211+08:00")
public class Table {
@SerializedName("requiredIndexColumns")
private List<Column> requiredIndexColumns = null;
Where javax.annotation.Generate cannot be resolved.
And then compiling the generated project throws: Error:(33,18) java: package javax.annotation does not exist
Here's how to test this (using a public swagger):
wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.19/swagger-codegen-cli-2.4.19.jar -O swagger-codegen-cli.jar
Then run:
java -jar swagger-codegen-cli.jar generate -l java -i https://petstore.swagger.io/v2/swagger.json -o petstore
Formalizing the comment left by Scratte, if you are using jdk11, you need to add the dependency explicitly in your dependency management tool
For example in maven
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation-api.version}</version>
</dependency>
The solution is to run with this command:
java -jar swagger-codegen-cli.jar generate -l java -i https://petstore.swagger.io/v2/swagger.json -o petstore -DhideGenerationTimestamp=true
The option to turn off @javax.annotation.Generated date in Java Classes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With