{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/116","repository_url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas","labels_url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/116/comments","events_url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/116/events","html_url":"https://github.com/Azure/azure-resource-manager-schemas/issues/116","id":139997456,"number":116,"title":"mixed types in parameters make templates difficult to parse with statically typed languages ","user":{"login":"robbyt","id":58051,"avatar_url":"https://avatars.githubusercontent.com/u/58051?v=3","gravatar_id":"","url":"https://api.github.com/users/robbyt","html_url":"https://github.com/robbyt","followers_url":"https://api.github.com/users/robbyt/followers","following_url":"https://api.github.com/users/robbyt/following{/other_user}","gists_url":"https://api.github.com/users/robbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/robbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbyt/subscriptions","organizations_url":"https://api.github.com/users/robbyt/orgs","repos_url":"https://api.github.com/users/robbyt/repos","events_url":"https://api.github.com/users/robbyt/events{/privacy}","received_events_url":"https://api.github.com/users/robbyt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-10T20:16:21Z","updated_at":"2016-03-10T20:27:25Z","closed_at":null,"body":"related to #115 \r\n\r\nSince the ARM template parameters are a hash, parsing them with a statically typed language (in my case Go) is needlessly difficult. I appreciate that there is a \"type\" field, however, since every parameters object is a hash element, there's not an easy way to unmarshal the parameters JSON because the some of the parameter values could either be strings or integers.\r\n\r\nExample, given this simple parameters json:\r\n\r\n```json\r\n{\r\n  \"$schema\": \"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#\",\r\n  \"contentVersion\": \"1.0.0\",\r\n  \"parameters\": {\r\n    \"name\": {\r\n      \"type\": \"string\",\r\n      \"minLength\": 4,\r\n      \"maxLength\": 20,\r\n      \"defaultValue\": \"myServer\",\r\n      \"metadata\": {\r\n        \"description\": \"Unique name for instance(s) and their network/storage resources\"\r\n      }\r\n    },\r\n    \"numberOfInstances\": {\r\n      \"type\": \"int\",\r\n      \"minValue\": 1,\r\n      \"maxValue\": 20,\r\n      \"defaultValue\": 1,\r\n      \"metadata\": {\r\n        \"description\": \"The number of instances to be created in this request.\"\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nBecause of the non-idiomatic use of JSON to store parameters objects in a hash rather than an array, It's not possible to easily parse this data structure with a statically typed language, e.g., in Go I my struts looks like this:\r\n\r\n```go\r\ntype azureArmParamObject struct {\r\n    Type          string\r\n    DefaultValue  string\r\n    AllowedValues []string\r\n    MinValue      int\r\n    MaxValue      int\r\n    MinLength     int\r\n    MaxLength     int\r\n    Metadata      struct{ Description string }\r\n}\r\ntype azureArmJson struct {\r\n    Parameters map[string]azureArmParamObject\r\n}\r\n```\r\n\r\nHowever, since the `defaultvalue` can be either an int or a string, and each params object is being stored as a key in the params hash, it's not possible to parse this json using my struct.\r\n\r\nI have to instead write a lot of extra code to work around the unusual use of JSON in the parameters section of the ARM templates.\r\n\r\nIn this article, you can read more about why the current design of the ARM parameters makes it excessively hard to parse with statically typed languages, such as Go, Swift, Java, C++, C#, etc:\r\nhttp://gowithconfidence.tumblr.com/post/119295279861/decoding-with-mixed-structures\r\n\r\nFrom the article:\r\n\r\n> Decoding with mixed structures\r\n> \r\n> Often people who don’t know any better will hand you a blob of JSON, or YAML, or some other structured document format, declare it to be the protocol, and then quit or move onto some other project.\r\n> \r\n> When this protocol contains collections that contain values of more than one type, you know that the original implementation is written in a dynamically typed language that does not require you to know what type something is before putting data into it.\r\n> \r\n> Let me begin with a plea to not have mixed structure collections! If you have a collection that can have elements that are one of N types, instead just have N collections, indexed by their type name. This is much simpler to decode and to think about."},"comment":{"url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/comments/195033331","html_url":"https://github.com/Azure/azure-resource-manager-schemas/issues/116#issuecomment-195033331","issue_url":"https://api.github.com/repos/Azure/azure-resource-manager-schemas/issues/116","id":195033331,"user":{"login":"robbyt","id":58051,"avatar_url":"https://avatars.githubusercontent.com/u/58051?v=3","gravatar_id":"","url":"https://api.github.com/users/robbyt","html_url":"https://github.com/robbyt","followers_url":"https://api.github.com/users/robbyt/followers","following_url":"https://api.github.com/users/robbyt/following{/other_user}","gists_url":"https://api.github.com/users/robbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/robbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbyt/subscriptions","organizations_url":"https://api.github.com/users/robbyt/orgs","repos_url":"https://api.github.com/users/robbyt/repos","events_url":"https://api.github.com/users/robbyt/events{/privacy}","received_events_url":"https://api.github.com/users/robbyt/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T20:27:25Z","updated_at":"2016-03-10T20:27:25Z","body":"cc @ahmetalpbalkan"}}