So, I'm having trouble using an XML object definition with Swagger (Core 1.5.7). Here's my XML code:
<result status="ok">
<another>
<cards/>
<customer my_super_id="2349027834"/>
<someothers>
<someother name="who-is-this" />
</someothers>
</another>
</result>
And here's my yml code:
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
I can get the status
with no problem, but the my_super_id
is null
because Swagger is generating the model class with the parameter in CamelCase, i.e., mySuperId
instead of my_super_id
.
In my generated model class I have this:
public ResultAnotherCustomer(@JsonProperty("mySuperId") final String mySuperId)
Is there any way to solve this?
Stupid as it is, it seems I wasn't using the latest version of swagger-codegen
, so updating it to the latest version (2.1.5) fixed the problem.
I was facing the same issue in Java Springboot App using Swagger Open API Specification. I ended overidding a Bean to make it work. But again this is how I fixed in Springboot with OAS.
@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
return new ModelResolver(objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With