Reputation: 35276
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
Upvotes: 11
Views: 16076
Reputation: 1047
If you are using swagger-codegen-maven-plugin, you can avoid this problem by disabling @Generated annotations using this configuration:
<configOptions>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
Upvotes: 1
Reputation: 3384
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>
Upvotes: 14
Reputation: 35276
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
Upvotes: 6