-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from soundcloud/support-proto3-optional
Add support for 'optional' in proto3 files
- Loading branch information
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
codegen/src/sbt-test/generator/e2e/src/main/protobuf/optional_fields.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// A small test case for support of optional fields in proto3. | ||
|
||
syntax = "proto3"; | ||
|
||
package proto.test; | ||
|
||
message IHaveOptionalFields { | ||
optional int32 maybe_int = 1; | ||
optional string maybe_string = 2; | ||
} | ||
|
||
service OptionalFieldsTest { | ||
rpc DoSomething(IHaveOptionalFields) returns (IHaveOptionalFields); | ||
} |
33 changes: 33 additions & 0 deletions
33
codegen/src/sbt-test/generator/e2e/src/test/scala/proto/test/OptionalFieldsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package proto.test | ||
|
||
import com.twitter.util.Future | ||
import com.soundcloud.twinagle.ServerBuilder | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
class OptionalFieldsSpec extends Specification { | ||
// if this compiles, we're good | ||
"Proto files with optional scalar values are generated correctly" in { | ||
val svc = new OptionalFieldsTestService { | ||
override def doSomething(req: IHaveOptionalFields): Future[IHaveOptionalFields] = { | ||
iTakeAnOptionInt(req.maybeInt) | ||
iTakeAnOptionString(req.maybeString) | ||
Future.value(req) | ||
} | ||
|
||
@annotation.nowarn | ||
private def iTakeAnOptionInt[T](a: T)(implicit ev: T =:= Option[Int]): Unit = () | ||
|
||
@annotation.nowarn | ||
private def iTakeAnOptionString[T](a: T)(implicit ev: T =:= Option[String]): Unit = () | ||
} | ||
|
||
val httpService = ServerBuilder() | ||
.register(svc) | ||
.build | ||
|
||
new OptionalFieldsTestClientProtobuf(httpService) | ||
new OptionalFieldsTestClientJson(httpService) | ||
ok | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters