Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made camelize model properties configurable and fixed swagger_model name capitalization issue #55

Conversation

aaronrenner
Copy link
Contributor

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.

{
  "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.

* Fix model tag name so it is the same case as the symbol passed in. A
swagger_model :Tag was being put into the json models hash as 'tag'
instead of 'Tag'
* Created ApiDeclarationFileMetadata class to make it clear the fields
that are needed on the ApiDeclarationFile metadata object
* Updated readme
richhollis added a commit that referenced this pull request May 30, 2014
…s_configurable

Made camelize model properties configurable and fixed swagger_model name capitalization issue
@richhollis richhollis merged commit aa6d9d4 into richhollis:master May 30, 2014
@richhollis
Copy link
Owner

@aaronrenner This is really great. Thank you for taking the time to contribute.

@aaronrenner aaronrenner deleted the make_camelize_model_properties_configurable branch June 1, 2014 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants