Skip to content

There isn't necessary fields in *pb.gw.go file #6037

@Illia-S-dev

Description

@Illia-S-dev

🐛 Bug Report

I have two messages

message DeleteBookRequest {
  string shelf_id = 1; // The ID of the shelf containing the book.
  string book_id = 2;  // The ID of the book to delete.
}
message DeleteBookResponse {}

And there is a readWrite service

service ReadWriteService {
  rpc DeleteBook(DeleteBookRequest) returns (DeleteBookResponse) {
    option (google.api.http) = {
      delete: "/v1/shelves/{shelf_id}/books/{book_id}"
    };
  }
}

To Reproduce

  1. Create messages and a service in *.proto
  2. run buf generate
  3. check *.pb.gw.go file

Expected behavior

There is no errors and I can run for example go run

Actual Behavior

I have the next errors in *.pb.gw.go
for example this func

func request_ReadWriteService_DeleteBook_0(ctx context.Context, marshaler runtime.Marshaler, client ReadWriteServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var (
		protoReq DeleteBookRequest
		metadata runtime.ServerMetadata
		err      error
	)
	if req.Body != nil {
		_, _ = io.Copy(io.Discard, req.Body)
	}
	val, ok := pathParams["shelf_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "shelf_id")
	}
	protoReq.ShelfId, err = runtime.String(val)
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "shelf_id", err)
	}
	val, ok = pathParams["book_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "book_id")
	}
	protoReq.BookId, err = runtime.String(val)
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "book_id", err)
	}
	msg, err := client.DeleteBook(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err
}
Image

As you can see on the screen, protoReq with type DeleteBookRequest
P.S. The type DeleteBookRequest from *.pb.go

type DeleteBookRequest struct {
	state                  protoimpl.MessageState `protogen:"opaque.v1"`
	xxx_hidden_ShelfId     *string                `protobuf:"bytes,1,opt,name=shelf_id,json=shelfId"`
	xxx_hidden_BookId      *string                `protobuf:"bytes,2,opt,name=book_id,json=bookId"`
	XXX_raceDetectHookData protoimpl.RaceDetectHookData
	XXX_presence           [1]uint32
	unknownFields          protoimpl.UnknownFields
	sizeCache              protoimpl.SizeCache
}

So, protoReq doesn't have both ShelfId and BookId

Your Environment

go version go1.25.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions