Repository: salesforce/reactive-grpc (java)

Issue:
Support optional feature
Hello,
With protobuf 3.12.x came the experimental feature of the optional fields. The general availability was targeted to 3.13.x but has been postponed to (hopefully) the next release.
I tried to use the experimental feature, but I can't get it to work with reactive-grpc, I get the following message:

> file.apg is a proto3 file that contains optional fields, but code generator protoc-gen-reactor hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional

Could you consider supporting this feature? Thanks

https://github.com/protocolbuffers/protobuf/blob/master/docs/implementing_proto3_presence.md#signaling-that-your-code-generator-supports-proto3-optional

Pull request:
Add support for proto3 optional
Fixes #230

* Upgrade to grpc-java 1.37.0
* Upgrade to protoc 3.15.8
* Upgrade to jprotoc 1.1.0

Patch:
diff --git a/common/reactive-grpc-benchmarks/pom.xml b/common/reactive-grpc-benchmarks/pom.xml
index b142bdc..dd68c61 100644
--- a/common/reactive-grpc-benchmarks/pom.xml
+++ b/common/reactive-grpc-benchmarks/pom.xml
@@ -43,6 +43,10 @@
             <groupId>io.grpc</groupId>
             <artifactId>grpc-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/common/reactive-grpc-gencommon/pom.xml b/common/reactive-grpc-gencommon/pom.xml
index 038263c..4705be3 100644
--- a/common/reactive-grpc-gencommon/pom.xml
+++ b/common/reactive-grpc-gencommon/pom.xml
@@ -21,6 +21,10 @@
             <groupId>com.salesforce.servicelibs</groupId>
             <artifactId>jprotoc</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java b/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java
index 21b9f89..9266f12 100644
--- a/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java
+++ b/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java
@@ -21,6 +21,7 @@ import com.salesforce.jprotoc.ProtoTypeMap;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -54,6 +55,11 @@ public abstract class ReactiveGrpcGenerator extends Generator {
         return generateFiles(services);
     }
 
+    @Override
+    protected List<PluginProtos.CodeGeneratorResponse.Feature> supportedFeatures() {
+        return Collections.singletonList(PluginProtos.CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL);
+    }
+
     private List<ServiceContext> findServices(List<FileDescriptorProto> protos, ProtoTypeMap typeMap) {
         List<ServiceContext> contexts = new ArrayList<>();
 
diff --git a/pom.xml b/pom.xml
index 9aafa96..5088d87 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,12 +58,13 @@
         <!-- Maven Plugin Versions -->
         <protobuf.plugin.version>0.6.1</protobuf.plugin.version>
         <compiler.plugin.version>3.8.0</compiler.plugin.version>
+        <canteen.plugin.version>1.1.0</canteen.plugin.version>
 
         <!-- Dependency Versions -->
         <reactive.streams.version>1.0.2</reactive.streams.version>
-        <grpc.version>1.23.0</grpc.version>
-        <protoc.version>3.9.0</protoc.version> <!-- Same version as grpc-proto -->
-        <jprotoc.version>0.9.1</jprotoc.version>
+        <grpc.version>1.37.0</grpc.version>
+        <protoc.version>3.15.8</protoc.version> <!-- Same version as grpc-proto -->
+        <jprotoc.version>1.1.0</jprotoc.version>
         <rxjava.version>2.2.12</rxjava.version>
         <reactor.version>3.2.12.RELEASE</reactor.version>
 
@@ -131,6 +132,11 @@
                 <artifactId>jprotoc</artifactId>
                 <version>${jprotoc.version}</version>
             </dependency>
+            <dependency>
+                <groupId>com.google.protobuf</groupId>
+                <artifactId>protobuf-java</artifactId>
+                <version>${protoc.version}</version>
+            </dependency>
             <dependency>
                 <groupId>io.grpc</groupId>
                 <artifactId>grpc-netty</artifactId>
@@ -146,6 +152,11 @@
                 <artifactId>grpc-core</artifactId>
                 <version>${grpc.version}</version>
             </dependency>
+            <dependency>
+                <groupId>io.grpc</groupId>
+                <artifactId>grpc-api</artifactId>
+                <version>${grpc.version}</version>
+            </dependency>
             <dependency>
                 <groupId>io.grpc</groupId>
                 <artifactId>grpc-context</artifactId>
diff --git a/reactor/reactor-grpc-tck/pom.xml b/reactor/reactor-grpc-tck/pom.xml
index e8367bd..1ed2d89 100644
--- a/reactor/reactor-grpc-tck/pom.xml
+++ b/reactor/reactor-grpc-tck/pom.xml
@@ -36,6 +36,11 @@
             <artifactId>grpc-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/reactor/reactor-grpc/pom.xml b/reactor/reactor-grpc/pom.xml
index aa16ab2..6b99aae 100644
--- a/reactor/reactor-grpc/pom.xml
+++ b/reactor/reactor-grpc/pom.xml
@@ -69,7 +69,7 @@
             <plugin>
                 <groupId>com.salesforce.servicelibs</groupId>
                 <artifactId>canteen-maven-plugin</artifactId>
-                <version>1.0.2</version>
+                <version>${canteen.plugin.version}</version>
                 <executions>
                     <execution>
                         <goals>
diff --git a/rx-java/rxgrpc-tck/pom.xml b/rx-java/rxgrpc-tck/pom.xml
index e3b9656..3f0ab80 100644
--- a/rx-java/rxgrpc-tck/pom.xml
+++ b/rx-java/rxgrpc-tck/pom.xml
@@ -36,6 +36,11 @@
             <artifactId>grpc-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/rx-java/rxgrpc/pom.xml b/rx-java/rxgrpc/pom.xml
index 511587f..f05289a 100644
--- a/rx-java/rxgrpc/pom.xml
+++ b/rx-java/rxgrpc/pom.xml
@@ -69,7 +69,7 @@
             <plugin>
                 <groupId>com.salesforce.servicelibs</groupId>
                 <artifactId>canteen-maven-plugin</artifactId>
-                <version>1.0.2</version>
+                <version>${canteen.plugin.version}</version>
                 <executions>
                     <execution>
                         <goals>


Test patch:
diff --git a/reactor/reactor-grpc-test-32/pom.xml b/reactor/reactor-grpc-test-32/pom.xml
index 079d9f8..29a1020 100644
--- a/reactor/reactor-grpc-test-32/pom.xml
+++ b/reactor/reactor-grpc-test-32/pom.xml
@@ -46,6 +46,11 @@
             <artifactId>grpc-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/reactor/reactor-grpc-test/pom.xml b/reactor/reactor-grpc-test/pom.xml
index 36f8f9d..7044a48 100644
--- a/reactor/reactor-grpc-test/pom.xml
+++ b/reactor/reactor-grpc-test/pom.xml
@@ -47,6 +47,11 @@
             <artifactId>grpc-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/reactor/reactor-grpc-test/src/test/proto/helloworld_optional.proto b/reactor/reactor-grpc-test/src/test/proto/helloworld_optional.proto
new file mode 100644
index 0000000..5bfc3e2
--- /dev/null
+++ b/reactor/reactor-grpc-test/src/test/proto/helloworld_optional.proto
@@ -0,0 +1,22 @@
+syntax = "proto3";
+
+package optional_helloworld;
+
+option java_package = "com.salesforce.rxgrpc";
+option java_outer_classname = "HelloWorldOptionalProto";
+
+// The greeting service definition.
+service OptionalGreeter {
+    // Sends a greeting
+    rpc SayHello (OptionalHelloRequest) returns (OptionalHelloResponse) {}
+}
+
+// The request message containing the user's name.
+message OptionalHelloRequest {
+    optional string name = 1;
+}
+
+// The response message containing the greetings
+message OptionalHelloResponse {
+    optional string message = 1;
+}
\ No newline at end of file
diff --git a/rx-java/rxgrpc-test/pom.xml b/rx-java/rxgrpc-test/pom.xml
index 7492740..57a2139 100644
--- a/rx-java/rxgrpc-test/pom.xml
+++ b/rx-java/rxgrpc-test/pom.xml
@@ -36,6 +36,11 @@
             <artifactId>grpc-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-stub</artifactId>
diff --git a/rx-java/rxgrpc-test/src/test/proto/helloworld_optional.proto b/rx-java/rxgrpc-test/src/test/proto/helloworld_optional.proto
new file mode 100644
index 0000000..5bfc3e2
--- /dev/null
+++ b/rx-java/rxgrpc-test/src/test/proto/helloworld_optional.proto
@@ -0,0 +1,22 @@
+syntax = "proto3";
+
+package optional_helloworld;
+
+option java_package = "com.salesforce.rxgrpc";
+option java_outer_classname = "HelloWorldOptionalProto";
+
+// The greeting service definition.
+service OptionalGreeter {
+    // Sends a greeting
+    rpc SayHello (OptionalHelloRequest) returns (OptionalHelloResponse) {}
+}
+
+// The request message containing the user's name.
+message OptionalHelloRequest {
+    optional string name = 1;
+}
+
+// The response message containing the greetings
+message OptionalHelloResponse {
+    optional string message = 1;
+}
\ No newline at end of file