From d297ba4413dda0acc42b1625dbe5435c11690387 Mon Sep 17 00:00:00 2001 From: Nikolay Tretyak Date: Fri, 25 Apr 2025 13:32:01 +0200 Subject: [PATCH 1/2] Fix response_body --- .../clients/responsebody/api/swagger.yaml | 25 +++ .../responsebody/api_response_body_service.go | 99 +++++++++ .../docs/ExamplepbResponseBodyValue.md | 10 + .../docs/ResponseBodyServiceApi.md | 27 +++ .../model_examplepb_response_body_value.go | 14 ++ .../internal/integration/integration_test.go | 23 +++ .../examplepb/response_body_service.pb.go | 188 ++++++++++++------ .../examplepb/response_body_service.pb.gw.go | 113 +++++++++-- .../examplepb/response_body_service.proto | 11 + .../response_body_service.swagger.json | 38 ++++ .../response_body_service_grpc.pb.go | 46 ++++- examples/internal/server/responsebody.go | 6 + .../internal/gengateway/template.go | 3 +- 13 files changed, 525 insertions(+), 78 deletions(-) create mode 100644 examples/internal/clients/responsebody/docs/ExamplepbResponseBodyValue.md create mode 100644 examples/internal/clients/responsebody/model_examplepb_response_body_value.go diff --git a/examples/internal/clients/responsebody/api/swagger.yaml b/examples/internal/clients/responsebody/api/swagger.yaml index 833b9ef524c..42d16be2310 100644 --- a/examples/internal/clients/responsebody/api/swagger.yaml +++ b/examples/internal/clients/responsebody/api/swagger.yaml @@ -32,6 +32,26 @@ paths: description: "An unexpected error response." schema: $ref: "#/definitions/rpcStatus" + /responsebody/samename/{data}: + get: + tags: + - "ResponseBodyService" + operationId: "ResponseBodyService_GetResponseBodySameName" + parameters: + - name: "data" + in: "path" + required: true + type: "string" + x-exportParamName: "Data" + responses: + 200: + description: "" + schema: + type: "string" + default: + description: "An unexpected error response." + schema: + $ref: "#/definitions/rpcStatus" /responsebody/stream/{data}: get: tags: @@ -145,6 +165,11 @@ definitions: type: "string" example: data: "data" + examplepbResponseBodyValue: + type: "object" + properties: + responseBodyValue: + type: "string" protobufAny: type: "object" properties: diff --git a/examples/internal/clients/responsebody/api_response_body_service.go b/examples/internal/clients/responsebody/api_response_body_service.go index 4421adfd82f..6119c3c6567 100644 --- a/examples/internal/clients/responsebody/api_response_body_service.go +++ b/examples/internal/clients/responsebody/api_response_body_service.go @@ -124,6 +124,105 @@ func (a *ResponseBodyServiceApiService) ResponseBodyServiceGetResponseBody(ctx c return localVarReturnValue, localVarHttpResponse, nil } +/* +ResponseBodyServiceApiService + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param data + +@return string +*/ +func (a *ResponseBodyServiceApiService) ResponseBodyServiceGetResponseBodySameName(ctx context.Context, data string) (string, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue string + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/responsebody/samename/{data}" + localVarPath = strings.Replace(localVarPath, "{"+"data"+"}", fmt.Sprintf("%v", data), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + + if localVarHttpResponse.StatusCode == 200 { + var v string + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + + if localVarHttpResponse.StatusCode == 0 { + var v RpcStatus + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} + /* ResponseBodyServiceApiService * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). diff --git a/examples/internal/clients/responsebody/docs/ExamplepbResponseBodyValue.md b/examples/internal/clients/responsebody/docs/ExamplepbResponseBodyValue.md new file mode 100644 index 00000000000..1d55912e981 --- /dev/null +++ b/examples/internal/clients/responsebody/docs/ExamplepbResponseBodyValue.md @@ -0,0 +1,10 @@ +# ExamplepbResponseBodyValue + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ResponseBodyValue** | **string** | | [optional] [default to null] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/examples/internal/clients/responsebody/docs/ResponseBodyServiceApi.md b/examples/internal/clients/responsebody/docs/ResponseBodyServiceApi.md index 852b6c4aaf0..940417257da 100644 --- a/examples/internal/clients/responsebody/docs/ResponseBodyServiceApi.md +++ b/examples/internal/clients/responsebody/docs/ResponseBodyServiceApi.md @@ -5,6 +5,7 @@ All URIs are relative to *https://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- [**ResponseBodyServiceGetResponseBody**](ResponseBodyServiceApi.md#ResponseBodyServiceGetResponseBody) | **Get** /responsebody/{data} | +[**ResponseBodyServiceGetResponseBodySameName**](ResponseBodyServiceApi.md#ResponseBodyServiceGetResponseBodySameName) | **Get** /responsebody/samename/{data} | [**ResponseBodyServiceGetResponseBodyStream**](ResponseBodyServiceApi.md#ResponseBodyServiceGetResponseBodyStream) | **Get** /responsebody/stream/{data} | [**ResponseBodyServiceListResponseBodies**](ResponseBodyServiceApi.md#ResponseBodyServiceListResponseBodies) | **Get** /responsebodies/{data} | [**ResponseBodyServiceListResponseStrings**](ResponseBodyServiceApi.md#ResponseBodyServiceListResponseStrings) | **Get** /responsestrings/{data} | @@ -36,6 +37,32 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **ResponseBodyServiceGetResponseBodySameName** +> string ResponseBodyServiceGetResponseBodySameName(ctx, data) + + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. + **data** | **string**| | + +### Return type + +**string** + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **ResponseBodyServiceGetResponseBodyStream** > StreamResultOfExamplepbResponseBodyOut ResponseBodyServiceGetResponseBodyStream(ctx, data) diff --git a/examples/internal/clients/responsebody/model_examplepb_response_body_value.go b/examples/internal/clients/responsebody/model_examplepb_response_body_value.go new file mode 100644 index 00000000000..037e3bf33c6 --- /dev/null +++ b/examples/internal/clients/responsebody/model_examplepb_response_body_value.go @@ -0,0 +1,14 @@ +/* + * examples/internal/proto/examplepb/response_body_service.proto + * + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * API version: version not set + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package responsebody + +type ExamplepbResponseBodyValue struct { + ResponseBodyValue string `json:"responseBodyValue,omitempty"` +} diff --git a/examples/internal/integration/integration_test.go b/examples/internal/integration/integration_test.go index 51a4a9e8aff..2613ffd003d 100644 --- a/examples/internal/integration/integration_test.go +++ b/examples/internal/integration/integration_test.go @@ -1817,6 +1817,29 @@ func testResponseBody(t *testing.T, port int) { } } +func TestResponseBodySameName(t *testing.T) { + apiURL := "http://localhost:8088/responsebody/samename/foo" + resp, err := http.Get(apiURL) + if err != nil { + t.Fatalf("http.Get(%q) failed with %v; want success", apiURL, err) + } + + defer resp.Body.Close() + buf, err := io.ReadAll(resp.Body) + if err != nil { + t.Fatalf("io.ReadAll(resp.Body) failed with %v; want success", err) + } + + if got, want := resp.StatusCode, http.StatusOK; got != want { + t.Errorf("resp.StatusCode = %d; want %d", got, want) + t.Logf("%s", buf) + } + + if diff := cmp.Diff(string(buf), `"foo"`); diff != "" { + t.Error(diff) + } +} + func TestResponseBodyStream(t *testing.T) { apiURL := "http://localhost:8088/responsebody/stream/foo" resp, err := http.Get(apiURL) diff --git a/examples/internal/proto/examplepb/response_body_service.pb.go b/examples/internal/proto/examplepb/response_body_service.pb.go index 09ce45a757e..fa96715acf2 100644 --- a/examples/internal/proto/examplepb/response_body_service.pb.go +++ b/examples/internal/proto/examplepb/response_body_service.pb.go @@ -253,6 +253,51 @@ func (x *RepeatedResponseStrings) GetValues() []string { return nil } +type ResponseBodyValue struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ResponseBodyValue string `protobuf:"bytes,1,opt,name=response_body_value,json=responseBodyValue,proto3" json:"response_body_value,omitempty"` +} + +func (x *ResponseBodyValue) Reset() { + *x = ResponseBodyValue{} + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ResponseBodyValue) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ResponseBodyValue) ProtoMessage() {} + +func (x *ResponseBodyValue) ProtoReflect() protoreflect.Message { + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ResponseBodyValue.ProtoReflect.Descriptor instead. +func (*ResponseBodyValue) Descriptor() ([]byte, []int) { + return file_examples_internal_proto_examplepb_response_body_service_proto_rawDescGZIP(), []int{4} +} + +func (x *ResponseBodyValue) GetResponseBodyValue() string { + if x != nil { + return x.ResponseBodyValue + } + return "" +} + type ResponseBodyOut_Response struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -263,7 +308,7 @@ type ResponseBodyOut_Response struct { func (x *ResponseBodyOut_Response) Reset() { *x = ResponseBodyOut_Response{} - mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[4] + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -275,7 +320,7 @@ func (x *ResponseBodyOut_Response) String() string { func (*ResponseBodyOut_Response) ProtoMessage() {} func (x *ResponseBodyOut_Response) ProtoReflect() protoreflect.Message { - mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[4] + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -309,7 +354,7 @@ type RepeatedResponseBodyOut_Response struct { func (x *RepeatedResponseBodyOut_Response) Reset() { *x = RepeatedResponseBodyOut_Response{} - mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[5] + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -321,7 +366,7 @@ func (x *RepeatedResponseBodyOut_Response) String() string { func (*RepeatedResponseBodyOut_Response) ProtoMessage() {} func (x *RepeatedResponseBodyOut_Response) ProtoReflect() protoreflect.Message { - mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[5] + mi := &file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -398,22 +443,39 @@ var file_examples_internal_proto_examplepb_response_body_service_proto_rawDesc = 0x05, 0x0a, 0x01, 0x42, 0x10, 0x02, 0x22, 0x31, 0x0a, 0x17, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x32, 0xb2, 0x06, 0x0a, 0x13, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0xba, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, - 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x6f, 0x64, 0x79, 0x49, 0x6e, 0x1a, 0x3f, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, - 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x6f, 0x64, 0x79, 0x4f, 0x75, 0x74, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x62, 0x08, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x12, 0xc7, - 0x01, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x6f, 0x64, 0x69, 0x65, 0x73, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, + 0x09, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x43, 0x0a, 0x11, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2e, + 0x0a, 0x13, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x5f, 0x62, 0x6f, 0x64, 0x79, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x8d, + 0x08, 0x0a, 0x13, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xba, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, 0x6e, 0x1a, 0x3f, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x4f, 0x75, 0x74, 0x22, 0x26, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x20, 0x62, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x2f, + 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x2f, 0x7b, 0x64, 0x61, + 0x74, 0x61, 0x7d, 0x12, 0xc7, 0x01, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x69, 0x65, 0x73, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, 0x6e, 0x1a, 0x47, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x70, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, + 0x4f, 0x75, 0x74, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x62, 0x08, 0x72, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x62, 0x6f, 0x64, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x12, 0xc7, 0x01, + 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, @@ -421,35 +483,36 @@ var file_examples_internal_proto_examplepb_response_body_service_proto_rawDesc = 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x4f, 0x75, 0x74, 0x22, 0x28, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x62, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x16, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x6f, 0x64, 0x69, 0x65, - 0x73, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x12, 0xc7, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, - 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, - 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, 0x6e, - 0x1a, 0x47, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, - 0x62, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x21, 0x62, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x12, 0x17, 0x2f, 0x72, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x2f, 0x7b, 0x64, 0x61, 0x74, - 0x61, 0x7d, 0x12, 0xc9, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x3e, 0x2e, 0x67, - 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, 0x6e, 0x1a, 0x3f, 0x2e, 0x67, - 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x4f, 0x75, 0x74, 0x22, 0x2d, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x62, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x1b, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x2f, 0x73, - 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x30, 0x01, 0x42, 0x4d, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x22, 0x27, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x62, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x12, 0x17, + 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, + 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x12, 0xc9, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x74, 0x72, 0x65, 0x61, + 0x6d, 0x12, 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, + 0x6e, 0x1a, 0x3f, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x4f, + 0x75, 0x74, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x62, 0x08, 0x72, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, + 0x6f, 0x64, 0x79, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, + 0x7d, 0x30, 0x01, 0x12, 0xd8, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x61, 0x6d, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x3e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, + 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, + 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x49, 0x6e, 0x1a, + 0x41, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x65, + 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, + 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x64, 0x79, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x22, 0x3a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x34, 0x62, 0x13, 0x72, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x5f, 0x62, 0x6f, 0x64, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, + 0x1d, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x2f, 0x73, + 0x61, 0x6d, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x2f, 0x7b, 0x64, 0x61, 0x74, 0x61, 0x7d, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x65, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x76, 0x32, 0x2f, 0x65, 0x78, 0x61, 0x6d, @@ -471,30 +534,33 @@ func file_examples_internal_proto_examplepb_response_body_service_proto_rawDescG } var file_examples_internal_proto_examplepb_response_body_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_examples_internal_proto_examplepb_response_body_service_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_examples_internal_proto_examplepb_response_body_service_proto_goTypes = []any{ (RepeatedResponseBodyOut_Response_ResponseType)(0), // 0: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response.ResponseType (*ResponseBodyIn)(nil), // 1: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn (*ResponseBodyOut)(nil), // 2: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut (*RepeatedResponseBodyOut)(nil), // 3: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut (*RepeatedResponseStrings)(nil), // 4: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseStrings - (*ResponseBodyOut_Response)(nil), // 5: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.Response - (*RepeatedResponseBodyOut_Response)(nil), // 6: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response + (*ResponseBodyValue)(nil), // 5: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyValue + (*ResponseBodyOut_Response)(nil), // 6: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.Response + (*RepeatedResponseBodyOut_Response)(nil), // 7: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response } var file_examples_internal_proto_examplepb_response_body_service_proto_depIdxs = []int32{ - 5, // 0: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.response:type_name -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.Response - 6, // 1: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.response:type_name -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response + 6, // 0: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.response:type_name -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut.Response + 7, // 1: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.response:type_name -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response 0, // 2: grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response.type:type_name -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut.Response.ResponseType 1, // 3: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBody:input_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn 1, // 4: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseBodies:input_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn 1, // 5: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseStrings:input_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn 1, // 6: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBodyStream:input_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn - 2, // 7: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBody:output_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut - 3, // 8: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseBodies:output_type -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut - 4, // 9: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseStrings:output_type -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseStrings - 2, // 10: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBodyStream:output_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut - 7, // [7:11] is the sub-list for method output_type - 3, // [3:7] is the sub-list for method input_type + 1, // 7: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBodySameName:input_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyIn + 2, // 8: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBody:output_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut + 3, // 9: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseBodies:output_type -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseBodyOut + 4, // 10: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.ListResponseStrings:output_type -> grpc.gateway.examples.internal.proto.examplepb.RepeatedResponseStrings + 2, // 11: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBodyStream:output_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyOut + 5, // 12: grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService.GetResponseBodySameName:output_type -> grpc.gateway.examples.internal.proto.examplepb.ResponseBodyValue + 8, // [8:13] is the sub-list for method output_type + 3, // [3:8] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name @@ -511,7 +577,7 @@ func file_examples_internal_proto_examplepb_response_body_service_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_examples_internal_proto_examplepb_response_body_service_proto_rawDesc, NumEnums: 1, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 1, }, diff --git a/examples/internal/proto/examplepb/response_body_service.pb.gw.go b/examples/internal/proto/examplepb/response_body_service.pb.gw.go index 27f81845811..a2c786fa265 100644 --- a/examples/internal/proto/examplepb/response_body_service.pb.gw.go +++ b/examples/internal/proto/examplepb/response_body_service.pb.gw.go @@ -173,6 +173,43 @@ func request_ResponseBodyService_GetResponseBodyStream_0(ctx context.Context, ma return stream, metadata, nil } +func request_ResponseBodyService_GetResponseBodySameName_0(ctx context.Context, marshaler runtime.Marshaler, client ResponseBodyServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ResponseBodyIn + metadata runtime.ServerMetadata + err error + ) + io.Copy(io.Discard, req.Body) + val, ok := pathParams["data"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "data") + } + protoReq.Data, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "data", err) + } + msg, err := client.GetResponseBodySameName(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_ResponseBodyService_GetResponseBodySameName_0(ctx context.Context, marshaler runtime.Marshaler, server ResponseBodyServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ResponseBodyIn + metadata runtime.ServerMetadata + err error + ) + val, ok := pathParams["data"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "data") + } + protoReq.Data, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "data", err) + } + msg, err := server.GetResponseBodySameName(ctx, &protoReq) + return msg, metadata, err +} + // RegisterResponseBodyServiceHandlerServer registers the http handlers for service ResponseBodyService to "mux". // UnaryRPC :call ResponseBodyServiceServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -246,6 +283,26 @@ func RegisterResponseBodyServiceHandlerServer(ctx context.Context, mux *runtime. runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return }) + mux.Handle(http.MethodGet, pattern_ResponseBodyService_GetResponseBodySameName_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBodySameName", runtime.WithHTTPPathPattern("/responsebody/samename/{data}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ResponseBodyService_GetResponseBodySameName_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_ResponseBodyService_GetResponseBodySameName_0(annotatedContext, mux, outboundMarshaler, w, req, response_ResponseBodyService_GetResponseBodySameName_0{resp.(*ResponseBodyValue)}, mux.GetForwardResponseOptions()...) + }) return nil } @@ -357,6 +414,23 @@ func RegisterResponseBodyServiceHandlerClient(ctx context.Context, mux *runtime. return response_ResponseBodyService_GetResponseBodyStream_0{res}, err }, mux.GetForwardResponseOptions()...) }) + mux.Handle(http.MethodGet, pattern_ResponseBodyService_GetResponseBodySameName_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBodySameName", runtime.WithHTTPPathPattern("/responsebody/samename/{data}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ResponseBodyService_GetResponseBodySameName_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_ResponseBodyService_GetResponseBodySameName_0(annotatedContext, mux, outboundMarshaler, w, req, response_ResponseBodyService_GetResponseBodySameName_0{resp.(*ResponseBodyValue)}, mux.GetForwardResponseOptions()...) + }) return nil } @@ -365,7 +439,8 @@ type response_ResponseBodyService_GetResponseBody_0 struct { } func (m response_ResponseBodyService_GetResponseBody_0) XXX_ResponseBody() interface{} { - return m.Response + response := m.ResponseBodyOut + return response.Response } type response_ResponseBodyService_ListResponseBodies_0 struct { @@ -373,7 +448,8 @@ type response_ResponseBodyService_ListResponseBodies_0 struct { } func (m response_ResponseBodyService_ListResponseBodies_0) XXX_ResponseBody() interface{} { - return m.Response + response := m.RepeatedResponseBodyOut + return response.Response } type response_ResponseBodyService_ListResponseStrings_0 struct { @@ -381,7 +457,8 @@ type response_ResponseBodyService_ListResponseStrings_0 struct { } func (m response_ResponseBodyService_ListResponseStrings_0) XXX_ResponseBody() interface{} { - return m.Values + response := m.RepeatedResponseStrings + return response.Values } type response_ResponseBodyService_GetResponseBodyStream_0 struct { @@ -389,19 +466,31 @@ type response_ResponseBodyService_GetResponseBodyStream_0 struct { } func (m response_ResponseBodyService_GetResponseBodyStream_0) XXX_ResponseBody() interface{} { - return m.Response + response := m.ResponseBodyOut + return response.Response +} + +type response_ResponseBodyService_GetResponseBodySameName_0 struct { + *ResponseBodyValue +} + +func (m response_ResponseBodyService_GetResponseBodySameName_0) XXX_ResponseBody() interface{} { + response := m.ResponseBodyValue + return response.ResponseBodyValue } var ( - pattern_ResponseBodyService_GetResponseBody_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsebody", "data"}, "")) - pattern_ResponseBodyService_ListResponseBodies_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsebodies", "data"}, "")) - pattern_ResponseBodyService_ListResponseStrings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsestrings", "data"}, "")) - pattern_ResponseBodyService_GetResponseBodyStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"responsebody", "stream", "data"}, "")) + pattern_ResponseBodyService_GetResponseBody_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsebody", "data"}, "")) + pattern_ResponseBodyService_ListResponseBodies_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsebodies", "data"}, "")) + pattern_ResponseBodyService_ListResponseStrings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"responsestrings", "data"}, "")) + pattern_ResponseBodyService_GetResponseBodyStream_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"responsebody", "stream", "data"}, "")) + pattern_ResponseBodyService_GetResponseBodySameName_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"responsebody", "samename", "data"}, "")) ) var ( - forward_ResponseBodyService_GetResponseBody_0 = runtime.ForwardResponseMessage - forward_ResponseBodyService_ListResponseBodies_0 = runtime.ForwardResponseMessage - forward_ResponseBodyService_ListResponseStrings_0 = runtime.ForwardResponseMessage - forward_ResponseBodyService_GetResponseBodyStream_0 = runtime.ForwardResponseStream + forward_ResponseBodyService_GetResponseBody_0 = runtime.ForwardResponseMessage + forward_ResponseBodyService_ListResponseBodies_0 = runtime.ForwardResponseMessage + forward_ResponseBodyService_ListResponseStrings_0 = runtime.ForwardResponseMessage + forward_ResponseBodyService_GetResponseBodyStream_0 = runtime.ForwardResponseStream + forward_ResponseBodyService_GetResponseBodySameName_0 = runtime.ForwardResponseMessage ) diff --git a/examples/internal/proto/examplepb/response_body_service.proto b/examples/internal/proto/examplepb/response_body_service.proto index 31480f8341d..5e099103573 100644 --- a/examples/internal/proto/examplepb/response_body_service.proto +++ b/examples/internal/proto/examplepb/response_body_service.proto @@ -37,6 +37,10 @@ message RepeatedResponseStrings { repeated string values = 1; } +message ResponseBodyValue { + string response_body_value = 1; +} + service ResponseBodyService { rpc GetResponseBody(ResponseBodyIn) returns (ResponseBodyOut) { option (google.api.http) = { @@ -63,4 +67,11 @@ service ResponseBodyService { response_body: "response" }; } + + rpc GetResponseBodySameName(ResponseBodyIn) returns (ResponseBodyValue) { + option (google.api.http) = { + get: "/responsebody/samename/{data}" + response_body: "response_body_value" + }; + } } diff --git a/examples/internal/proto/examplepb/response_body_service.swagger.json b/examples/internal/proto/examplepb/response_body_service.swagger.json index 034ce969375..9fa0c95b2c8 100644 --- a/examples/internal/proto/examplepb/response_body_service.swagger.json +++ b/examples/internal/proto/examplepb/response_body_service.swagger.json @@ -50,6 +50,36 @@ ] } }, + "/responsebody/samename/{data}": { + "get": { + "operationId": "ResponseBodyService_GetResponseBodySameName", + "responses": { + "200": { + "description": "", + "schema": { + "type": "string" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "data", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "ResponseBodyService" + ] + } + }, "/responsebody/stream/{data}": { "get": { "operationId": "ResponseBodyService_GetResponseBodyStream", @@ -214,6 +244,14 @@ } } }, + "examplepbResponseBodyValue": { + "type": "object", + "properties": { + "responseBodyValue": { + "type": "string" + } + } + }, "protobufAny": { "type": "object", "properties": { diff --git a/examples/internal/proto/examplepb/response_body_service_grpc.pb.go b/examples/internal/proto/examplepb/response_body_service_grpc.pb.go index e78eb738343..c3cf7fa469c 100644 --- a/examples/internal/proto/examplepb/response_body_service_grpc.pb.go +++ b/examples/internal/proto/examplepb/response_body_service_grpc.pb.go @@ -19,10 +19,11 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - ResponseBodyService_GetResponseBody_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBody" - ResponseBodyService_ListResponseBodies_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/ListResponseBodies" - ResponseBodyService_ListResponseStrings_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/ListResponseStrings" - ResponseBodyService_GetResponseBodyStream_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBodyStream" + ResponseBodyService_GetResponseBody_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBody" + ResponseBodyService_ListResponseBodies_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/ListResponseBodies" + ResponseBodyService_ListResponseStrings_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/ListResponseStrings" + ResponseBodyService_GetResponseBodyStream_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBodyStream" + ResponseBodyService_GetResponseBodySameName_FullMethodName = "/grpc.gateway.examples.internal.proto.examplepb.ResponseBodyService/GetResponseBodySameName" ) // ResponseBodyServiceClient is the client API for ResponseBodyService service. @@ -33,6 +34,7 @@ type ResponseBodyServiceClient interface { ListResponseBodies(ctx context.Context, in *ResponseBodyIn, opts ...grpc.CallOption) (*RepeatedResponseBodyOut, error) ListResponseStrings(ctx context.Context, in *ResponseBodyIn, opts ...grpc.CallOption) (*RepeatedResponseStrings, error) GetResponseBodyStream(ctx context.Context, in *ResponseBodyIn, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ResponseBodyOut], error) + GetResponseBodySameName(ctx context.Context, in *ResponseBodyIn, opts ...grpc.CallOption) (*ResponseBodyValue, error) } type responseBodyServiceClient struct { @@ -92,6 +94,16 @@ func (c *responseBodyServiceClient) GetResponseBodyStream(ctx context.Context, i // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. type ResponseBodyService_GetResponseBodyStreamClient = grpc.ServerStreamingClient[ResponseBodyOut] +func (c *responseBodyServiceClient) GetResponseBodySameName(ctx context.Context, in *ResponseBodyIn, opts ...grpc.CallOption) (*ResponseBodyValue, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ResponseBodyValue) + err := c.cc.Invoke(ctx, ResponseBodyService_GetResponseBodySameName_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ResponseBodyServiceServer is the server API for ResponseBodyService service. // All implementations should embed UnimplementedResponseBodyServiceServer // for forward compatibility. @@ -100,6 +112,7 @@ type ResponseBodyServiceServer interface { ListResponseBodies(context.Context, *ResponseBodyIn) (*RepeatedResponseBodyOut, error) ListResponseStrings(context.Context, *ResponseBodyIn) (*RepeatedResponseStrings, error) GetResponseBodyStream(*ResponseBodyIn, grpc.ServerStreamingServer[ResponseBodyOut]) error + GetResponseBodySameName(context.Context, *ResponseBodyIn) (*ResponseBodyValue, error) } // UnimplementedResponseBodyServiceServer should be embedded to have @@ -121,6 +134,9 @@ func (UnimplementedResponseBodyServiceServer) ListResponseStrings(context.Contex func (UnimplementedResponseBodyServiceServer) GetResponseBodyStream(*ResponseBodyIn, grpc.ServerStreamingServer[ResponseBodyOut]) error { return status.Errorf(codes.Unimplemented, "method GetResponseBodyStream not implemented") } +func (UnimplementedResponseBodyServiceServer) GetResponseBodySameName(context.Context, *ResponseBodyIn) (*ResponseBodyValue, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetResponseBodySameName not implemented") +} func (UnimplementedResponseBodyServiceServer) testEmbeddedByValue() {} // UnsafeResponseBodyServiceServer may be embedded to opt out of forward compatibility for this service. @@ -206,6 +222,24 @@ func _ResponseBodyService_GetResponseBodyStream_Handler(srv interface{}, stream // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. type ResponseBodyService_GetResponseBodyStreamServer = grpc.ServerStreamingServer[ResponseBodyOut] +func _ResponseBodyService_GetResponseBodySameName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ResponseBodyIn) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ResponseBodyServiceServer).GetResponseBodySameName(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ResponseBodyService_GetResponseBodySameName_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ResponseBodyServiceServer).GetResponseBodySameName(ctx, req.(*ResponseBodyIn)) + } + return interceptor(ctx, in, info, handler) +} + // ResponseBodyService_ServiceDesc is the grpc.ServiceDesc for ResponseBodyService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -225,6 +259,10 @@ var ResponseBodyService_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListResponseStrings", Handler: _ResponseBodyService_ListResponseStrings_Handler, }, + { + MethodName: "GetResponseBodySameName", + Handler: _ResponseBodyService_GetResponseBodySameName_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/examples/internal/server/responsebody.go b/examples/internal/server/responsebody.go index d661684f436..59408bfc705 100644 --- a/examples/internal/server/responsebody.go +++ b/examples/internal/server/responsebody.go @@ -59,3 +59,9 @@ func (s *responseBodyServer) GetResponseBodyStream(req *examples.ResponseBodyIn, }, }) } + +func (s *responseBodyServer) GetResponseBodySameName(ctx context.Context, req *examples.ResponseBodyIn) (*examples.ResponseBodyValue, error) { + return &examples.ResponseBodyValue{ + ResponseBodyValue: req.Data, + }, nil +} diff --git a/protoc-gen-grpc-gateway/internal/gengateway/template.go b/protoc-gen-grpc-gateway/internal/gengateway/template.go index e9f3599d87e..a41c9aa6e6f 100644 --- a/protoc-gen-grpc-gateway/internal/gengateway/template.go +++ b/protoc-gen-grpc-gateway/internal/gengateway/template.go @@ -775,7 +775,8 @@ type response_{{ $svc.GetName }}_{{ $m.GetName }}_{{ $b.Index }} struct { } func (m response_{{ $svc.GetName }}_{{ $m.GetName }}_{{ $b.Index }}) XXX_ResponseBody() interface{} { - return {{ $b.ResponseBody.AssignableExpr "m" $m.Service.File.GoPkg.Path }} + response := m.{{ $m.ResponseType.GoType $m.Service.File.GoPkg.Path }} + return {{ $b.ResponseBody.AssignableExpr "response" $m.Service.File.GoPkg.Path }} } {{ end }} {{ end }} From 1bc71cebaa33213049c139d822a9ae78d4a045e7 Mon Sep 17 00:00:00 2001 From: Nikolay Tretyak Date: Mon, 5 May 2025 12:18:07 +0200 Subject: [PATCH 2/2] generate --- examples/internal/clients/responsebody/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/internal/clients/responsebody/BUILD.bazel b/examples/internal/clients/responsebody/BUILD.bazel index 9d76d60e947..61245093c64 100644 --- a/examples/internal/clients/responsebody/BUILD.bazel +++ b/examples/internal/clients/responsebody/BUILD.bazel @@ -11,6 +11,7 @@ go_library( "model_examplepb_repeated_response_strings.go", "model_examplepb_response_body_out.go", "model_examplepb_response_body_out_response.go", + "model_examplepb_response_body_value.go", "model_protobuf_any.go", "model_response_response_type.go", "model_rpc_status.go",