我正在使用 openapi 生成器根据 openapi 规范生成接口和模型。一切正常。但是,我想在我的型号名称中添加后缀。例如:员工将是 EmployeeDTO。我在我的年级的 openApiGenerate 配置中的 configOptions 中添加了“modelSuffix”,如下。
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.6'
id 'org.sonarqube' version '5.1.0.4882'
id 'jacoco'
id 'com.adarshr.test-logger' version '4.0.0'
id 'com.diffplug.spotless' version '7.0.0.BETA1'
id 'org.openapi.generator' version '7.7.0'
}
openApiGenerate {
generatorName = 'spring'
inputSpec = file('src/main/resources/api-spec/api.yaml').absolutePath
outputDir = file('build/generated').absolutePath
apiPackage = 'com.abhi.api'
modelPackage = 'com.abhi.model'
invokerPackage = 'com.abhi.invoker'
configOptions = [
interfaceOnly: 'true',
useOptional: 'false',
dateLibrary: 'java8',
implementationPackage: '', // Prevent generation of implementation classes
skipDefaultInterface: 'true', // Skip generation of default methods
modelSuffix: 'DTO',
useTags: 'true',
]
}
但是没有效果。您能给我任何解决方案吗?
我刚刚从 configOptions 中删除了“modelSuffix”,然后在 openApiGenerate 下添加了 modelNameSuffix = 'DTO'。现在它起作用了。以下是完整代码。
openApiGenerate {
generatorName = 'spring'
inputSpec = file('src/main/resources/api-spec/api.yaml').absolutePath
outputDir = file('build/generated').absolutePath
apiPackage = 'com.abhi.api'
modelPackage = 'com.abhi.model'
invokerPackage = 'com.abhi.invoker'
modelNameSuffix = 'DTO' // move it to here
configOptions = [
interfaceOnly: 'true',
useOptional: 'false',
dateLibrary: 'java8',
implementationPackage: '', // Prevent generation of implementation classes
skipDefaultInterface: 'true', // Skip generation of default methods
useTags: 'true'
]
}