ahultgren / swagger-elm

Generate Elm types and decoders based on a Swagger file
74 stars 9 forks source link

Support dictionary data structure #13

Closed mxinden closed 7 years ago

mxinden commented 7 years ago

According to the [Swagger specification] (http://swagger.io/specification/#model-with-map-dictionary-properties-88) a dict is defined by the following json:

{
  "type": "object",
  "additionalProperties": {
    "type": "string"
  }
}

This PR checks if the field additionalProperties is defined and properties is undefined. If so, it interprets it as a dict, otherwise as an object as usual. It will use the nested field type as the second type of the Elm dictionary. The above example would result in a dictionary Dict String String with a decoder dict string.

Related to issue #10, related to PR #12, and Alertmanager PR

mxinden commented 7 years ago

@ahultgren Porting my fix to new structure as discussed in PR #12. I will test it more tomorrow. Works with a new integration test already.

Let me know what you think. Hope there is not a 'rewrite everything 2' :-P

mxinden commented 7 years ago

@ahultgren Thanks for the review. I will look into it tomorrow. Was definitely easier the second time - good work!

mxinden commented 7 years ago

@ahultgren Addressed all your comments. Let me know what you think.

ahultgren commented 7 years ago

Awesome! Looks good 👍