grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

bug: URL Query parameter not bind to `Optional` proto message field

Open afifurrohman-id opened this issue 6 months ago • 3 comments

🐛 Bug Report

When using optional field as request message and will be expected to bind with HTTP url query parameter the optional field always nil

To Reproduce

  • buf.gen.yaml
version: v2
plugins:
  - local: protoc-gen-go
    out: .
    opt: paths=source_relative
  - local: protoc-gen-go-grpc
    out: .
    opt: paths=source_relative
  - local: protoc-gen-grpc-gateway
    out: .
    opt: paths=source_relative

inputs:
  - directory: .
  • buf.yaml
version: v2
name: example.com/foo
deps:
  - buf.build/googleapis/googleapis

  • svc.proto
syntax = "proto3";

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

message DeleteFooRequest {
    string foo_id = 1;
    optional bool soft_delete = 2;
}

service ProductService {

    rpc DeleteFoo(DeleteFooRequest) returns (google.protobuf.Empty) {
        option (google.api.http) = {
            delete: "/foo/{foo_id}"
        };
    }

}
  • Generate stub
buf generate
  • Create normal grpc gateway server
  • Test using curl with url?soft_delete=true or url?soft_delete=false

Expected behavior

it should either false or true

Actual Behavior

Soft delete it will always nil

Your Environment

Linux GRPC-GATEWAY 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux

afifurrohman-id avatar Aug 26 '24 09:08 afifurrohman-id