-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to ignore
json_name
in HTTP/JSON transcoding
Motivation: There is a bug in protoc that always adds json_name to the descriptor. This happens by default when compiling proto files in Bazel. To mitigate this bug, I propose to add `HttpJsonTranscodingQueryParamMatchRule.IGORE_JSON` to forcibliy ignore json_name when matching query params or path variables. Modifications: - Add `HttpJsonTranscodingQueryParamMatchRule.INGORE_JSON` - If enabled, the `json_name` field option is ignored. Result: - Fixes #5890 - You can now ignore the `json_name` field option when trancoding HTTP/JSON to gRPC messages.
- Loading branch information
Showing
16 changed files
with
1,675 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
implementation project(':grpc') | ||
testImplementation libs.javax.annotation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
syntax = "proto3"; | ||
|
||
package hello.v1; | ||
option java_package = "testing.grpc.jsonname"; | ||
|
||
option java_multiple_files = true; | ||
|
||
message HelloRequest { | ||
string name_input = 1; | ||
} | ||
|
||
message HelloReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
package hello.service.v1; | ||
|
||
import "hello/v1/hello.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
option java_package = "testing.grpc.jsonname"; | ||
option java_multiple_files = true; | ||
|
||
|
||
service HelloService { | ||
rpc Hello (hello.v1.HelloRequest) returns (hello.v1.HelloReply){ | ||
option (google.api.http) = { | ||
get: "/v1/hello/{name_input}" | ||
}; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
.../src/test/java/com/linecorp/armeria/server/grpc/jsonname/GrpcTranscodingJsonNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2025 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.server.grpc.jsonname; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.linecorp.armeria.client.BlockingWebClient; | ||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.server.ServerBuilder; | ||
import com.linecorp.armeria.server.grpc.GrpcService; | ||
import com.linecorp.armeria.server.grpc.HttpJsonTranscodingOptions; | ||
import com.linecorp.armeria.server.grpc.HttpJsonTranscodingQueryParamMatchRule; | ||
import com.linecorp.armeria.testing.junit5.server.ServerExtension; | ||
|
||
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class GrpcTranscodingJsonNameTest { | ||
|
||
@RegisterExtension | ||
static ServerExtension server = new ServerExtension() { | ||
@Override | ||
protected void configure(ServerBuilder sb) { | ||
final HttpJsonTranscodingOptions options = | ||
HttpJsonTranscodingOptions.builder() | ||
.queryParamMatchRules( | ||
HttpJsonTranscodingQueryParamMatchRule.IGNORE_JSON_NAME) | ||
.build(); | ||
final GrpcService grpcService = GrpcService.builder() | ||
.addService(new HelloService()) | ||
.enableHttpJsonTranscoding(options) | ||
.build(); | ||
sb.service(grpcService); | ||
} | ||
}; | ||
|
||
@Test | ||
void shouldIgnoreJsonNameOption() { | ||
final BlockingWebClient client = server.blockingWebClient(); | ||
final AggregatedHttpResponse response = client.get("/v1/hello/Armeria"); | ||
assertThat(response.status()).isEqualTo(HttpStatus.OK); | ||
assertThatJson(response.contentUtf8()) | ||
.isEqualTo("{\"message\":\"Hello, Armeria!\"}"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
it/grpc-json-name/src/test/java/com/linecorp/armeria/server/grpc/jsonname/HelloService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.linecorp.armeria.server.grpc.jsonname; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import testing.grpc.jsonname.HelloReply; | ||
import testing.grpc.jsonname.HelloRequest; | ||
import testing.grpc.jsonname.HelloServiceGrpc; | ||
|
||
public class HelloService extends HelloServiceGrpc.HelloServiceImplBase { | ||
|
||
@Override | ||
public void hello(HelloRequest req, StreamObserver<HelloReply> responseObserver) { | ||
HelloReply reply = HelloReply.newBuilder() | ||
.setMessage("Hello, " + req.getNameInput() + '!') | ||
.build(); | ||
responseObserver.onNext(reply); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
it/grpc-json-name/src/test/java/testing/grpc/jsonname/Hello.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.