{"action":"created","issue":{"url":"https://api.github.com/repos/apple/swift-protobuf/issues/131","repository_url":"https://api.github.com/repos/apple/swift-protobuf","labels_url":"https://api.github.com/repos/apple/swift-protobuf/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/apple/swift-protobuf/issues/131/comments","events_url":"https://api.github.com/repos/apple/swift-protobuf/issues/131/events","html_url":"https://github.com/apple/swift-protobuf/issues/131","id":186568299,"number":131,"title":"Generated code for protobuf 2 optionals, becomes non-optional fields in Swift","user":{"login":"erikt","id":76964,"avatar_url":"https://avatars.githubusercontent.com/u/76964?v=3","gravatar_id":"","url":"https://api.github.com/users/erikt","html_url":"https://github.com/erikt","followers_url":"https://api.github.com/users/erikt/followers","following_url":"https://api.github.com/users/erikt/following{/other_user}","gists_url":"https://api.github.com/users/erikt/gists{/gist_id}","starred_url":"https://api.github.com/users/erikt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikt/subscriptions","organizations_url":"https://api.github.com/users/erikt/orgs","repos_url":"https://api.github.com/users/erikt/repos","events_url":"https://api.github.com/users/erikt/events{/privacy}","received_events_url":"https://api.github.com/users/erikt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-01T15:46:46Z","updated_at":"2016-11-02T14:58:53Z","closed_at":null,"body":"Protobuf 2 optionals generates Swift structs with non-optional fields.\r\n\r\nGiven this protobuf definition:\r\n\r\n    syntax = \"proto2\";\r\n    message Foo {\r\n        optional int32 field1 = 1;\r\n        optional string field2 = 2;\r\n    }\r\n\r\nThe generated code is (abbreviated):\r\n\r\n    private var _field1: Int32? = nil\r\n    public var field1: Int32 {\r\n        get {return _field1 ?? 0}\r\n        set {_field1 = newValue}\r\n    }\r\n    \r\n    private var _field2: String? = nil\r\n    public var field2: String {\r\n        get {return _field2 ?? \"\"}\r\n        set {_field2 = newValue}\r\n    }\r\n\r\nAccording to the documentation ([GENERATED_CODE.md](https://github.com/apple/swift-protobuf/blob/master/Documentation/GENERATED_CODE.md)) the generated structure should be:\r\n\r\n    struct Foo {\r\n       public var field1: Int32? = nil\r\n       public var field2: String? = nil\r\n    }\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apple/swift-protobuf/issues/comments/257890286","html_url":"https://github.com/apple/swift-protobuf/issues/131#issuecomment-257890286","issue_url":"https://api.github.com/repos/apple/swift-protobuf/issues/131","id":257890286,"user":{"login":"erikt","id":76964,"avatar_url":"https://avatars.githubusercontent.com/u/76964?v=3","gravatar_id":"","url":"https://api.github.com/users/erikt","html_url":"https://github.com/erikt","followers_url":"https://api.github.com/users/erikt/followers","following_url":"https://api.github.com/users/erikt/following{/other_user}","gists_url":"https://api.github.com/users/erikt/gists{/gist_id}","starred_url":"https://api.github.com/users/erikt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikt/subscriptions","organizations_url":"https://api.github.com/users/erikt/orgs","repos_url":"https://api.github.com/users/erikt/repos","events_url":"https://api.github.com/users/erikt/events{/privacy}","received_events_url":"https://api.github.com/users/erikt/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T14:58:53Z","updated_at":"2016-11-02T14:58:53Z","body":"After having gone through the commits for the last 14 or so days, I found [Generate non-optional properties for all fields. #102](https://github.com/apple/swift-protobuf/pull/102) and understand this issue much better. \r\n\r\nIs the current solution that I am responsible for checking with `has` and setting the Swift optional? It feels quite weird, having `optional` and `Optional` on both sides, but it is what it is I guess."}}
{"actor":{"display_login":"erikt"}}