diff --git a/examples/internal/clients/abe/BUILD.bazel b/examples/internal/clients/abe/BUILD.bazel index 9c2e6553c11..cfddbceac15 100644 --- a/examples/internal/clients/abe/BUILD.bazel +++ b/examples/internal/clients/abe/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "model_pathenum_path_enum.go", "model_protobuf_any.go", "model_protobuf_field_mask.go", - "model_runtime_error.go", + "model_rpc_status.go", "model_sub_string_message.go", "response.go", ], diff --git a/examples/internal/clients/abe/api/swagger.yaml b/examples/internal/clients/abe/api/swagger.yaml index 742056db6f6..5bae500ca54 100644 --- a/examples/internal/clients/abe/api/swagger.yaml +++ b/examples/internal/clients/abe/api/swagger.yaml @@ -62,7 +62,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/echo/{value}: get: tags: @@ -104,7 +104,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" externalDocs: description: "Find out more Echo" url: "https://github.com/grpc-ecosystem/grpc-gateway" @@ -395,7 +395,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/params/get/{single_nested.name}: get: tags: @@ -690,7 +690,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/params/post/{string_value}: post: tags: @@ -729,7 +729,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/query/{uuid}: get: tags: @@ -1030,7 +1030,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" security: [] externalDocs: description: "Find out more about GetQuery" @@ -1188,7 +1188,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/{single_nested.name}: post: tags: @@ -1228,7 +1228,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/a_bit_of_everything/{uuid}: get: tags: @@ -1261,7 +1261,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" put: tags: - "ABitOfEverythingService" @@ -1298,7 +1298,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" delete: tags: - "ABitOfEverythingService" @@ -1329,7 +1329,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" security: - ApiKeyAuth: [] OAuth2: @@ -1526,7 +1526,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/a_bit_of_everything/{abe.uuid}: put: tags: @@ -1564,7 +1564,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" patch: tags: - "ABitOfEverythingService" @@ -1601,7 +1601,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/echo: get: tags: @@ -1644,7 +1644,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" externalDocs: description: "Find out more Echo" url: "https://github.com/grpc-ecosystem/grpc-gateway" @@ -1689,7 +1689,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" externalDocs: description: "Find out more Echo" url: "https://github.com/grpc-ecosystem/grpc-gateway" @@ -1719,7 +1719,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/errorwithdetails: get: tags: @@ -1746,7 +1746,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/overwriteresponsecontenttype: get: tags: @@ -1776,7 +1776,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/postwithemptybody/{name}: post: tags: @@ -1814,7 +1814,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/timeout: get: tags: @@ -1841,7 +1841,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2/example/withbody/{id}: post: tags: @@ -1879,7 +1879,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v2a/example/a_bit_of_everything/{abe.uuid}: patch: tags: @@ -1917,7 +1917,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" securityDefinitions: ApiKeyAuth: type: "apiKey" @@ -2369,11 +2369,9 @@ definitions: \ API method which has a FieldMask type field in the\nrequest should verify\ \ the included field paths, and return an\n`INVALID_ARGUMENT` error if any path\ \ is duplicated or unmappable." - runtimeError: + rpcStatus: type: "object" properties: - error: - type: "string" code: type: "integer" format: "int32" diff --git a/examples/internal/clients/abe/api_a_bit_of_everything_service.go b/examples/internal/clients/abe/api_a_bit_of_everything_service.go index 419a2454a4a..e7b1f563612 100644 --- a/examples/internal/clients/abe/api_a_bit_of_everything_service.go +++ b/examples/internal/clients/abe/api_a_bit_of_everything_service.go @@ -318,7 +318,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCheckGetQuery } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -625,7 +625,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCheckNestedEn } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -773,7 +773,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCheckPostQuer } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -955,7 +955,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreate(ctx co } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1101,7 +1101,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreateBody(ct } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1249,7 +1249,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceDeepPathEcho( } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1394,7 +1394,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceDelete(ctx co } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1537,7 +1537,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceErrorWithDeta } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1685,7 +1685,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceGetMessageWit } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -1984,7 +1984,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceGetQuery(ctx } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2207,7 +2207,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceGetRepeatedQu } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2352,7 +2352,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceLookup(ctx co } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2495,7 +2495,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceOverwriteResp } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2643,7 +2643,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServicePostWithEmpty } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2786,7 +2786,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceTimeout(ctx c } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -2934,7 +2934,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdate(ctx co } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -3082,7 +3082,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV2(ctx } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -3230,7 +3230,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV22(ctx } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -3378,7 +3378,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV23(ctx } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/abe/api_camel_case_service_name.go b/examples/internal/clients/abe/api_camel_case_service_name.go index c7a4a7707e3..9a71f70e61e 100644 --- a/examples/internal/clients/abe/api_camel_case_service_name.go +++ b/examples/internal/clients/abe/api_camel_case_service_name.go @@ -152,7 +152,7 @@ func (a *CamelCaseServiceNameApiService) CamelCaseServiceNameEmpty(ctx context.C } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/abe/api_echo_rpc.go b/examples/internal/clients/abe/api_echo_rpc.go index 8e1f06d5ad8..3abd88ac7f4 100644 --- a/examples/internal/clients/abe/api_echo_rpc.go +++ b/examples/internal/clients/abe/api_echo_rpc.go @@ -168,7 +168,7 @@ func (a *EchoRpcApiService) ABitOfEverythingServiceEcho(ctx context.Context, val } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -326,7 +326,7 @@ func (a *EchoRpcApiService) ABitOfEverythingServiceEcho2(ctx context.Context, bo } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -491,7 +491,7 @@ func (a *EchoRpcApiService) ABitOfEverythingServiceEcho3(ctx context.Context, lo } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/abe/model_runtime_error.go b/examples/internal/clients/abe/model_rpc_status.go similarity index 86% rename from examples/internal/clients/abe/model_runtime_error.go rename to examples/internal/clients/abe/model_rpc_status.go index 9674e976dc7..840daffba2c 100644 --- a/examples/internal/clients/abe/model_runtime_error.go +++ b/examples/internal/clients/abe/model_rpc_status.go @@ -10,8 +10,7 @@ package abe -type RuntimeError struct { - Error_ string `json:"error,omitempty"` +type RpcStatus struct { Code int32 `json:"code,omitempty"` Message string `json:"message,omitempty"` Details []ProtobufAny `json:"details,omitempty"` diff --git a/examples/internal/clients/echo/BUILD.bazel b/examples/internal/clients/echo/BUILD.bazel index 7fd6b4f37b8..0b2e672c5b3 100644 --- a/examples/internal/clients/echo/BUILD.bazel +++ b/examples/internal/clients/echo/BUILD.bazel @@ -11,7 +11,7 @@ go_library( "model_examplepb_embedded.go", "model_examplepb_simple_message.go", "model_protobuf_any.go", - "model_runtime_error.go", + "model_rpc_status.go", "response.go", ], importpath = "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/clients/echo", diff --git a/examples/internal/clients/echo/api/swagger.yaml b/examples/internal/clients/echo/api/swagger.yaml index 2df4be32a99..193d9301b5a 100644 --- a/examples/internal/clients/echo/api/swagger.yaml +++ b/examples/internal/clients/echo/api/swagger.yaml @@ -31,7 +31,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo/{id}/{num}: get: tags: @@ -106,7 +106,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo/{id}/{num}/{lang}: get: tags: @@ -180,7 +180,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo1/{id}/{line_num}/{status.note}: get: tags: @@ -248,7 +248,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo2/{no.note}: get: tags: @@ -318,7 +318,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo_body: post: tags: @@ -340,7 +340,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo_delete: delete: tags: @@ -416,7 +416,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" definitions: examplepbEmbedded: type: "object" @@ -522,11 +522,9 @@ definitions: \ custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\ \n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n\ \ \"value\": \"1.212s\"\n }" - runtimeError: + rpcStatus: type: "object" properties: - error: - type: "string" code: type: "integer" format: "int32" diff --git a/examples/internal/clients/echo/api_echo_service.go b/examples/internal/clients/echo/api_echo_service.go index b4eeb7dd655..b3aad8bcd2c 100644 --- a/examples/internal/clients/echo/api_echo_service.go +++ b/examples/internal/clients/echo/api_echo_service.go @@ -110,7 +110,7 @@ func (a *EchoServiceApiService) EchoServiceEcho(ctx context.Context, id string) } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -252,7 +252,7 @@ func (a *EchoServiceApiService) EchoServiceEcho2(ctx context.Context, id string, } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -391,7 +391,7 @@ func (a *EchoServiceApiService) EchoServiceEcho3(ctx context.Context, id string, } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -525,7 +525,7 @@ func (a *EchoServiceApiService) EchoServiceEcho4(ctx context.Context, id string, } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -665,7 +665,7 @@ func (a *EchoServiceApiService) EchoServiceEcho5(ctx context.Context, noNote str } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -765,7 +765,7 @@ func (a *EchoServiceApiService) EchoServiceEchoBody(ctx context.Context, body Ex } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -912,7 +912,7 @@ func (a *EchoServiceApiService) EchoServiceEchoDelete(ctx context.Context, local } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/echo/model_runtime_error.go b/examples/internal/clients/echo/model_rpc_status.go similarity index 84% rename from examples/internal/clients/echo/model_runtime_error.go rename to examples/internal/clients/echo/model_rpc_status.go index 836afd7ac6b..f6a4b0e21ca 100644 --- a/examples/internal/clients/echo/model_runtime_error.go +++ b/examples/internal/clients/echo/model_rpc_status.go @@ -9,8 +9,7 @@ package echo -type RuntimeError struct { - Error_ string `json:"error,omitempty"` +type RpcStatus struct { Code int32 `json:"code,omitempty"` Message string `json:"message,omitempty"` Details []ProtobufAny `json:"details,omitempty"` diff --git a/examples/internal/clients/responsebody/BUILD.bazel b/examples/internal/clients/responsebody/BUILD.bazel index 911f72d0ffd..bfa8990254a 100644 --- a/examples/internal/clients/responsebody/BUILD.bazel +++ b/examples/internal/clients/responsebody/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "model_examplepb_response_body_out_response.go", "model_protobuf_any.go", "model_response_response_type.go", - "model_runtime_error.go", + "model_rpc_status.go", "model_runtime_stream_error.go", "model_stream_result_of_examplepb_response_body_out.go", "response.go", diff --git a/examples/internal/clients/responsebody/api/swagger.yaml b/examples/internal/clients/responsebody/api/swagger.yaml index 9a8fd0ea52a..59d02a7a163 100644 --- a/examples/internal/clients/responsebody/api/swagger.yaml +++ b/examples/internal/clients/responsebody/api/swagger.yaml @@ -29,7 +29,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /responsebody/stream/{data}: get: tags: @@ -55,7 +55,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /responsebody/{data}: get: tags: @@ -75,7 +75,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /responsestrings/{data}: get: tags: @@ -97,7 +97,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" definitions: ResponseResponseType: type: "string" @@ -204,11 +204,9 @@ definitions: example: value: "value" type_url: "type_url" - runtimeError: + rpcStatus: type: "object" properties: - error: - type: "string" code: type: "integer" format: "int32" diff --git a/examples/internal/clients/responsebody/api_response_body_service.go b/examples/internal/clients/responsebody/api_response_body_service.go index 968077eb532..4421adfd82f 100644 --- a/examples/internal/clients/responsebody/api_response_body_service.go +++ b/examples/internal/clients/responsebody/api_response_body_service.go @@ -108,7 +108,7 @@ func (a *ResponseBodyServiceApiService) ResponseBodyServiceGetResponseBody(ctx c } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -207,7 +207,7 @@ func (a *ResponseBodyServiceApiService) ResponseBodyServiceGetResponseBodyStream } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -306,7 +306,7 @@ func (a *ResponseBodyServiceApiService) ResponseBodyServiceListResponseBodies(ct } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -405,7 +405,7 @@ func (a *ResponseBodyServiceApiService) ResponseBodyServiceListResponseStrings(c } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/responsebody/docs/RpcStatus.md b/examples/internal/clients/responsebody/docs/RpcStatus.md new file mode 100644 index 00000000000..04bc70e31fb --- /dev/null +++ b/examples/internal/clients/responsebody/docs/RpcStatus.md @@ -0,0 +1,12 @@ +# RpcStatus + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Code** | **int32** | | [optional] [default to null] +**Message** | **string** | | [optional] [default to null] +**Details** | [**[]ProtobufAny**](protobufAny.md) | | [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/model_runtime_error.go b/examples/internal/clients/responsebody/model_rpc_status.go similarity index 87% rename from examples/internal/clients/responsebody/model_runtime_error.go rename to examples/internal/clients/responsebody/model_rpc_status.go index c23ba823000..8c0d4bdbf0c 100644 --- a/examples/internal/clients/responsebody/model_runtime_error.go +++ b/examples/internal/clients/responsebody/model_rpc_status.go @@ -9,8 +9,7 @@ package responsebody -type RuntimeError struct { - Error_ string `json:"error,omitempty"` +type RpcStatus struct { Code int32 `json:"code,omitempty"` Message string `json:"message,omitempty"` Details []ProtobufAny `json:"details,omitempty"` diff --git a/examples/internal/clients/unannotatedecho/BUILD.bazel b/examples/internal/clients/unannotatedecho/BUILD.bazel index 467850b4f91..4fc29ca5847 100644 --- a/examples/internal/clients/unannotatedecho/BUILD.bazel +++ b/examples/internal/clients/unannotatedecho/BUILD.bazel @@ -11,7 +11,7 @@ go_library( "model_examplepb_unannotated_embedded.go", "model_examplepb_unannotated_simple_message.go", "model_protobuf_any.go", - "model_runtime_error.go", + "model_rpc_status.go", "response.go", ], importpath = "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/clients/unannotatedecho", diff --git a/examples/internal/clients/unannotatedecho/api/swagger.yaml b/examples/internal/clients/unannotatedecho/api/swagger.yaml index c821b3b1023..61b0ea7d028 100644 --- a/examples/internal/clients/unannotatedecho/api/swagger.yaml +++ b/examples/internal/clients/unannotatedecho/api/swagger.yaml @@ -34,7 +34,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo/{id}/{num}: get: tags: @@ -115,7 +115,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo_body: post: tags: @@ -137,7 +137,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" /v1/example/echo_delete: delete: tags: @@ -219,7 +219,7 @@ paths: default: description: "An unexpected error response" schema: - $ref: "#/definitions/runtimeError" + $ref: "#/definitions/rpcStatus" definitions: examplepbUnannotatedEmbedded: type: "object" @@ -329,11 +329,9 @@ definitions: \ custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\ \n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n\ \ \"value\": \"1.212s\"\n }" - runtimeError: + rpcStatus: type: "object" properties: - error: - type: "string" code: type: "integer" format: "int32" diff --git a/examples/internal/clients/unannotatedecho/api_unannotated_echo_service.go b/examples/internal/clients/unannotatedecho/api_unannotated_echo_service.go index 99520f0ca51..7183d28741e 100644 --- a/examples/internal/clients/unannotatedecho/api_unannotated_echo_service.go +++ b/examples/internal/clients/unannotatedecho/api_unannotated_echo_service.go @@ -110,7 +110,7 @@ func (a *UnannotatedEchoServiceApiService) UnannotatedEchoServiceEcho(ctx contex } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -257,7 +257,7 @@ func (a *UnannotatedEchoServiceApiService) UnannotatedEchoServiceEcho2(ctx conte } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -357,7 +357,7 @@ func (a *UnannotatedEchoServiceApiService) UnannotatedEchoServiceEchoBody(ctx co } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() @@ -509,7 +509,7 @@ func (a *UnannotatedEchoServiceApiService) UnannotatedEchoServiceEchoDelete(ctx } if localVarHttpResponse.StatusCode == 0 { - var v RuntimeError + var v RpcStatus err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); if err != nil { newErr.error = err.Error() diff --git a/examples/internal/clients/unannotatedecho/model_runtime_error.go b/examples/internal/clients/unannotatedecho/model_rpc_status.go similarity index 90% rename from examples/internal/clients/unannotatedecho/model_runtime_error.go rename to examples/internal/clients/unannotatedecho/model_rpc_status.go index 8518d725074..2ffb74dc75d 100644 --- a/examples/internal/clients/unannotatedecho/model_runtime_error.go +++ b/examples/internal/clients/unannotatedecho/model_rpc_status.go @@ -9,8 +9,7 @@ package unannotatedecho -type RuntimeError struct { - Error_ string `json:"error,omitempty"` +type RpcStatus struct { Code int32 `json:"code,omitempty"` Message string `json:"message,omitempty"` Details []ProtobufAny `json:"details,omitempty"` diff --git a/examples/internal/integration/BUILD.bazel b/examples/internal/integration/BUILD.bazel index f7b9d441dd4..bcc837b56f1 100644 --- a/examples/internal/integration/BUILD.bazel +++ b/examples/internal/integration/BUILD.bazel @@ -23,7 +23,9 @@ go_test( "@com_github_golang_protobuf//descriptor:go_default_library_gen", "@com_github_golang_protobuf//jsonpb:go_default_library_gen", "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes:go_default_library_gen", "@com_github_google_go_cmp//cmp:go_default_library", + "@go_googleapis//google/rpc:errdetails_go_proto", "@go_googleapis//google/rpc:status_go_proto", "@io_bazel_rules_go//proto/wkt:empty_go_proto", "@io_bazel_rules_go//proto/wkt:field_mask_go_proto", diff --git a/examples/internal/integration/integration_test.go b/examples/internal/integration/integration_test.go index e37cd04cac9..f23f6e7e133 100644 --- a/examples/internal/integration/integration_test.go +++ b/examples/internal/integration/integration_test.go @@ -26,17 +26,12 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/pathenum" "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/sub" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/genproto/protobuf/field_mask" "google.golang.org/grpc/codes" "google.golang.org/protobuf/testing/protocmp" ) -type errorBody struct { - Error string `json:"error"` - Code int `json:"code"` - Details []interface{} `json:"details"` -} - func TestEcho(t *testing.T) { if testing.Short() { t.Skip() @@ -616,7 +611,7 @@ func testABEBulkCreateWithError(t *testing.T, port int) { t.Logf("%s", buf) } - var msg errorBody + var msg spb.Status if err := json.Unmarshal(buf, &msg); err != nil { t.Fatalf("json.Unmarshal(%s, &msg) failed with %v; want success", buf, err) } @@ -907,19 +902,19 @@ func testABELookupNotFound(t *testing.T, port int) { return } - var msg errorBody + var msg spb.Status if err := json.Unmarshal(buf, &msg); err != nil { t.Errorf("json.Unmarshal(%s, &msg) failed with %v; want success", buf, err) return } - if got, want := msg.Code, int(codes.NotFound); got != want { + if got, want := msg.Code, int32(codes.NotFound); got != want { t.Errorf("msg.Code = %d; want %d", got, want) return } - if got, want := msg.Error, "not found"; got != want { - t.Errorf("msg.Error = %s; want %s", got, want) + if got, want := msg.Message, "not found"; got != want { + t.Errorf("msg.Message = %s; want %s", got, want) return } @@ -1310,71 +1305,6 @@ func TestTimeout(t *testing.T) { } } -func TestErrorWithDetails(t *testing.T) { - if testing.Short() { - t.Skip() - return - } - - apiURL := "http://localhost:8088/v2/example/errorwithdetails" - resp, err := http.Get(apiURL) - if err != nil { - t.Errorf("http.Get(%q) failed with %v; want success", apiURL, err) - return - } - defer resp.Body.Close() - - buf, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatalf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) - } - - if got, want := resp.StatusCode, http.StatusInternalServerError; got != want { - t.Errorf("resp.StatusCode = %d; want %d", got, want) - } - - var msg errorBody - if err := json.Unmarshal(buf, &msg); err != nil { - t.Fatalf("json.Unmarshal(%s, &msg) failed with %v; want success", buf, err) - } - - if got, want := msg.Code, int(codes.Unknown); got != want { - t.Errorf("msg.Code = %d; want %d", got, want) - } - if got, want := msg.Error, "with details"; got != want { - t.Errorf("msg.Error = %s; want %s", got, want) - } - if got, want := len(msg.Details), 1; got != want { - t.Fatalf("len(msg.Details) = %q; want %q", got, want) - } - - details, ok := msg.Details[0].(map[string]interface{}) - if got, want := ok, true; got != want { - t.Fatalf("msg.Details[0] got type: %T, want %T", msg.Details[0], map[string]interface{}{}) - } - typ, ok := details["@type"].(string) - if got, want := ok, true; got != want { - t.Fatalf("msg.Details[0][\"@type\"] got type: %T, want %T", typ, "") - } - if got, want := details["@type"], "type.googleapis.com/google.rpc.DebugInfo"; got != want { - t.Errorf("msg.Details[\"@type\"] = %q; want %q", got, want) - } - if got, want := details["detail"], "error debug details"; got != want { - t.Errorf("msg.Details[\"detail\"] = %q; want %q", got, want) - } - entries, ok := details["stack_entries"].([]interface{}) - if got, want := ok, true; got != want { - t.Fatalf("msg.Details[0][\"stack_entries\"] got type: %T, want %T", entries, []string{}) - } - entry, ok := entries[0].(string) - if got, want := ok, true; got != want { - t.Fatalf("msg.Details[0][\"stack_entries\"][0] got type: %T, want %T", entry, "") - } - if got, want := entries[0], "foo:1"; got != want { - t.Errorf("msg.Details[\"stack_entries\"][0] = %q; want %q", got, want) - } -} - func TestPostWithEmptyBody(t *testing.T) { if testing.Short() { t.Skip() diff --git a/examples/internal/integration/proto_error_test.go b/examples/internal/integration/proto_error_test.go index bc93895cf26..12a636c1a62 100644 --- a/examples/internal/integration/proto_error_test.go +++ b/examples/internal/integration/proto_error_test.go @@ -10,7 +10,9 @@ import ( "time" "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/ptypes" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "google.golang.org/genproto/googleapis/rpc/errdetails" spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" ) @@ -62,6 +64,7 @@ func TestABEWithProtoErrorHandler(t *testing.T) { testABEBulkCreate(t, port) testABELookup(t, port) testABELookupNotFoundWithProtoError(t, port) + testABELookupNotFoundWithProtoErrorIncludingDetails(t, port) testABEList(t, port) testABEBulkEcho(t, port) testABEBulkEchoZeroLength(t, port) @@ -118,6 +121,62 @@ func testABELookupNotFoundWithProtoError(t *testing.T, port uint16) { } } +func testABELookupNotFoundWithProtoErrorIncludingDetails(t *testing.T, port uint16) { + uuid := "errorwithdetails" + url := fmt.Sprintf("http://localhost:%d/v2/example/%s", port, uuid) + resp, err := http.Get(url) + if err != nil { + t.Errorf("http.Get(%q) failed with %v; want success", url, err) + return + } + defer resp.Body.Close() + + buf, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + return + } + + if got, want := resp.StatusCode, http.StatusInternalServerError; got != want { + t.Errorf("resp.StatusCode = %d; want %d", got, want) + t.Logf("%s", buf) + return + } + + var msg spb.Status + if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil { + t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err) + return + } + + if got, want := msg.Code, int32(codes.Unknown); got != want { + t.Errorf("msg.Code = %d; want %d", got, want) + return + } + + if got, want := msg.Message, "with details"; got != want { + t.Errorf("msg.Message = %s; want %s", got, want) + return + } + + details := msg.Details + if got, want := len(details), 1; got != want { + t.Fatalf("got %q details, wanted %q", got, want) + } + + detail := errdetails.DebugInfo{} + if got, want := ptypes.UnmarshalAny(msg.Details[0], &detail), error(nil); got != want { + t.Errorf("unmarshaling any: got %q, wanted %q", got, want) + } + + if got, want := len(detail.StackEntries), 1; got != want { + t.Fatalf("got %d stack entries, expected %d", got, want) + } + if got, want := detail.StackEntries[0], "foo:1"; got != want { + t.Errorf("StackEntries[0]: got %q; want %q", got, want) + } +} + func TestUnknownPathWithProtoError(t *testing.T) { if testing.Short() { t.Skip() diff --git a/examples/internal/proto/examplepb/a_bit_of_everything.swagger.json b/examples/internal/proto/examplepb/a_bit_of_everything.swagger.json index 76a818c470e..883d98f0536 100644 --- a/examples/internal/proto/examplepb/a_bit_of_everything.swagger.json +++ b/examples/internal/proto/examplepb/a_bit_of_everything.swagger.json @@ -58,7 +58,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -119,7 +119,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -170,7 +170,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -485,7 +485,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -806,7 +806,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -861,7 +861,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1197,7 +1197,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1384,7 +1384,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1440,7 +1440,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1485,7 +1485,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1540,7 +1540,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1595,7 +1595,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1831,7 +1831,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1884,7 +1884,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -1951,7 +1951,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2012,7 +2012,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2065,7 +2065,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2104,7 +2104,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2143,7 +2143,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2185,7 +2185,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2240,7 +2240,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2279,7 +2279,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2334,7 +2334,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -2783,12 +2783,9 @@ "description": "paths: \"f.a\"\n paths: \"f.b.d\"\n\nHere `f` represents a field in some root message, `a` and `b`\nfields in the message found in `f`, and `d` a field found in the\nmessage in `f.b`.\n\nField masks are used to specify a subset of fields that should be\nreturned by a get operation or modified by an update operation.\nField masks also have a custom JSON encoding (see below).\n\n# Field Masks in Projections\n\nWhen used in the context of a projection, a response message or\nsub-message is filtered by the API to only contain those fields as\nspecified in the mask. For example, if the mask in the previous\nexample is applied to a response message as follows:\n\n f {\n a : 22\n b {\n d : 1\n x : 2\n }\n y : 13\n }\n z: 8\n\nThe result will not contain specific values for fields x,y and z\n(their value will be set to the default, and omitted in proto text\noutput):\n\n\n f {\n a : 22\n b {\n d : 1\n }\n }\n\nA repeated field is not allowed except at the last position of a\npaths string.\n\nIf a FieldMask object is not present in a get operation, the\noperation applies to all fields (as if a FieldMask of all fields\nhad been specified).\n\nNote that a field mask does not necessarily apply to the\ntop-level response message. In case of a REST get operation, the\nfield mask applies directly to the response, but in case of a REST\nlist operation, the mask instead applies to each individual message\nin the returned resource list. In case of a REST custom method,\nother definitions may be used. Where the mask applies will be\nclearly documented together with its declaration in the API. In\nany case, the effect on the returned resource/resources is required\nbehavior for APIs.\n\n# Field Masks in Update Operations\n\nA field mask in update operations specifies which fields of the\ntargeted resource are going to be updated. The API is required\nto only change the values of the fields as specified in the mask\nand leave the others untouched. If a resource is passed in to\ndescribe the updated values, the API ignores the values of all\nfields not covered by the mask.\n\nIf a repeated field is specified for an update operation, new values will\nbe appended to the existing repeated field in the target resource. Note that\na repeated field is only allowed in the last position of a `paths` string.\n\nIf a sub-message is specified in the last position of the field mask for an\nupdate operation, then new value will be merged into the existing sub-message\nin the target resource.\n\nFor example, given the target message:\n\n f {\n b {\n d: 1\n x: 2\n }\n c: [1]\n }\n\nAnd an update message:\n\n f {\n b {\n d: 10\n }\n c: [2]\n }\n\nthen if the field mask is:\n\n paths: [\"f.b\", \"f.c\"]\n\nthen the result will be:\n\n f {\n b {\n d: 10\n x: 2\n }\n c: [1, 2]\n }\n\nAn implementation may provide options to override this default behavior for\nrepeated and message fields.\n\nIn order to reset a field's value to the default, the field must\nbe in the mask and set to the default value in the provided resource.\nHence, in order to reset all fields of a resource, provide a default\ninstance of the resource and set all fields in the mask, or do\nnot provide a mask as described below.\n\nIf a field mask is not present on update, the operation applies to\nall fields (as if a field mask of all fields has been specified).\nNote that in the presence of schema evolution, this may mean that\nfields the client does not know and has therefore not filled into\nthe request will be reset to their default. If this is unwanted\nbehavior, a specific service may require a client to always specify\na field mask, producing an error if not.\n\nAs with get operations, the location of the resource which\ndescribes the updated values in the request message depends on the\noperation kind. In any case, the effect of the field mask is\nrequired to be honored by the API.\n\n## Considerations for HTTP REST\n\nThe HTTP kind of an update operation which uses a field mask must\nbe set to PATCH instead of PUT in order to satisfy HTTP semantics\n(PUT must only be used for full updates).\n\n# JSON Encoding of Field Masks\n\nIn JSON, a field mask is encoded as a single string where paths are\nseparated by a comma. Fields name in each path are converted\nto/from lower-camel naming conventions.\n\nAs an example, consider the following message declarations:\n\n message Profile {\n User user = 1;\n Photo photo = 2;\n }\n message User {\n string display_name = 1;\n string address = 2;\n }\n\nIn proto a field mask for `Profile` may look as such:\n\n mask {\n paths: \"user.display_name\"\n paths: \"photo\"\n }\n\nIn JSON, the same mask is represented as below:\n\n {\n mask: \"user.displayName,photo\"\n }\n\n# Field Masks and Oneof Fields\n\nField masks treat fields in oneofs just as regular fields. Consider the\nfollowing message:\n\n message SampleMessage {\n oneof test_oneof {\n string name = 4;\n SubMessage sub_message = 9;\n }\n }\n\nThe field mask can be:\n\n mask {\n paths: \"name\"\n }\n\nOr:\n\n mask {\n paths: \"sub_message\"\n }\n\nNote that oneof type names (\"test_oneof\" in this case) cannot be used in\npaths.\n\n## Field Mask Verification\n\nThe implementation of any API method which has a FieldMask type field in the\nrequest should verify the included field paths, and return an\n`INVALID_ARGUMENT` error if any path is duplicated or unmappable.", "title": "`FieldMask` represents a set of symbolic field paths, for example:" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/echo_service.swagger.json b/examples/internal/proto/examplepb/echo_service.swagger.json index 43d9b608d56..e21e5ac1361 100644 --- a/examples/internal/proto/examplepb/echo_service.swagger.json +++ b/examples/internal/proto/examplepb/echo_service.swagger.json @@ -27,7 +27,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -60,7 +60,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -146,7 +146,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -232,7 +232,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -312,7 +312,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -391,7 +391,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -424,7 +424,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -556,12 +556,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/response_body_service.swagger.json b/examples/internal/proto/examplepb/response_body_service.swagger.json index 1fad10c2042..31f2fc59788 100644 --- a/examples/internal/proto/examplepb/response_body_service.swagger.json +++ b/examples/internal/proto/examplepb/response_body_service.swagger.json @@ -27,7 +27,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -66,7 +66,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -96,7 +96,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -129,7 +129,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -222,12 +222,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/stream.swagger.json b/examples/internal/proto/examplepb/stream.swagger.json index 2d4681d6c4a..b54ec910a5e 100644 --- a/examples/internal/proto/examplepb/stream.swagger.json +++ b/examples/internal/proto/examplepb/stream.swagger.json @@ -33,7 +33,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -55,7 +55,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -97,7 +97,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -377,12 +377,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/unannotated_echo_service.swagger.json b/examples/internal/proto/examplepb/unannotated_echo_service.swagger.json index 1521bc4c043..854d3972cf5 100644 --- a/examples/internal/proto/examplepb/unannotated_echo_service.swagger.json +++ b/examples/internal/proto/examplepb/unannotated_echo_service.swagger.json @@ -27,7 +27,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -60,7 +60,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -151,7 +151,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -184,7 +184,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -325,12 +325,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/use_go_template.swagger.json b/examples/internal/proto/examplepb/use_go_template.swagger.json index 2c68208ce1b..0e69b428172 100644 --- a/examples/internal/proto/examplepb/use_go_template.swagger.json +++ b/examples/internal/proto/examplepb/use_go_template.swagger.json @@ -26,7 +26,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -60,7 +60,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -154,12 +154,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/examples/internal/proto/examplepb/wrappers.swagger.json b/examples/internal/proto/examplepb/wrappers.swagger.json index 0153c9592df..2fa5a12d2b3 100644 --- a/examples/internal/proto/examplepb/wrappers.swagger.json +++ b/examples/internal/proto/examplepb/wrappers.swagger.json @@ -24,7 +24,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -57,7 +57,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -91,7 +91,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -125,7 +125,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -158,7 +158,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -191,7 +191,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -225,7 +225,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -259,7 +259,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -292,7 +292,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -325,7 +325,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -359,7 +359,7 @@ "default": { "description": "An unexpected error response", "schema": { - "$ref": "#/definitions/runtimeError" + "$ref": "#/definitions/rpcStatus" } } }, @@ -436,12 +436,9 @@ }, "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := ptypes.MarshalAny(foo)\n ...\n foo := \u0026pb.Foo{}\n if err := ptypes.UnmarshalAny(any, foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }" }, - "runtimeError": { + "rpcStatus": { "type": "object", "properties": { - "error": { - "type": "string" - }, "code": { "type": "integer", "format": "int32" diff --git a/internal/errors.pb.go b/internal/errors.pb.go index f8eedaeef23..5a2faa56e1d 100644 --- a/internal/errors.pb.go +++ b/internal/errors.pb.go @@ -26,81 +26,6 @@ const ( // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 -// Error is the generic error returned from unary RPCs. -type Error struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` - // This is to make the error more compatible with users that expect errors to be Status objects: - // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto - // It should be the exact same message as the Error field. - Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"` - Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` - Details []*any.Any `protobuf:"bytes,4,rep,name=details,proto3" json:"details,omitempty"` -} - -func (x *Error) Reset() { - *x = Error{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_errors_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Error) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Error) ProtoMessage() {} - -func (x *Error) ProtoReflect() protoreflect.Message { - mi := &file_internal_errors_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Error.ProtoReflect.Descriptor instead. -func (*Error) Descriptor() ([]byte, []int) { - return file_internal_errors_proto_rawDescGZIP(), []int{0} -} - -func (x *Error) GetError() string { - if x != nil { - return x.Error - } - return "" -} - -func (x *Error) GetCode() int32 { - if x != nil { - return x.Code - } - return 0 -} - -func (x *Error) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -func (x *Error) GetDetails() []*any.Any { - if x != nil { - return x.Details - } - return nil -} - // StreamError is a response type which is returned when // streaming rpc returns an error. type StreamError struct { @@ -118,7 +43,7 @@ type StreamError struct { func (x *StreamError) Reset() { *x = StreamError{} if protoimpl.UnsafeEnabled { - mi := &file_internal_errors_proto_msgTypes[1] + mi := &file_internal_errors_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -131,7 +56,7 @@ func (x *StreamError) String() string { func (*StreamError) ProtoMessage() {} func (x *StreamError) ProtoReflect() protoreflect.Message { - mi := &file_internal_errors_proto_msgTypes[1] + mi := &file_internal_errors_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -144,7 +69,7 @@ func (x *StreamError) ProtoReflect() protoreflect.Message { // Deprecated: Use StreamError.ProtoReflect.Descriptor instead. func (*StreamError) Descriptor() ([]byte, []int) { - return file_internal_errors_proto_rawDescGZIP(), []int{1} + return file_internal_errors_proto_rawDescGZIP(), []int{0} } func (x *StreamError) GetGrpcCode() int32 { @@ -189,27 +114,20 @@ var file_internal_errors_proto_rawDesc = []byte{ 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, - 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7b, 0x0a, 0x05, 0x45, 0x72, 0x72, 0x6f, - 0x72, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, - 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x64, 0x65, - 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0xb2, 0x01, 0x0a, 0x0b, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x63, 0x6f, - 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x67, 0x72, 0x70, 0x63, 0x43, 0x6f, - 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x68, 0x74, 0x74, 0x70, 0x43, 0x6f, 0x64, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x74, 0x74, - 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x68, 0x74, 0x74, 0x70, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2e, 0x0a, 0x07, 0x64, 0x65, - 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, - 0x79, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x0a, 0x5a, 0x08, 0x69, 0x6e, - 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb2, 0x01, 0x0a, 0x0b, 0x53, 0x74, 0x72, + 0x65, 0x61, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x67, 0x72, 0x70, 0x63, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x67, 0x72, 0x70, + 0x63, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x68, 0x74, 0x74, 0x70, 0x43, 0x6f, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, + 0x68, 0x74, 0x74, 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2e, 0x0a, + 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x0a, 0x5a, + 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -224,20 +142,18 @@ func file_internal_errors_proto_rawDescGZIP() []byte { return file_internal_errors_proto_rawDescData } -var file_internal_errors_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_internal_errors_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_internal_errors_proto_goTypes = []interface{}{ - (*Error)(nil), // 0: grpc.gateway.runtime.Error - (*StreamError)(nil), // 1: grpc.gateway.runtime.StreamError - (*any.Any)(nil), // 2: google.protobuf.Any + (*StreamError)(nil), // 0: grpc.gateway.runtime.StreamError + (*any.Any)(nil), // 1: google.protobuf.Any } var file_internal_errors_proto_depIdxs = []int32{ - 2, // 0: grpc.gateway.runtime.Error.details:type_name -> google.protobuf.Any - 2, // 1: grpc.gateway.runtime.StreamError.details:type_name -> google.protobuf.Any - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 1, // 0: grpc.gateway.runtime.StreamError.details:type_name -> google.protobuf.Any + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_internal_errors_proto_init() } @@ -247,18 +163,6 @@ func file_internal_errors_proto_init() { } if !protoimpl.UnsafeEnabled { file_internal_errors_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Error); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_errors_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StreamError); i { case 0: return &v.state @@ -277,7 +181,7 @@ func file_internal_errors_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_errors_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 1, NumExtensions: 0, NumServices: 0, }, diff --git a/internal/errors.proto b/internal/errors.proto index 4fb212c6b69..55f42ce63ec 100644 --- a/internal/errors.proto +++ b/internal/errors.proto @@ -4,17 +4,6 @@ option go_package = "internal"; import "google/protobuf/any.proto"; -// Error is the generic error returned from unary RPCs. -message Error { - string error = 1; - // This is to make the error more compatible with users that expect errors to be Status objects: - // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto - // It should be the exact same message as the Error field. - int32 code = 2; - string message = 3; - repeated google.protobuf.Any details = 4; -} - // StreamError is a response type which is returned when // streaming rpc returns an error. message StreamError { diff --git a/protoc-gen-swagger/genswagger/BUILD.bazel b/protoc-gen-swagger/genswagger/BUILD.bazel index 534cc688a30..e2b2e447a8b 100644 --- a/protoc-gen-swagger/genswagger/BUILD.bazel +++ b/protoc-gen-swagger/genswagger/BUILD.bazel @@ -22,6 +22,7 @@ go_library( "@com_github_golang_protobuf//descriptor:go_default_library_gen", "@com_github_golang_protobuf//jsonpb:go_default_library_gen", "@com_github_golang_protobuf//proto:go_default_library", + "@go_googleapis//google/rpc:status_go_proto", "@io_bazel_rules_go//proto/wkt:any_go_proto", "@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto", "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", diff --git a/protoc-gen-swagger/genswagger/generator.go b/protoc-gen-swagger/genswagger/generator.go index 8203d64c318..bb1fc5ae391 100644 --- a/protoc-gen-swagger/genswagger/generator.go +++ b/protoc-gen-swagger/genswagger/generator.go @@ -19,6 +19,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway/descriptor" gen "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway/generator" swagger_options "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-swagger/options" + spb "google.golang.org/genproto/googleapis/rpc/status" ) var ( @@ -217,20 +218,20 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGenerato return files, nil } -//AddStreamError Adds grpc.gateway.runtime.StreamError and google.protobuf.Any to registry for stream responses -func AddStreamError(reg *descriptor.Registry) error { - //load internal protos +// AddErrorDefs Adds grpc.gateway.runtime.StreamError, google.rpc.Status, and google.protobuf.Any +// to registry (used for error-related API responses) +func AddErrorDefs(reg *descriptor.Registry) error { + // load internal protos any := fileDescriptorProtoForMessage(&any.Any{}) + status := fileDescriptorProtoForMessage(&spb.Status{}) streamError := fileDescriptorProtoForMessage(&internal.StreamError{}) - if err := reg.Load(&plugin.CodeGeneratorRequest{ + return reg.Load(&plugin.CodeGeneratorRequest{ ProtoFile: []*protocdescriptor.FileDescriptorProto{ any, + status, streamError, }, - }); err != nil { - return err - } - return nil + }) } func fileDescriptorProtoForMessage(msg pbdescriptor.Message) *protocdescriptor.FileDescriptorProto { diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index e67ab923bed..712c2e0657d 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -963,7 +963,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re }, } if !reg.GetDisableDefaultErrors() { - errDef, hasErrDef := fullyQualifiedNameToSwaggerName(".grpc.gateway.runtime.Error", reg) + errDef, hasErrDef := fullyQualifiedNameToSwaggerName(".google.rpc.Status", reg) if hasErrDef { // https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#responses-object operationObject.Responses["default"] = swaggerResponseObject{ @@ -1139,7 +1139,7 @@ func applyTemplate(p param) (*swaggerObject, error) { if !p.reg.GetDisableDefaultErrors() { // Add the error type to the message map - runtimeError, swgRef, err := lookupMsgAndSwaggerName(".grpc.gateway.runtime", "Error", p.reg) + runtimeError, swgRef, err := lookupMsgAndSwaggerName("google.rpc", "Status", p.reg) if err == nil { messages[swgRef] = runtimeError } else { diff --git a/protoc-gen-swagger/genswagger/template_test.go b/protoc-gen-swagger/genswagger/template_test.go index a80b1fdbe26..3636abf2b65 100644 --- a/protoc-gen-swagger/genswagger/template_test.go +++ b/protoc-gen-swagger/genswagger/template_test.go @@ -572,6 +572,10 @@ func TestApplyTemplateSimple(t *testing.T) { }, } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } fileCL := crossLinkFixture(&file) err := reg.Load(reqFromFile(fileCL)) if err != nil { @@ -690,6 +694,10 @@ func TestApplyTemplateMultiService(t *testing.T) { }, } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } fileCL := crossLinkFixture(&file) err := reg.Load(reqFromFile(fileCL)) if err != nil { @@ -782,6 +790,10 @@ func TestApplyTemplateOverrideOperationID(t *testing.T) { } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } fileCL := crossLinkFixture(&file) err := reg.Load(reqFromFile(fileCL)) if err != nil { @@ -903,6 +915,10 @@ func TestApplyTemplateExtensions(t *testing.T) { t.Fatalf("proto.SetExtension(MethodDescriptorProto.Options) failed: %v", err) } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } fileCL := crossLinkFixture(&file) err := reg.Load(reqFromFile(fileCL)) if err != nil { @@ -1084,6 +1100,10 @@ func TestApplyTemplateRequestWithoutClientStreaming(t *testing.T) { }, } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } reg.Load(&plugin.CodeGeneratorRequest{ProtoFile: []*protodescriptor.FileDescriptorProto{file.FileDescriptorProto}}) result, err := applyTemplate(param{File: crossLinkFixture(&file), reg: reg}) if err != nil { @@ -1238,8 +1258,8 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) { }, } reg := descriptor.NewRegistry() - if err := AddStreamError(reg); err != nil { - t.Errorf("AddStreamError(%#v) failed with %v; want success", reg, err) + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) return } reg.Load(&plugin.CodeGeneratorRequest{ProtoFile: []*protodescriptor.FileDescriptorProto{file.FileDescriptorProto}}) @@ -1398,6 +1418,10 @@ func TestApplyTemplateRequestWithUnusedReferences(t *testing.T) { } reg := descriptor.NewRegistry() + if err := AddErrorDefs(reg); err != nil { + t.Errorf("AddErrorDefs(%#v) failed with %v; want success", reg, err) + return + } reg.Load(&plugin.CodeGeneratorRequest{ProtoFile: []*protodescriptor.FileDescriptorProto{file.FileDescriptorProto}}) result, err := applyTemplate(param{File: crossLinkFixture(&file), reg: reg}) if err != nil { @@ -1405,8 +1429,8 @@ func TestApplyTemplateRequestWithUnusedReferences(t *testing.T) { return } - // Only EmptyMessage must be present, not ExampleMessage - if want, got, name := 1, len(result.Definitions), "len(Definitions)"; !reflect.DeepEqual(got, want) { + // Only EmptyMessage must be present, not ExampleMessage (plus error status) + if want, got, name := 3, len(result.Definitions), "len(Definitions)"; !reflect.DeepEqual(got, want) { t.Errorf("applyTemplate(%#v).%s = %d want to be %d", file, name, got, want) } diff --git a/protoc-gen-swagger/main.go b/protoc-gen-swagger/main.go index 63270d490d4..2d6c8da6c9f 100644 --- a/protoc-gen-swagger/main.go +++ b/protoc-gen-swagger/main.go @@ -103,7 +103,7 @@ func main() { g := genswagger.New(reg) - if err := genswagger.AddStreamError(reg); err != nil { + if err := genswagger.AddErrorDefs(reg); err != nil { emitError(err) return } diff --git a/runtime/errors.go b/runtime/errors.go index c95e4264bc4..58c80eec857 100644 --- a/runtime/errors.go +++ b/runtime/errors.go @@ -5,7 +5,6 @@ import ( "io" "net/http" - "github.com/grpc-ecosystem/grpc-gateway/v2/internal" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" "google.golang.org/grpc/status" @@ -108,14 +107,12 @@ func MuxOrGlobalHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshale // If otherwise, it replies with http.StatusInternalServerError. // // The response body returned by this function is a JSON object, -// which contains a member whose key is "error" and whose value is err.Error(). +// which contains a member whose key is "message" and whose value is err.Error(). func DefaultHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, _ *http.Request, err error) { const fallback = `{"error": "failed to marshal error message"}` - s, ok := status.FromError(err) - if !ok { - s = status.New(codes.Unknown, err.Error()) - } + s := status.Convert(err) + pb := s.Proto() w.Header().Del("Trailer") @@ -124,21 +121,13 @@ func DefaultHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w // An interface param needs to be added to the ContentType() function on // the Marshal interface to be able to remove this check if typeMarshaler, ok := marshaler.(contentTypeMarshaler); ok { - pb := s.Proto() contentType = typeMarshaler.ContentTypeFromMessage(pb) } w.Header().Set("Content-Type", contentType) - body := &internal.Error{ - Error: s.Message(), - Message: s.Message(), - Code: int32(s.Code()), - Details: s.Proto().GetDetails(), - } - - buf, merr := marshaler.Marshal(body) + buf, merr := marshaler.Marshal(pb) if merr != nil { - grpclog.Infof("Failed to marshal error message %q: %v", body, merr) + grpclog.Infof("Failed to marshal error message %q: %v", s, merr) w.WriteHeader(http.StatusInternalServerError) if _, err := io.WriteString(w, fallback); err != nil { grpclog.Infof("Failed to write response: %v", err) diff --git a/runtime/errors_test.go b/runtime/errors_test.go index afd289aebac..83ec1666a03 100644 --- a/runtime/errors_test.go +++ b/runtime/errors_test.go @@ -77,9 +77,6 @@ func TestDefaultHTTPError(t *testing.T) { continue } - if got, want := body["error"].(string), spec.msg; !strings.Contains(got, want) { - t.Errorf(`body["error"] = %q; want %q; on spec.err=%v`, got, want, spec.err) - } if got, want := body["message"].(string), spec.msg; !strings.Contains(got, want) { t.Errorf(`body["message"] = %q; want %q; on spec.err=%v`, got, want, spec.err) }