Skip to content

Commit 80a7a7b

Browse files
fix import alias issue with protoc-gen-grpc-gateway (#1757)
* return registry from gengateway.New retain parsing order comment * update test after merge * add example to abe * bad merge * cut and paste err * simple change * simplify * outdated * goimports
1 parent f2e74d6 commit 80a7a7b

27 files changed

+1546
-879
lines changed

examples/internal/clients/abe/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"model_examplepb_a_bit_of_everything_repeated.go",
1717
"model_examplepb_body.go",
1818
"model_examplepb_book.go",
19+
"model_examplepb_check_status_response.go",
1920
"model_examplepb_numeric_enum.go",
2021
"model_examplepb_update_v2_request.go",
2122
"model_message_path_enum_nested_path_enum.go",

examples/internal/clients/abe/api/swagger.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,34 @@ paths:
17241724
description: "An unexpected error response."
17251725
schema:
17261726
$ref: "#/definitions/rpcStatus"
1727+
/v1/example/checkStatus:
1728+
get:
1729+
tags:
1730+
- "ABitOfEverythingService"
1731+
operationId: "ABitOfEverythingService_CheckStatus"
1732+
parameters: []
1733+
responses:
1734+
200:
1735+
description: "A successful response."
1736+
schema:
1737+
$ref: "#/definitions/examplepbCheckStatusResponse"
1738+
403:
1739+
description: "Returned when the user does not have permission to access\
1740+
\ the resource."
1741+
schema: {}
1742+
404:
1743+
description: "Returned when the resource does not exist."
1744+
schema:
1745+
type: "string"
1746+
format: "string"
1747+
418:
1748+
description: "I'm a teapot."
1749+
schema:
1750+
$ref: "#/definitions/examplepbNumericEnum"
1751+
default:
1752+
description: "An unexpected error response."
1753+
schema:
1754+
$ref: "#/definitions/rpcStatus"
17271755
/v1/example/deep_path/{singleNested.name}:
17281756
post:
17291757
tags:
@@ -2564,6 +2592,20 @@ definitions:
25642592
createTime: "2000-01-23T04:56:07.000+00:00"
25652593
name: "name"
25662594
id: "id"
2595+
examplepbCheckStatusResponse:
2596+
type: "object"
2597+
properties:
2598+
status:
2599+
$ref: "#/definitions/rpcStatus"
2600+
example:
2601+
status:
2602+
code: 0
2603+
details:
2604+
- typeUrl: "typeUrl"
2605+
value: "value"
2606+
- typeUrl: "typeUrl"
2607+
value: "value"
2608+
message: "message"
25672609
examplepbNumericEnum:
25682610
type: "string"
25692611
description: "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE\
@@ -2648,18 +2690,68 @@ definitions:
26482690
\ custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\
26492691
\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n\
26502692
\ \"value\": \"1.212s\"\n }"
2693+
example:
2694+
typeUrl: "typeUrl"
2695+
value: "value"
26512696
rpcStatus:
26522697
type: "object"
26532698
properties:
26542699
code:
26552700
type: "integer"
26562701
format: "int32"
2702+
description: "The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]."
26572703
message:
26582704
type: "string"
2705+
description: "A developer-facing error message, which should be in English.\
2706+
\ Any\nuser-facing error message should be localized and sent in the\n[google.rpc.Status.details][google.rpc.Status.details]\
2707+
\ field, or localized by the client."
26592708
details:
26602709
type: "array"
2710+
description: "A list of messages that carry the error details. There is a\
2711+
\ common set of\nmessage types for APIs to use."
26612712
items:
26622713
$ref: "#/definitions/protobufAny"
2714+
title: "The `Status` type defines a logical error model that is suitable for different\n\
2715+
programming environments, including REST APIs and RPC APIs. It is used by\n\
2716+
[gRPC](https://github.com/grpc). The error model is designed to be:"
2717+
description: "- Simple to use and understand for most users\n- Flexible enough\
2718+
\ to meet unexpected needs\n\n# Overview\n\nThe `Status` message contains three\
2719+
\ pieces of data: error code, error message,\nand error details. The error code\
2720+
\ should be an enum value of\n[google.rpc.Code][google.rpc.Code], but it may\
2721+
\ accept additional error codes if needed. The\nerror message should be a developer-facing\
2722+
\ English message that helps\ndevelopers *understand* and *resolve* the error.\
2723+
\ If a localized user-facing\nerror message is needed, put the localized message\
2724+
\ in the error details or\nlocalize it in the client. The optional error details\
2725+
\ may contain arbitrary\ninformation about the error. There is a predefined\
2726+
\ set of error detail types\nin the package `google.rpc` that can be used for\
2727+
\ common error conditions.\n\n# Language mapping\n\nThe `Status` message is\
2728+
\ the logical representation of the error model, but it\nis not necessarily\
2729+
\ the actual wire format. When the `Status` message is\nexposed in different\
2730+
\ client libraries and different wire protocols, it can be\nmapped differently.\
2731+
\ For example, it will likely be mapped to some exceptions\nin Java, but more\
2732+
\ likely mapped to some error codes in C.\n\n# Other uses\n\nThe error model\
2733+
\ and the `Status` message can be used in a variety of\nenvironments, either\
2734+
\ with or without APIs, to provide a\nconsistent developer experience across\
2735+
\ different environments.\n\nExample uses of this error model include:\n\n-\
2736+
\ Partial errors. If a service needs to return partial errors to the client,\n\
2737+
\ it may embed the `Status` in the normal response to indicate the partial\n\
2738+
\ errors.\n\n- Workflow errors. A typical workflow has multiple steps. Each\
2739+
\ step may\n have a `Status` message for error reporting.\n\n- Batch operations.\
2740+
\ If a client uses batch request and batch response, the\n `Status` message\
2741+
\ should be used directly inside batch response, one for\n each error sub-response.\n\
2742+
\n- Asynchronous operations. If an API call embeds asynchronous operation\n\
2743+
\ results in its response, the status of those operations should be\n \
2744+
\ represented directly using the `Status` message.\n\n- Logging. If some API\
2745+
\ errors are stored in logs, the message `Status` could\n be used directly\
2746+
\ after any stripping needed for security/privacy reasons."
2747+
example:
2748+
code: 0
2749+
details:
2750+
- typeUrl: "typeUrl"
2751+
value: "value"
2752+
- typeUrl: "typeUrl"
2753+
value: "value"
2754+
message: "message"
26632755
subStringMessage:
26642756
type: "object"
26652757
properties:

examples/internal/clients/abe/api_a_bit_of_everything_service.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,149 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCheckPostQuer
10861086
return localVarReturnValue, localVarHttpResponse, nil
10871087
}
10881088

1089+
/*
1090+
ABitOfEverythingServiceApiService
1091+
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
1092+
1093+
@return ExamplepbCheckStatusResponse
1094+
*/
1095+
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCheckStatus(ctx context.Context) (ExamplepbCheckStatusResponse, *http.Response, error) {
1096+
var (
1097+
localVarHttpMethod = strings.ToUpper("Get")
1098+
localVarPostBody interface{}
1099+
localVarFileName string
1100+
localVarFileBytes []byte
1101+
localVarReturnValue ExamplepbCheckStatusResponse
1102+
)
1103+
1104+
// create path and map variables
1105+
localVarPath := a.client.cfg.BasePath + "/v1/example/checkStatus"
1106+
1107+
localVarHeaderParams := make(map[string]string)
1108+
localVarQueryParams := url.Values{}
1109+
localVarFormParams := url.Values{}
1110+
1111+
// to determine the Content-Type header
1112+
localVarHttpContentTypes := []string{"application/json", "application/x-foo-mime"}
1113+
1114+
// set Content-Type header
1115+
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
1116+
if localVarHttpContentType != "" {
1117+
localVarHeaderParams["Content-Type"] = localVarHttpContentType
1118+
}
1119+
1120+
// to determine the Accept header
1121+
localVarHttpHeaderAccepts := []string{"application/json", "application/x-foo-mime"}
1122+
1123+
// set Accept header
1124+
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
1125+
if localVarHttpHeaderAccept != "" {
1126+
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
1127+
}
1128+
if ctx != nil {
1129+
// API Key Authentication
1130+
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
1131+
var key string
1132+
if auth.Prefix != "" {
1133+
key = auth.Prefix + " " + auth.Key
1134+
} else {
1135+
key = auth.Key
1136+
}
1137+
localVarHeaderParams["X-API-Key"] = key
1138+
1139+
}
1140+
}
1141+
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
1142+
if err != nil {
1143+
return localVarReturnValue, nil, err
1144+
}
1145+
1146+
localVarHttpResponse, err := a.client.callAPI(r)
1147+
if err != nil || localVarHttpResponse == nil {
1148+
return localVarReturnValue, localVarHttpResponse, err
1149+
}
1150+
1151+
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
1152+
localVarHttpResponse.Body.Close()
1153+
if err != nil {
1154+
return localVarReturnValue, localVarHttpResponse, err
1155+
}
1156+
1157+
if localVarHttpResponse.StatusCode < 300 {
1158+
// If we succeed, return the data, otherwise pass on to decode error.
1159+
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1160+
if err == nil {
1161+
return localVarReturnValue, localVarHttpResponse, err
1162+
}
1163+
}
1164+
1165+
if localVarHttpResponse.StatusCode >= 300 {
1166+
newErr := GenericSwaggerError{
1167+
body: localVarBody,
1168+
error: localVarHttpResponse.Status,
1169+
}
1170+
1171+
if localVarHttpResponse.StatusCode == 200 {
1172+
var v ExamplepbCheckStatusResponse
1173+
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1174+
if err != nil {
1175+
newErr.error = err.Error()
1176+
return localVarReturnValue, localVarHttpResponse, newErr
1177+
}
1178+
newErr.model = v
1179+
return localVarReturnValue, localVarHttpResponse, newErr
1180+
}
1181+
1182+
if localVarHttpResponse.StatusCode == 403 {
1183+
var v interface{}
1184+
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1185+
if err != nil {
1186+
newErr.error = err.Error()
1187+
return localVarReturnValue, localVarHttpResponse, newErr
1188+
}
1189+
newErr.model = v
1190+
return localVarReturnValue, localVarHttpResponse, newErr
1191+
}
1192+
1193+
if localVarHttpResponse.StatusCode == 404 {
1194+
var v string
1195+
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1196+
if err != nil {
1197+
newErr.error = err.Error()
1198+
return localVarReturnValue, localVarHttpResponse, newErr
1199+
}
1200+
newErr.model = v
1201+
return localVarReturnValue, localVarHttpResponse, newErr
1202+
}
1203+
1204+
if localVarHttpResponse.StatusCode == 418 {
1205+
var v ExamplepbNumericEnum
1206+
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1207+
if err != nil {
1208+
newErr.error = err.Error()
1209+
return localVarReturnValue, localVarHttpResponse, newErr
1210+
}
1211+
newErr.model = v
1212+
return localVarReturnValue, localVarHttpResponse, newErr
1213+
}
1214+
1215+
if localVarHttpResponse.StatusCode == 0 {
1216+
var v RpcStatus
1217+
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
1218+
if err != nil {
1219+
newErr.error = err.Error()
1220+
return localVarReturnValue, localVarHttpResponse, newErr
1221+
}
1222+
newErr.model = v
1223+
return localVarReturnValue, localVarHttpResponse, newErr
1224+
}
1225+
1226+
return localVarReturnValue, localVarHttpResponse, newErr
1227+
}
1228+
1229+
return localVarReturnValue, localVarHttpResponse, nil
1230+
}
1231+
10891232
/*
10901233
ABitOfEverythingServiceApiService Create a new ABitOfEverything
10911234
This API creates a new ABitOfEverything
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* A Bit of Everything
3+
*
4+
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5+
*
6+
* API version: 1.0
7+
* Contact: [email protected]
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package abe
12+
13+
type ExamplepbCheckStatusResponse struct {
14+
Status *RpcStatus `json:"status,omitempty"`
15+
}

examples/internal/clients/abe/model_rpc_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
package abe
1212

13+
// - Simple to use and understand for most users - Flexible enough to meet unexpected needs # Overview The `Status` message contains three pieces of data: error code, error message, and error details. The error code should be an enum value of [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The error message should be a developer-facing English message that helps developers *understand* and *resolve* the error. If a localized user-facing error message is needed, put the localized message in the error details or localize it in the client. The optional error details may contain arbitrary information about the error. There is a predefined set of error detail types in the package `google.rpc` that can be used for common error conditions. # Language mapping The `Status` message is the logical representation of the error model, but it is not necessarily the actual wire format. When the `Status` message is exposed in different client libraries and different wire protocols, it can be mapped differently. For example, it will likely be mapped to some exceptions in Java, but more likely mapped to some error codes in C. # Other uses The error model and the `Status` message can be used in a variety of environments, either with or without APIs, to provide a consistent developer experience across different environments. Example uses of this error model include: - Partial errors. If a service needs to return partial errors to the client, it may embed the `Status` in the normal response to indicate the partial errors. - Workflow errors. A typical workflow has multiple steps. Each step may have a `Status` message for error reporting. - Batch operations. If a client uses batch request and batch response, the `Status` message should be used directly inside batch response, one for each error sub-response. - Asynchronous operations. If an API call embeds asynchronous operation results in its response, the status of those operations should be represented directly using the `Status` message. - Logging. If some API errors are stored in logs, the message `Status` could be used directly after any stripping needed for security/privacy reasons.
1314
type RpcStatus struct {
15+
// The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
1416
Code int32 `json:"code,omitempty"`
17+
// A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
1518
Message string `json:"message,omitempty"`
19+
// A list of messages that carry the error details. There is a common set of message types for APIs to use.
1620
Details []ProtobufAny `json:"details,omitempty"`
1721
}

examples/internal/clients/echo/api/swagger.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,48 @@ definitions:
596596
code:
597597
type: "integer"
598598
format: "int32"
599+
description: "The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]."
599600
message:
600601
type: "string"
602+
description: "A developer-facing error message, which should be in English.\
603+
\ Any\nuser-facing error message should be localized and sent in the\n[google.rpc.Status.details][google.rpc.Status.details]\
604+
\ field, or localized by the client."
601605
details:
602606
type: "array"
607+
description: "A list of messages that carry the error details. There is a\
608+
\ common set of\nmessage types for APIs to use."
603609
items:
604610
$ref: "#/definitions/protobufAny"
611+
title: "The `Status` type defines a logical error model that is suitable for different\n\
612+
programming environments, including REST APIs and RPC APIs. It is used by\n\
613+
[gRPC](https://github.com/grpc). The error model is designed to be:"
614+
description: "- Simple to use and understand for most users\n- Flexible enough\
615+
\ to meet unexpected needs\n\n# Overview\n\nThe `Status` message contains three\
616+
\ pieces of data: error code, error message,\nand error details. The error code\
617+
\ should be an enum value of\n[google.rpc.Code][google.rpc.Code], but it may\
618+
\ accept additional error codes if needed. The\nerror message should be a developer-facing\
619+
\ English message that helps\ndevelopers *understand* and *resolve* the error.\
620+
\ If a localized user-facing\nerror message is needed, put the localized message\
621+
\ in the error details or\nlocalize it in the client. The optional error details\
622+
\ may contain arbitrary\ninformation about the error. There is a predefined\
623+
\ set of error detail types\nin the package `google.rpc` that can be used for\
624+
\ common error conditions.\n\n# Language mapping\n\nThe `Status` message is\
625+
\ the logical representation of the error model, but it\nis not necessarily\
626+
\ the actual wire format. When the `Status` message is\nexposed in different\
627+
\ client libraries and different wire protocols, it can be\nmapped differently.\
628+
\ For example, it will likely be mapped to some exceptions\nin Java, but more\
629+
\ likely mapped to some error codes in C.\n\n# Other uses\n\nThe error model\
630+
\ and the `Status` message can be used in a variety of\nenvironments, either\
631+
\ with or without APIs, to provide a\nconsistent developer experience across\
632+
\ different environments.\n\nExample uses of this error model include:\n\n-\
633+
\ Partial errors. If a service needs to return partial errors to the client,\n\
634+
\ it may embed the `Status` in the normal response to indicate the partial\n\
635+
\ errors.\n\n- Workflow errors. A typical workflow has multiple steps. Each\
636+
\ step may\n have a `Status` message for error reporting.\n\n- Batch operations.\
637+
\ If a client uses batch request and batch response, the\n `Status` message\
638+
\ should be used directly inside batch response, one for\n each error sub-response.\n\
639+
\n- Asynchronous operations. If an API call embeds asynchronous operation\n\
640+
\ results in its response, the status of those operations should be\n \
641+
\ represented directly using the `Status` message.\n\n- Logging. If some API\
642+
\ errors are stored in logs, the message `Status` could\n be used directly\
643+
\ after any stripping needed for security/privacy reasons."

0 commit comments

Comments
 (0)