我如何才能获得敏捷的代码生成器以使用现有类而不是创建新类?这可能吗?例如,我想使用com.test.account.dto.Permission而不是大摇大摆地创建另一个权限类。
等级:
import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.config.CodegenConfigurator
def swaggerInput = "${project.projectDir.path}/src/main/resources/swagger/account.yaml"
def swaggerOutputDir = file('build/swagger')
task generateApi {
inputs.file(swaggerInput)
outputs.dir(swaggerOutputDir)
doLast {
def config = new CodegenConfigurator()
config.setInputSpec(swaggerInput)
config.setOutputDir(swaggerOutputDir.path)
config.setLang('spring')
config.setAdditionalProperties([
'invokerPackage' : 'com.test.account',
'modelPackage' : 'com.test.account.model',
'apiPackage' : 'com.test.account.api',
'dateLibrary' : 'java8',
'useTags' : 'true',
'interfaceOnly' : 'true',
'serializableModel': 'true'
])
config.setImportMappings([
'Permission': 'com.test.account.Permission'
])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
account.yaml
Permission:
type: "object"
user:
properties:
permissions:
type: array
items:
type: "object"
$ref: '#/definitions/Permission'
错误:
> Task :compileSwaggerJava
C:\Users\user\Desktop\test\test\build\swagger\src\main\java\com\test\account\model\CurrentUser.java:35: error: package com.test.account.dto. does not exist
private List<com.test.account.dto.Permission> permissions = null;