5

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?

Schrödinger's Box
  • 3,138
  • 1
  • 28
  • 50

4 Answers4

2

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.

Schrödinger's Box
  • 3,138
  • 1
  • 28
  • 50
1

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));
}
Sourabh
  • 335
  • 2
  • 14
0

My experience working with the Swagger coder generator is that it gets me about 80% of what I want and then I have to do the rest myself. If you think this is a bug than you can log it here: https://github.com/swagger-api/swagger-codegen/issues

Java generally favors CamelCase over snake_case so I'm guessing that it's intentional.

Charlie
  • 1,692
  • 3
  • 17
  • 34
  • Can you share a bit more about the rest that you need to do manually? Thanks. Please share your feedback with us via https://github.com/swagger-api/swagger-codegen/issues – William Cheng Apr 06 '16 at 04:47
-1

I also had this issue when generating a swagger client

The models were renamed from snake case 'aa_ba_ca' to camel case 'AaBaCa'

Error arose as no model was found when calling api_instance.method(swagger_client.model(parameters))

Error: AttributeError swagger module has no attribute

user3712978
  • 157
  • 2
  • 6