Skip to content

Commit e0a026a

Browse files
protoc-gen-swagger: Implement Response Header(s) object (#1730)
* feat: protoc-gen-swagger: Implement Response Header(s) object, Implement Field Enum,Example&Format attributes #1729 * fix: resolve linting errors * fix: running per CI * fix: Resolve PR requests * a bunch of whitespace/format changes... have since added this to my IDE * remove any.Any objects, and convert them to string * move runtime regex strings to global variables * update examples * update tests * fix: Running go mode tidy to cleanup go.mod and go.sum * fix: Resolving PR comments * remove regex logic, and update functions to use simple booleans * cleanup example proto * enforce CanonicalMIMEHeaderKey for header name * Update protoc-gen-swagger/genswagger/template.go simplifying string check Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]> * Update protoc-gen-swagger/genswagger/template.go fix: remove string comparisons Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]> * fix: resolving MR requests * fix: unqouting error * Update protoc-gen-swagger/genswagger/template.go Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]> * Update protoc-gen-swagger/genswagger/template.go Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]> * fix: adding requested changes * parse unsigned ints with strconv.ParseUint * update unqoute logic * Updating integer switch * Minor nits * Remove extra newlines Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]>
1 parent cfb0a30 commit e0a026a

19 files changed

+2162
-417
lines changed

examples/internal/clients/abe/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ go_library(
1616
"model_examplepb_a_bit_of_everything_repeated.go",
1717
"model_examplepb_body.go",
1818
"model_examplepb_book.go",
19+
"model_examplepb_error_object.go",
20+
"model_examplepb_error_response.go",
1921
"model_examplepb_numeric_enum.go",
2022
"model_examplepb_update_v2_request.go",
2123
"model_message_path_enum_nested_path_enum.go",

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

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ paths:
5959
description: "I'm a teapot."
6060
schema:
6161
$ref: "#/definitions/examplepbNumericEnum"
62+
500:
63+
description: "Server error"
64+
schema:
65+
$ref: "#/definitions/examplepbErrorResponse"
6266
default:
6367
description: "An unexpected error response."
6468
schema:
@@ -97,6 +101,10 @@ paths:
97101
description: "I'm a teapot."
98102
schema:
99103
$ref: "#/definitions/examplepbNumericEnum"
104+
500:
105+
description: "Server error"
106+
schema:
107+
$ref: "#/definitions/examplepbErrorResponse"
100108
503:
101109
description: "Returned when the resource is temporarily unavailable."
102110
schema: {}
@@ -391,6 +399,10 @@ paths:
391399
description: "I'm a teapot."
392400
schema:
393401
$ref: "#/definitions/examplepbNumericEnum"
402+
500:
403+
description: "Server error"
404+
schema:
405+
$ref: "#/definitions/examplepbErrorResponse"
394406
default:
395407
description: "An unexpected error response."
396408
schema:
@@ -685,6 +697,10 @@ paths:
685697
description: "I'm a teapot."
686698
schema:
687699
$ref: "#/definitions/examplepbNumericEnum"
700+
500:
701+
description: "Server error"
702+
schema:
703+
$ref: "#/definitions/examplepbErrorResponse"
688704
default:
689705
description: "An unexpected error response."
690706
schema:
@@ -966,6 +982,10 @@ paths:
966982
description: "I'm a teapot."
967983
schema:
968984
$ref: "#/definitions/examplepbNumericEnum"
985+
500:
986+
description: "Server error"
987+
schema:
988+
$ref: "#/definitions/examplepbErrorResponse"
969989
default:
970990
description: "An unexpected error response."
971991
schema:
@@ -1266,6 +1286,10 @@ paths:
12661286
description: "I'm a teapot."
12671287
schema:
12681288
$ref: "#/definitions/examplepbNumericEnum"
1289+
500:
1290+
description: "Server error"
1291+
schema:
1292+
$ref: "#/definitions/examplepbErrorResponse"
12691293
default:
12701294
description: "An unexpected error response."
12711295
schema:
@@ -1423,6 +1447,10 @@ paths:
14231447
description: "I'm a teapot."
14241448
schema:
14251449
$ref: "#/definitions/examplepbNumericEnum"
1450+
500:
1451+
description: "Server error"
1452+
schema:
1453+
$ref: "#/definitions/examplepbErrorResponse"
14261454
default:
14271455
description: "An unexpected error response."
14281456
schema:
@@ -1463,6 +1491,10 @@ paths:
14631491
description: "I'm a teapot."
14641492
schema:
14651493
$ref: "#/definitions/examplepbNumericEnum"
1494+
500:
1495+
description: "Server error"
1496+
schema:
1497+
$ref: "#/definitions/examplepbErrorResponse"
14661498
default:
14671499
description: "An unexpected error response."
14681500
schema:
@@ -1496,6 +1528,10 @@ paths:
14961528
description: "I'm a teapot."
14971529
schema:
14981530
$ref: "#/definitions/examplepbNumericEnum"
1531+
500:
1532+
description: "Server error"
1533+
schema:
1534+
$ref: "#/definitions/examplepbErrorResponse"
14991535
default:
15001536
description: "An unexpected error response."
15011537
schema:
@@ -1533,6 +1569,10 @@ paths:
15331569
description: "I'm a teapot."
15341570
schema:
15351571
$ref: "#/definitions/examplepbNumericEnum"
1572+
500:
1573+
description: "Server error"
1574+
schema:
1575+
$ref: "#/definitions/examplepbErrorResponse"
15361576
default:
15371577
description: "An unexpected error response."
15381578
schema:
@@ -1564,6 +1604,10 @@ paths:
15641604
description: "I'm a teapot."
15651605
schema:
15661606
$ref: "#/definitions/examplepbNumericEnum"
1607+
500:
1608+
description: "Server error"
1609+
schema:
1610+
$ref: "#/definitions/examplepbErrorResponse"
15671611
default:
15681612
description: "An unexpected error response."
15691613
schema:
@@ -1760,6 +1804,10 @@ paths:
17601804
description: "I'm a teapot."
17611805
schema:
17621806
$ref: "#/definitions/examplepbNumericEnum"
1807+
500:
1808+
description: "Server error"
1809+
schema:
1810+
$ref: "#/definitions/examplepbErrorResponse"
17631811
default:
17641812
description: "An unexpected error response."
17651813
schema:
@@ -1811,6 +1859,10 @@ paths:
18111859
description: "I'm a teapot."
18121860
schema:
18131861
$ref: "#/definitions/examplepbNumericEnum"
1862+
500:
1863+
description: "Server error"
1864+
schema:
1865+
$ref: "#/definitions/examplepbErrorResponse"
18141866
default:
18151867
description: "An unexpected error response."
18161868
schema:
@@ -1858,6 +1910,10 @@ paths:
18581910
description: "I'm a teapot."
18591911
schema:
18601912
$ref: "#/definitions/examplepbNumericEnum"
1913+
500:
1914+
description: "Server error"
1915+
schema:
1916+
$ref: "#/definitions/examplepbErrorResponse"
18611917
default:
18621918
description: "An unexpected error response."
18631919
schema:
@@ -1904,6 +1960,10 @@ paths:
19041960
description: "I'm a teapot."
19051961
schema:
19061962
$ref: "#/definitions/examplepbNumericEnum"
1963+
500:
1964+
description: "Server error"
1965+
schema:
1966+
$ref: "#/definitions/examplepbErrorResponse"
19071967
default:
19081968
description: "An unexpected error response."
19091969
schema:
@@ -1943,6 +2003,10 @@ paths:
19432003
description: "I'm a teapot."
19442004
schema:
19452005
$ref: "#/definitions/examplepbNumericEnum"
2006+
500:
2007+
description: "Server error"
2008+
schema:
2009+
$ref: "#/definitions/examplepbErrorResponse"
19462010
503:
19472011
description: "Returned when the resource is temporarily unavailable."
19482012
schema: {}
@@ -1988,6 +2052,10 @@ paths:
19882052
description: "I'm a teapot."
19892053
schema:
19902054
$ref: "#/definitions/examplepbNumericEnum"
2055+
500:
2056+
description: "Server error"
2057+
schema:
2058+
$ref: "#/definitions/examplepbErrorResponse"
19912059
503:
19922060
description: "Returned when the resource is temporarily unavailable."
19932061
schema: {}
@@ -2022,6 +2090,10 @@ paths:
20222090
description: "I'm a teapot."
20232091
schema:
20242092
$ref: "#/definitions/examplepbNumericEnum"
2093+
500:
2094+
description: "Server error"
2095+
schema:
2096+
$ref: "#/definitions/examplepbErrorResponse"
20252097
default:
20262098
description: "An unexpected error response."
20272099
schema:
@@ -2049,6 +2121,10 @@ paths:
20492121
description: "I'm a teapot."
20502122
schema:
20512123
$ref: "#/definitions/examplepbNumericEnum"
2124+
500:
2125+
description: "Server error"
2126+
schema:
2127+
$ref: "#/definitions/examplepbErrorResponse"
20522128
default:
20532129
description: "An unexpected error response."
20542130
schema:
@@ -2079,6 +2155,10 @@ paths:
20792155
description: "I'm a teapot."
20802156
schema:
20812157
$ref: "#/definitions/examplepbNumericEnum"
2158+
500:
2159+
description: "Server error"
2160+
schema:
2161+
$ref: "#/definitions/examplepbErrorResponse"
20822162
default:
20832163
description: "An unexpected error response."
20842164
schema:
@@ -2117,6 +2197,10 @@ paths:
21172197
description: "I'm a teapot."
21182198
schema:
21192199
$ref: "#/definitions/examplepbNumericEnum"
2200+
500:
2201+
description: "Server error"
2202+
schema:
2203+
$ref: "#/definitions/examplepbErrorResponse"
21202204
default:
21212205
description: "An unexpected error response."
21222206
schema:
@@ -2144,6 +2228,10 @@ paths:
21442228
description: "I'm a teapot."
21452229
schema:
21462230
$ref: "#/definitions/examplepbNumericEnum"
2231+
500:
2232+
description: "Server error"
2233+
schema:
2234+
$ref: "#/definitions/examplepbErrorResponse"
21472235
default:
21482236
description: "An unexpected error response."
21492237
schema:
@@ -2182,6 +2270,10 @@ paths:
21822270
description: "I'm a teapot."
21832271
schema:
21842272
$ref: "#/definitions/examplepbNumericEnum"
2273+
500:
2274+
description: "Server error"
2275+
schema:
2276+
$ref: "#/definitions/examplepbErrorResponse"
21852277
default:
21862278
description: "An unexpected error response."
21872279
schema:
@@ -2217,6 +2309,10 @@ paths:
22172309
description: "I'm a teapot."
22182310
schema:
22192311
$ref: "#/definitions/examplepbNumericEnum"
2312+
500:
2313+
description: "Server error"
2314+
schema:
2315+
$ref: "#/definitions/examplepbErrorResponse"
22202316
default:
22212317
description: "An unexpected error response."
22222318
schema:
@@ -2255,6 +2351,10 @@ paths:
22552351
description: "I'm a teapot."
22562352
schema:
22572353
$ref: "#/definitions/examplepbNumericEnum"
2354+
500:
2355+
description: "Server error"
2356+
schema:
2357+
$ref: "#/definitions/examplepbErrorResponse"
22582358
default:
22592359
description: "An unexpected error response."
22602360
schema:
@@ -2566,6 +2666,31 @@ definitions:
25662666
create_time: "2000-01-23T04:56:07.000+00:00"
25672667
name: "name"
25682668
id: "id"
2669+
examplepbErrorObject:
2670+
type: "object"
2671+
properties:
2672+
code:
2673+
type: "integer"
2674+
format: "integer"
2675+
description: "Response code"
2676+
title: "code"
2677+
message:
2678+
type: "string"
2679+
description: "Response message"
2680+
title: "message"
2681+
pattern: "^[a-zA-Z0-9]{1, 32}$"
2682+
examplepbErrorResponse:
2683+
type: "object"
2684+
properties:
2685+
correlationId:
2686+
type: "string"
2687+
format: "uuid"
2688+
example: "2438ac3c-37eb-4902-adef-ed16b4431030"
2689+
description: "Unique event identifier for server requests"
2690+
title: "x-correlation-id"
2691+
pattern: "^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
2692+
error:
2693+
$ref: "#/definitions/examplepbErrorObject"
25692694
examplepbNumericEnum:
25702695
type: "string"
25712696
description: "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE\

0 commit comments

Comments
 (0)