I'm generate a java client using swagger codegen cli tool (version 3.0.25) in gradle:
task doCodeGenSdk(type: JavaExec) {
main = "io.swagger.codegen.v3.Codegen"
classpath = configurations.codeGenCli
inputs.files file("${swaggerSpecDir}/*.json")
outputs.dir file("${codeGenDirSdk}")
args = ["generate", "--lang", "java", "--input-spec", "${swaggerSpecFile}",
"--config", "${swaggerConfig}",
"--template-dir", "${swaggerTemplateDir}",
"--output", "${codeGenDirSdk}"]
systemProperty "apiTests", "false"
systemProperty "apiDocs", "false"
systemProperty "modelTests", "false"
systemProperty "modelDocs", "false"}
The swagger config file is as shown below:
{
"library": "resttemplate",
"artifactVersion": "__VERSION__",
"artifactId": "__ARTIFACT_ID__",
"modelPackage": "com.model",
"apiPackage": "com.api",
"invokerPackage": "com.invoker",
"dateLibrary": "java8",
"apiTests": false,
"java8": true,
"serializableModel": true,
"useBeanValidation": true,
"performBeanValidation": true}
The template-directory has the following mustache files:
ApiClient.mustache, generatedAnnotation.mustache, licenseInfo.mustach, pojo.mustache
The gradle file:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.swagger.core.v3:swagger-gradle-plugin:2.1.10"
}
}
apply plugin: io.swagger.v3.plugins.gradle.SwaggerPlugin
configurations {
codeGenCli
}
dependencies {
codeGenCli "io.swagger.codegen.v3:swagger-codegen-cli:3.0.25"
}
The swagger codegen generates the files in the build directory, however there are import error for some of the packages.
error: package io.swagger.v3.oas.annotations.media does not exist
We were using swagger codegen tool to generate client code using swagger spec file in 2.0.
This is the first time, we're trying to generate a client using a swagger spec file in 3.0.
Any help would be much appreciated.