Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect google.protobuf.Empty representation with oneof in GET request #4758

Open
lo00l opened this issue Sep 24, 2024 · 1 comment
Open

Comments

@lo00l
Copy link

lo00l commented Sep 24, 2024

🐛 Bug Report

Hi guys,

I have the following files

AdminAPI.proto:

syntax = "proto3";
option go_package = "./admin";

package admin;

import "google/protobuf/empty.proto";

service AdminService {
  rpc GetInstruments(GetInstrumentsRequest) returns (InstrumentList);
}

message InstrumentNameList {
  repeated string names = 1;
}

message GetInstrumentsRequest {
  oneof instrument_name_filter {
    google.protobuf.Empty all_instrument_names = 1;
    InstrumentNameList instrument_name_list = 2;
  }
}

message InstrumentList {
  repeated Instrument instruments = 1;
}

message Instrument {
  // long definition here
}

grpc_api_configuration.yaml:

type: google.api.Service
config_version: 3

http:
  rules:
    - selector: admin.AdminService.GetInstruments
      get: /v1/instruments

buf.gen.yaml:

version: v1
plugins:
  - plugin: go
    out: gen
    opt:
      - paths=source_relative
  - plugin: go-grpc
    out: gen
    opt:
      - paths=source_relative
  - plugin: grpc-gateway
    out: gen
    opt:
      - paths=source_relative
      - grpc_api_configuration=grpc_api_configuration.yaml
  - plugin: openapiv2
    out: docs
    opt:
      - grpc_api_configuration=grpc_api_configuration.yaml
      - output_format=yaml

After generating code with buf generate I get the following in my swagger:

paths:
  /v1/instruments:
    get:
      operationId: AdminService_GetInstruments
      responses:
        "200":
          description: A successful response.
          schema:
            $ref: '#/definitions/adminInstrumentList'
        default:
          description: An unexpected error response.
          schema:
            $ref: '#/definitions/rpcStatus'
      parameters:
        - name: allInstrumentNames
          in: query
          required: false
          type: object
        - name: instrumentNameList.names
          in: query
          required: false
          type: array
          items:
            type: string
          collectionFormat: multi
      tags:
        - AdminService

Seems it's impossible to provide allInstrumentNames in query. I tried different options, but always get an error

{
    "code": 3,
    "message": "parsing field \"all_instrument_names\": unsupported message type: \"google.protobuf.Empty\"",
    "details": []
}

Underlying gRPC service expects whether all_instrument_names or instrument_name_list to be filled, and we cannot change it.

If proto service method accepts just google.protobuf.Empty, everything works fine since REST server doesn't except any query parameters.

Also, if I change method to POST, everything becomes ok with the following request:

{
    "allInstrumentNames": {}
}

So are there any ways to fix it?

Expected behavior

There is a way to pass google.protobuf.Empty struct in query parameter.

Actual Behavior

REST server returns error

{
    "code": 3,
    "message": "parsing field \"all_instrument_names\": unsupported message type: \"google.protobuf.Empty\"",
    "details": []
}

Your Environment

grpc-gateway version is v2.22.0

@johanbrandhorst
Copy link
Collaborator

I don't know of any way to accomplish this, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants