Skip to content

Commit

Permalink
protoc-gen-swagger: Implement Response Header(s) object (#1730)
Browse files Browse the repository at this point in the history
* 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 <johan.brandhorst@gmail.com>

* Update protoc-gen-swagger/genswagger/template.go

fix: remove string comparisons

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* fix: resolving MR requests

* fix: unqouting error

* Update protoc-gen-swagger/genswagger/template.go

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* Update protoc-gen-swagger/genswagger/template.go

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* 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 <johan.brandhorst@gmail.com>
  • Loading branch information
elijah-roberts and johanbrandhorst authored Oct 28, 2020
1 parent cfb0a30 commit e0a026a
Show file tree
Hide file tree
Showing 19 changed files with 2,162 additions and 417 deletions.
2 changes: 2 additions & 0 deletions examples/internal/clients/abe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ go_library(
"model_examplepb_a_bit_of_everything_repeated.go",
"model_examplepb_body.go",
"model_examplepb_book.go",
"model_examplepb_error_object.go",
"model_examplepb_error_response.go",
"model_examplepb_numeric_enum.go",
"model_examplepb_update_v2_request.go",
"model_message_path_enum_nested_path_enum.go",
Expand Down
125 changes: 125 additions & 0 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -97,6 +101,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
503:
description: "Returned when the resource is temporarily unavailable."
schema: {}
Expand Down Expand Up @@ -391,6 +399,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -685,6 +697,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -966,6 +982,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1266,6 +1286,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1423,6 +1447,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1463,6 +1491,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1496,6 +1528,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1533,6 +1569,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1564,6 +1604,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1760,6 +1804,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1811,6 +1859,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1858,6 +1910,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1904,6 +1960,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -1943,6 +2003,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
503:
description: "Returned when the resource is temporarily unavailable."
schema: {}
Expand Down Expand Up @@ -1988,6 +2052,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
503:
description: "Returned when the resource is temporarily unavailable."
schema: {}
Expand Down Expand Up @@ -2022,6 +2090,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2049,6 +2121,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2079,6 +2155,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2117,6 +2197,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2144,6 +2228,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2182,6 +2270,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2217,6 +2309,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2255,6 +2351,10 @@ paths:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
Expand Down Expand Up @@ -2566,6 +2666,31 @@ definitions:
create_time: "2000-01-23T04:56:07.000+00:00"
name: "name"
id: "id"
examplepbErrorObject:
type: "object"
properties:
code:
type: "integer"
format: "integer"
description: "Response code"
title: "code"
message:
type: "string"
description: "Response message"
title: "message"
pattern: "^[a-zA-Z0-9]{1, 32}$"
examplepbErrorResponse:
type: "object"
properties:
correlationId:
type: "string"
format: "uuid"
example: "2438ac3c-37eb-4902-adef-ed16b4431030"
description: "Unique event identifier for server requests"
title: "x-correlation-id"
pattern: "^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
error:
$ref: "#/definitions/examplepbErrorObject"
examplepbNumericEnum:
type: "string"
description: "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE\
Expand Down
Loading

0 comments on commit e0a026a

Please sign in to comment.