{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2714","repository_url":"https://api.github.com/repos/swagger-api/swagger-codegen","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2714/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2714/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2714/events","html_url":"https://github.com/swagger-api/swagger-codegen/issues/2714","id":151302056,"number":2714,"title":"C# - Lists of enums not properly generated ","user":{"login":"JoshuaWhatley","id":3322909,"avatar_url":"https://avatars.githubusercontent.com/u/3322909?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshuaWhatley","html_url":"https://github.com/JoshuaWhatley","followers_url":"https://api.github.com/users/JoshuaWhatley/followers","following_url":"https://api.github.com/users/JoshuaWhatley/following{/other_user}","gists_url":"https://api.github.com/users/JoshuaWhatley/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshuaWhatley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshuaWhatley/subscriptions","organizations_url":"https://api.github.com/users/JoshuaWhatley/orgs","repos_url":"https://api.github.com/users/JoshuaWhatley/repos","events_url":"https://api.github.com/users/JoshuaWhatley/events{/privacy}","received_events_url":"https://api.github.com/users/JoshuaWhatley/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/labels/Client:%20C-Sharp","name":"Client: C-Sharp","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/milestones/9","html_url":"https://github.com/swagger-api/swagger-codegen/milestones/v2.2.0","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/milestones/9/labels","id":1375944,"number":9,"title":"v2.2.0","description":"","creator":{"login":"fehguy","id":249413,"avatar_url":"https://avatars.githubusercontent.com/u/249413?v=3","gravatar_id":"","url":"https://api.github.com/users/fehguy","html_url":"https://github.com/fehguy","followers_url":"https://api.github.com/users/fehguy/followers","following_url":"https://api.github.com/users/fehguy/following{/other_user}","gists_url":"https://api.github.com/users/fehguy/gists{/gist_id}","starred_url":"https://api.github.com/users/fehguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fehguy/subscriptions","organizations_url":"https://api.github.com/users/fehguy/orgs","repos_url":"https://api.github.com/users/fehguy/repos","events_url":"https://api.github.com/users/fehguy/events{/privacy}","received_events_url":"https://api.github.com/users/fehguy/received_events","type":"User","site_admin":false},"open_issues":174,"closed_issues":376,"state":"open","created_at":"2015-10-25T23:43:33Z","updated_at":"2016-05-28T03:12:34Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2016-04-27T05:29:34Z","updated_at":"2016-05-28T14:38:46Z","closed_at":null,"body":"SwashBuckle will generate a swagger json similar to the following for List<enumType>. The generated client code contains a couple mistakes. \r\n\r\n- The name is missing\r\n- Missing [JsonConverter(typeof(StringEnumConverter))]\r\n- The generic type in the list is correct in the constructor, but incorrect in the property\r\n\r\n```\r\npublic enum {\r\n    [EnumMember(Value = \"food\")]\r\n    Food,\r\n            \r\n    [EnumMember(Value = \"bar\")]\r\n    Bar\r\n}\r\n\r\npublic ResponseContract(GoodEnumEnum? GoodEnum = null, List<listOfEnumsEnum?> ListOfEnums = null)\r\n{\r\n    this.GoodEnum = GoodEnum;\r\n    this.ListOfEnums = ListOfEnums;\r\n}\r\n\r\n/// <summary>\r\n/// Some Description\r\n/// </summary>\r\n/// <value>Some Description</value>\r\n[DataMember(Name=\"listOfEnums\", EmitDefaultValue=false)]\r\npublic List<string> ListOfEnums { get; set; }\r\n```\r\n\r\nSwagger Doc:\r\n```\r\n{\r\n\t\"swagger\": \"2.0\",\r\n\t\"info\": {\r\n\t\t\"version\": \"V1\",\r\n\t\t\"title\": \"Title\"\r\n\t},\r\n\t\"host\": \"example.com\",\r\n  \"schemes\": [ \"https\" ],\r\n  \"paths\": {\r\n\t\t\"/v1.0/example\": {\r\n\t\t\t\"post\": {\r\n\t\t\t\t\"tags\": [\"Tag\"],\r\n\t\t\t\t\"summary\": \"Summary\",\r\n\t\t\t\t\"operationId\": \"Some Id\",\r\n\t\t\t\t\"consumes\": [\"application/json\", \"text/json\", \"application/xml\", \"text/xml\", \"application/x-www-form-urlencoded\"],\r\n\t\t\t\t\"produces\": [\"application/json\", \"text/json\", \"application/xml\", \"text/xml\"],\r\n\t\t\t\t\"parameters\": [{\r\n\t\t\t\t\t\"name\": \"request\",\r\n\t\t\t\t\t\"in\": \"body\",\r\n\t\t\t\t\t\"description\": \"request\",\r\n\t\t\t\t\t\"required\": true,\r\n\t\t\t\t\t\"schema\": {\r\n\t\t\t\t\t\t\"$ref\": \"#/definitions/ResponseContract\"\r\n\t\t\t\t\t}\r\n\t\t\t\t}],\r\n\t\t\t\t\"responses\": {\r\n\t\t\t\t\t\"200\": {\r\n\t\t\t\t\t\t\"description\": \"Some description\",\r\n\t\t\t\t\t\t\"schema\": {\r\n\t\t\t\t\t\t\t\"$ref\": \"#/definitions/ResponseContract\"\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t},\r\n\t\t\t\t\"deprecated\": false\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\t\"definitions\": {\r\n\t\t\"ResponseContract\": {\r\n\t\t\t\"description\": \"Some Description\",\r\n\t\t\t\"type\": \"object\",\r\n\t\t\t\"properties\": {\r\n\t\t\t\t\"goodEnum\": {\r\n\t\t\t\t\t\"description\": \"Some Description\",\r\n\t\t\t\t\t\"enum\": [\"food\", \"bar\"],\r\n\t\t\t\t\t\"type\": \"string\"\r\n\t\t\t\t},\r\n\t\t\t\t\"listOfEnums\": {\r\n\t\t\t\t\t\"description\": \"Some Description\",\r\n\t\t\t\t\t\"type\": \"array\",\r\n\t\t\t\t\t\"items\": {\r\n\t\t\t\t\t\t\"enum\": [\"food\", \"bar\"],\r\n\t\t\t\t\t\t\"type\": \"string\"\r\n\t\t\t\t\t},\r\n\t\t\t\t\t\"readOnly\": true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nI have a fix, but it is leveraging a hack written by a previous contributor. I'll submit a pull request so that we can discuss.  "},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/comments/222311785","html_url":"https://github.com/swagger-api/swagger-codegen/issues/2714#issuecomment-222311785","issue_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2714","id":222311785,"user":{"login":"jimschubert","id":109659,"avatar_url":"https://avatars.githubusercontent.com/u/109659?v=3","gravatar_id":"","url":"https://api.github.com/users/jimschubert","html_url":"https://github.com/jimschubert","followers_url":"https://api.github.com/users/jimschubert/followers","following_url":"https://api.github.com/users/jimschubert/following{/other_user}","gists_url":"https://api.github.com/users/jimschubert/gists{/gist_id}","starred_url":"https://api.github.com/users/jimschubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimschubert/subscriptions","organizations_url":"https://api.github.com/users/jimschubert/orgs","repos_url":"https://api.github.com/users/jimschubert/repos","events_url":"https://api.github.com/users/jimschubert/events{/privacy}","received_events_url":"https://api.github.com/users/jimschubert/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T14:38:46Z","updated_at":"2016-05-28T14:38:46Z","body":"I haven't looked at the issue at hand with Enums, Lists, or Dictionaries. @wing328 did you make any progress on this issue?\r\n\r\n@aws-na-ss-usplu Since you've put a lot of research into your comment, I wanted to address it somewhat in depth.\r\n\r\n> Primitive data types in the Swagger Specification are based on the types supported by the JSON-Schema Draft 4. Models are described using the Schema Object which is a subset of JSON Schema Draft 4.\r\n> [Swagger Specification](http://swagger.io/specification/)\r\n\r\nThe Loopback issue you pointed to is more about implementing enum support correctly in the datasource abstraction and emitting the swagger definition correctly against the JSON Schema enum specification (http://json-schema.org/latest/json-schema-validation.html#anchor76).\r\n\r\nYour first link to Autorest highlights the main problem. There can be no standard representation across all languages for an enum, because not all languages support enums and those that do don't support them in exactly the same way.\r\n\r\nFor example, these are all valid enums in C#:\r\n\r\n```\r\npublic enum Color { Red, Green, Blue }\r\n\r\npublic enum ColorDecimal \r\n{ \r\n    Red  = 16711680, \r\n    Green = 65280, \r\n    Blue = 255\r\n}\r\n\r\n[Flags]\r\npublic enum Permissions\r\n{\r\n    CREATE        = 1 << 0,\r\n    READ            = 1 << 1,\r\n    UPDATE        = 1 << 2,\r\n    DELETE        = 1 << 3\r\n}\r\n\r\n[Flags]\r\npublic enum AuthorizationBits : Long\r\n{\r\n    Minimal                    = 1 << 0,\r\n    ReadArticles            = 1 << 15 ,\r\n    RemoveComments  = 1 << 20,\r\n    Moderation               = 1 << 62\r\n}\r\n\r\npublic enum HttpStatusCode\r\n{\r\n    // Informational 1xx\r\n    Continue = 100,\r\n    SwitchingProtocols = 101,\r\n\r\n    // Successful 2xx\r\n    OK = 200,\r\n    Created = 201,\r\n    Accepted = 202,\r\n    NonAuthoritativeInformation = 203,\r\n    NoContent = 204,\r\n    ResetContent = 205,\r\n    PartialContent = 206,\r\n    //…\r\n}\r\n```\r\n\r\nAnd this is a valid Java enum:\r\n\r\n```\r\npublic enum Planet {\r\n    MERCURY (3.303e+23, 2.4397e6),\r\n    VENUS   (4.869e+24, 6.0518e6),\r\n    EARTH   (5.976e+24, 6.37814e6),\r\n    MARS    (6.421e+23, 3.3972e6),\r\n    JUPITER (1.9e+27,   7.1492e7),\r\n    SATURN  (5.688e+26, 6.0268e7),\r\n    URANUS  (8.686e+25, 2.5559e7),\r\n    NEPTUNE (1.024e+26, 2.4746e7);\r\n\r\n    private final double mass;   // in kilograms\r\n    private final double radius; // in meters\r\n    Planet(double mass, double radius) {\r\n        this.mass = mass;\r\n        this.radius = radius;\r\n    }\r\n    private double mass() { return mass; }\r\n    private double radius() { return radius; }\r\n\r\n    // universal gravitational constant  (m3 kg-1 s-2)\r\n    public static final double G = 6.67300E-11;\r\n\r\n    double surfaceGravity() {\r\n        return G * mass / (radius * radius);\r\n    }\r\n    double surfaceWeight(double otherMass) {\r\n        return otherMass * surfaceGravity();\r\n    }\r\n    public static void main(String[] args) {\r\n        if (args.length != 1) {\r\n            System.err.println(\"Usage: java Planet <earth_weight>\");\r\n            System.exit(-1);\r\n        }\r\n        double earthWeight = Double.parseDouble(args[0]);\r\n        double mass = earthWeight/EARTH.surfaceGravity();\r\n        for (Planet p : Planet.values())\r\n           System.out.printf(\"Your weight on %s is %f%n\",\r\n                             p, p.surfaceWeight(mass));\r\n    }\r\n}\r\n```\r\n\r\nTo support a universal definition of an enum would be complex. I'll touch on this briefly, since you asked for some feedback.\r\n\r\nI'm assuming this complexity is why Microsoft has prefixed their vendor extensions with `x-ms-`... there's just too many Microsoft concerns related to enums. In my examples above, `Color` could easily be output to the JSON Schema definition of a string representing the values with at least one value in the array. To support `ColorDecimal`, you would then have to apply some extension that supports a key/value pair.  Then, you can add some extension to indicate to clients that the `Permissions` enum is a bitmask (a special case of enum).\r\n\r\nAt this point, most languages will be able to support the enum definition natively, even if it's quite a bit of code.\r\n\r\nNow if you try to support `AuthorizationBits` consistently across languages, you'll start running into issues with some clients. For instance, we know that all numbers in JavaScript are 64-bit floating point numbers.  Many people don't know, however, that only the first 52 bits of a JavaScript number contain a value. Then, 11 bits are for holding an exponent, and the last bit is for the sign. You can [read more here](http://speakingjs.com/es5/ch11.html). If you put a 64 bit value into an enum's value, some clients like JavaScript won't store a 64 bit value. You can work around this in different ways, but they're all hacky. It's obvious from this one example that you can't make all languages happy with a generic definition.\r\n\r\nThen, you have an example of a valid enum in Java. `Planet` is a singleton structure which doesn't just assign one value to one key... it applies a tuple of key/values to one enum. For instance:\r\n\r\n```\r\nPlanet:\r\n    MERCURY => ( (mass => 3.303e+23), (radius => 2.4397e6) )\r\n```\r\n\r\nAt this point, you'd need to indicate that `Planet` has complex values which store complex metadata about those values. This is really just an object. It would be better for whatever swagger definition generator used in the Java code to represent this enum as an immutable object rather than an enum.\r\n\r\nThat last example brings it back around to the Loopback example. Their implementation may have additional metadata applied to the enum. It may result in an object representation rather than an enum."}}
{"actor":{"display_login":"jimschubert"}}