【发布时间】:2021-08-20 17:58:09
【问题描述】:
所以,我在使用带有 Swagger(核心 1.5.7)的 XML 对象定义时遇到了问题。这是我的 XML 代码:
<result status="ok">
<another>
<cards/>
<customer my_super_id="2349027834"/>
<someothers>
<someother name="who-is-this" />
</someothers>
</another>
</result>
这是我的 yml 代码:
result:
type: object
description: Some random description
properties:
status:
type: string
xml:
attribute: true
another:
type: object
properties:
customer:
type: object
properties:
superId:
type: string
xml:
name: my_super_id
attribute: true
我可以毫无问题地获得status,但my_super_id 是null,因为Swagger 正在使用CamelCase 中的参数生成模型类,即mySuperId 而不是my_super_id。
在我生成的模型类中,我有这个:
public ResultAnotherCustomer(@JsonProperty("mySuperId") final String mySuperId)
有没有办法解决这个问题?
【问题讨论】:
-
当你说模型类在你的服务器代码中?谁具体抛出错误?是 XML 反序列化器吗?
-
是的,Swagger在构建过程中生成的模型类。我在帖子中添加了其他信息,即生成的模型类中的 CamelCase 输出。
-
也许我遗漏了一些东西 - 为什么你不能改变模型,让它显示@JsonProperty("my_super_id")?
-
模型是根据我在 yml 文件中的内容自动生成的。我认为这是与 swagger-codegen 相关的错误,但我不知道为什么。
-
是的,我的错误在于没有使用最新版本。感谢您的帮助!
标签: swagger