我当前正在使用yml的swagger代码生成生成我的模型。但是我有一个字段,那就是List<Object>
,需要具有@JacksonXmlElementWrapper(useWrapping = false)
。我可以在@JacksonXmlElementWrapper
中看到POJO.mustache
,但不能在model.mustache
中看到。有谁知道在yaml文件或其他任何地方添加什么,以便使用该注释生成该字段?谢谢。我正在使用gradle的spring-java语言。我需要在构建过程中生成它。因此,最好进行最小的更改。
答案 0 :(得分:0)
根据git的自述文件,Swagger Codegen提到了执行此操作的方法:
https://github.com/swagger-api/swagger-codegen/blob/master/README.md
因为您正在使用gradle:
我们可以使用自定义模板进行代码生成,如下所示:
// build.gradle
swaggerSources {
inputFile = file('{name of your file}.yaml')
xyz {
language = 'spring'
// template directory path
templateDir = file('templates/{name of your custom directory}')
}
}
在templates/{name of your custom directory}
内,您可以存储自定义的胡子文件,因为您需要做的就是从git下载所需的spring模板(例如,此链接用于pojo.mustache)
并将所需的更改以及项目和库文件夹添加到模板中。运行gradle build,它将生成。
但是,有一个更简单的解决方法,您可以只使用自己的pojo类并将其添加到现有的config.json
中,并从Yaml文件中删除该模型的较早条目(当然):>
"importMappings" : {
"{replace with className}": "{replace with packageName}.{replace with className}"
}
希望这会有所帮助。