richhollis/swagger-docs — pull request #55 by aaronrenner (2014-05-28 17:24:41+00:00)
Title: Made camelize model properties configurable and fixed swagger_model name capitalization issue

This addresses #49 by introducing a new configuration property `:camelize_model_properties`. The default value is true to maintain backward compatibility. If set to false, it uses the model properties exactly the way they are passed in.

I also had an issue where if the model name was not camelcased, the model name in the parameter type field wouldn't match the key in the models hash.

```json
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000/",
"apis": [
{
"path": "sk/start_purchase2",
"operations": [
{
"summary": "...",
"parameters": [
{
"paramType": "form",
"name": "order_data",
"type": "OrderData",
"description": "Order Data",
"required": true
}
],
"method": "post",
"nickname": "Sk::V2::Purchases#start"
}
]
},
]
}
],
"resourcePath": "purchases",
"models": {
"orderData": {
"id": "OrderData",
"required": [ ... ],
"properties": { ... }
}
}
}
```
You can see that the type of the "order_data" param ("OrderData") does not match up the it's key in the models hash ("orderData"). This was causing issues in the swagger ui because it couldn't find a model definition with a key of "OrderData".

Finally, to ease testability, I extracted a class called ApiDeclarationFile that is named after the Api declaration files in the swagger spec (https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-declaration). This class's responsibility is to build the resource hash that will be serialized as json and written out to a file. I made sure all of your test coverage passed and wrote my own coverage as it went.

Let me know if you have any feedback. I'm excited that I could fix these issues.