question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GRPC JSON transcoding : query parameters not "discovered"

See original GitHub issue

This is about #167 and https://docs.microsoft.com/en-us/aspnet/core/grpc/httpapi?view=aspnetcore-5.0

Given the following proto

syntax = "proto3";

option csharp_namespace = "user_management";

import "google/api/annotations.proto";

service UserListService {
    //List users 
    rpc ListUsers (ListUserRequest) returns (UserList) {
        option (google.api.http) = {
            get: "/v1/users";
        };
    }
}

message ListUserRequest {
    int32 page_size = 1;
    int32 page_nb = 2;
    string order_by = 3;
    
    string name = 4;
}

message UserList {
    int32 total = 1;
    int32 page_nb = 2;
    repeated UserItem data = 3;
}

//Partial details for a user
message UserItem{
	string id = 1;
	string name = 2;
}

I would expect that ListUserRequest is exposed as query parameters

Indeed, calling http://localhost:5000/v1/users?page_size=10&page_nb=1 will correctly submit the parameters to the C# class

However, the generated swagger as explained at https://docs.microsoft.com/en-us/aspnet/core/grpc/httpapi?view=aspnetcore-5.0#enable-swaggeropenapi-support does not contain them

Capture d’écran 2021-10-13 224905

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
christopheblincommented, Oct 15, 2021

@JamesNK thanks for your answer

if there is no way to include them automatically, what is the way to include them explicitly ?

for ex, for post I can do :

option (google.api.http) = {
  post: "/v1/example/echo"
  body: "*"
};

however, there is no such thing for get (at least that I can see)

it seems wrong to do

option (google.api.http) = {
  get: "/v1/example/echo?message={message}"
};

another point (already said in the ticket, sorry for redundancy) is that if I call http://localhost:5000/v1/users?page_size=10&page_nb=1, then it will correctly submit the parameters to the C# class -> why are they not documented in the OpenApi part if I can use them (and because it is a GET, it is the ONLY possible way to use them anyway)

final point, the google docs https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#google.api.HttpRule

Any fields in the request message which are not bound by the path template automatically become HTTP query parameters if there is no HTTP request body.

Hope it helps to make a decision in my favor 😃 😃 😃

0reactions
JamesNKcommented, Dec 27, 2022

This is done in the OpenAPI integration for gRPC JSON transcoding:

https://learn.microsoft.com/en-us/aspnet/core/grpc/json-transcoding-openapi?view=aspnetcore-7.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure HTTP and JSON for gRPC JSON transcoding
gRPC JSON transcoding routes support route parameters. For example, {name} in a route binds to the name field on the request message.
Read more >
gRPC JSON transcoding : using repeated fields in query ...
I'm trying to make a request via Swagger using JSON transcoding, but I'm encountering an error when I use a repeated field parameter...
Read more >
gRPC-JSON transcoder (proto)
(repeated string) A list of query parameters to be ignored for transcoding method mapping. By default, the transcoder filter will not transcode a...
Read more >
Transcoding HTTP/JSON to gRPC - Cloud Endpoints
Transcoding involves mapping HTTP/JSON requests and their parameters to gRPC ... field not bound by the path template should be mapped to the...
Read more >
gRPC JSON Transcoding in .NET 7
With gRPC JSON Transcoding, any application that can issue an HttpRequest can use the service. The application can issue a HTTP/1.1 or an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found