java包io。大摇大摆v3。美洲国家组织。注释。媒体不退出(大摇大摆的Codegen)
我正在gradle中使用swagger codegen cli工具(版本3.0.25)生成java客户端:
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"}
swagger配置文件如下所示:
{
"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}
模板目录包含以下小胡子文件:
ApiClient.mustache, generatedAnnotation.mustache, licenseInfo.mustach, pojo.mustache
gradle文件:
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"
}
swagger codegen在build目录中生成文件,但是有些包存在导入错误
error: package io.swagger.v3.oas.annotations.media does not exist
我们使用swagger codegen工具在2.0中使用swagger规范文件生成客户机代码
这是我们第一次尝试使用3.0中的一个swagger规范文件生成客户端
任何帮助都将不胜感激
# 1 楼答案
通过在编译期间在构建中添加swagger注释库,我能够修复依赖性问题。gradle文件: