因此,我在Swagger(Core 1.5.7)中使用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)
有什么办法解决这个问题吗?
5条答案
按热度按时间nhjlsmyf1#
愚蠢的是,我似乎没有使用最新版本的
swagger-codegen
,所以更新到最新版本(2.1.5)修复了这个问题。omqzjyyz2#
我在使用Swagger Open API规范的Java Springboot应用程序中遇到了同样的问题。我结束了覆盖一个Bean来使它工作。但这也是我在使用OAS的Springboot中修复的方法。
vktxenjb3#
我使用Swagger编码器生成器的经验是,它能让我得到我想要的80%,然后我必须自己做剩下的。如果你认为这是一个bug,你可以在这里记录它:https://github.com/swagger-api/swagger-codegen/issues
Java通常更喜欢CamelCase而不是snake_case,所以我猜这是故意的。
7qhs6swi4#
老主题了,但是我在直接从swagger.io生成typescript-angularjs时遇到了同样的问题。Snake -〉Camel转换。在生成代码时,modelPropertyNaming必须配置为snake_case,默认情况下是Camel。
https://github.com/swagger-api/swagger-codegen/wiki/FAQ#typescript
使用Docker的示例。
如果能帮到你们的话,伙计们。太好了。
iq3niunx5#
我在生成一个昂首阔步的客户端时也遇到了这个问题
将模型从snake case“aa_ba_ca”重命名为camel case“AaBaCa”
调用api_instance.method(swagger_client.model(parameters))时未找到模型,因此出错
错误:AttributeError swagger模块没有属性