Skip to content

Commit

Permalink
Swagger-gen: Major overhaul of well-known-type handling
Browse files Browse the repository at this point in the history
- swaggerSchemaObject.Properties is now optional (pointer), because
  google.protobuf.Empty requires us to set Properties{} instead of nil, because
  this equals in Swagger to an empty JSON object (which is exactly what Empty
  represents and how the gateway treats it). If it's not a pointer, we can't
  distinguish between "not set" (in most cases, we don't want Properties to be
  set, instead usually just .Ref is set), and "set to an empty value e.g.
  Properties{} with length 0). We don't want Properties{} to occur except for
  specific cases, e.g. for Empty.
- Wrappers and Empty are not rendered as definitions, now also for RPC Method
  input/output. instead, all necessary schema information is provided "in-line"
  via schema.type and schema.properties.
- Empty is now omitted as well if it's input/output of a RPC Method.
  • Loading branch information
birdayz committed Nov 17, 2018
1 parent 09679ff commit e8c93a5
Show file tree
Hide file tree
Showing 13 changed files with 1,180 additions and 120 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ ABE_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/abe/a_bit_of_everything_nested.go \
$(EXAMPLE_CLIENT_DIR)/abe/examplepb_body.go \
$(EXAMPLE_CLIENT_DIR)/abe/examplepb_numeric_enum.go \
$(EXAMPLE_CLIENT_DIR)/abe/nested_deep_enum.go \
$(EXAMPLE_CLIENT_DIR)/abe/protobuf_empty.go \
$(EXAMPLE_CLIENT_DIR)/abe/sub_string_message.go
UNANNOTATED_ECHO_EXAMPLE_SPEC=examples/proto/examplepb/unannotated_echo_service.swagger.json
UNANNOTATED_ECHO_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/unannotatedecho/api_client.go \
Expand Down
1 change: 0 additions & 1 deletion examples/clients/abe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
"message_path_enum_nested_path_enum.go",
"nested_deep_enum.go",
"pathenum_path_enum.go",
"protobuf_empty.go",
"sub_string_message.go",
],
importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe",
Expand Down
42 changes: 21 additions & 21 deletions examples/clients/abe/a_bit_of_everything_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ func (a ABitOfEverythingServiceApi) DeepPathEcho(singleNestedName string, body E
*
*
* @param uuid
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) Delete(uuid string) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Delete")
// create path and map variables
Expand Down Expand Up @@ -350,7 +350,7 @@ func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIRes
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand All @@ -371,9 +371,9 @@ func (a ABitOfEverythingServiceApi) Delete(uuid string) (*ProtobufEmpty, *APIRes
/**
*
*
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) ErrorWithDetails() (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) ErrorWithDetails() (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down Expand Up @@ -422,7 +422,7 @@ func (a ABitOfEverythingServiceApi) ErrorWithDetails() (*ProtobufEmpty, *APIResp
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand All @@ -445,9 +445,9 @@ func (a ABitOfEverythingServiceApi) ErrorWithDetails() (*ProtobufEmpty, *APIResp
*
* @param id
* @param body
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body ExamplepbBody) (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body ExamplepbBody) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Post")
// create path and map variables
Expand Down Expand Up @@ -499,7 +499,7 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
}
// body params
localVarPostBody = &body
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand Down Expand Up @@ -547,9 +547,9 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
* @param nonConventionalNameValue
* @param timestampValue
* @param repeatedEnumValue repeated enum value. it is comma-separated in query. - ZERO: ZERO means 0 - ONE: ONE means 1
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, bytesValue string, uint32Value int64, enumValue string, pathEnumValue string, nestedPathEnumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName string, singleNestedAmount int64, singleNestedOk string, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, bytesValue string, uint32Value int64, enumValue string, pathEnumValue string, nestedPathEnumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down Expand Up @@ -616,7 +616,7 @@ func (a ABitOfEverythingServiceApi) GetQuery(uuid string, singleNestedName strin
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand Down Expand Up @@ -817,9 +817,9 @@ func (a ABitOfEverythingServiceApi) Lookup(uuid string) (*ExamplepbABitOfEveryth
*
* @param name
* @param body
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) PostWithEmptyBody(name string, body ExamplepbBody) (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) PostWithEmptyBody(name string, body ExamplepbBody) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Post")
// create path and map variables
Expand Down Expand Up @@ -871,7 +871,7 @@ func (a ABitOfEverythingServiceApi) PostWithEmptyBody(name string, body Examplep
}
// body params
localVarPostBody = &body
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand All @@ -892,9 +892,9 @@ func (a ABitOfEverythingServiceApi) PostWithEmptyBody(name string, body Examplep
/**
*
*
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) Timeout() (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down Expand Up @@ -943,7 +943,7 @@ func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, err
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand All @@ -966,9 +966,9 @@ func (a ABitOfEverythingServiceApi) Timeout() (*ProtobufEmpty, *APIResponse, err
*
* @param uuid
* @param body
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEverything) (*ProtobufEmpty, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEverything) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Put")
// create path and map variables
Expand Down Expand Up @@ -1020,7 +1020,7 @@ func (a ABitOfEverythingServiceApi) Update(uuid string, body ExamplepbABitOfEver
}
// body params
localVarPostBody = &body
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand Down
6 changes: 3 additions & 3 deletions examples/clients/abe/camel_case_service_name_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func NewCamelCaseServiceNameApiWithBasePath(basePath string) *CamelCaseServiceNa
* Create a new ABitOfEverything
* This API creates a new ABitOfEverything
*
* @return *ProtobufEmpty
* @return *interface{}
*/
func (a CamelCaseServiceNameApi) Empty() (*ProtobufEmpty, *APIResponse, error) {
func (a CamelCaseServiceNameApi) Empty() (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down Expand Up @@ -91,7 +91,7 @@ func (a CamelCaseServiceNameApi) Empty() (*ProtobufEmpty, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ProtobufEmpty)
var successPayload = new(interface{})
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
Expand Down
2 changes: 1 addition & 1 deletion examples/clients/abe/examplepb_a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ExamplepbABitOfEverything struct {

RepeatedStringValue []string `json:"repeated_string_value,omitempty"`

OneofEmpty ProtobufEmpty `json:"oneof_empty,omitempty"`
OneofEmpty interface{} `json:"oneof_empty,omitempty"`

OneofString string `json:"oneof_string,omitempty"`

Expand Down
15 changes: 0 additions & 15 deletions examples/clients/abe/protobuf_empty.go

This file was deleted.

23 changes: 9 additions & 14 deletions examples/proto/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -636,7 +636,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -683,7 +683,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1066,7 +1066,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1098,7 +1098,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1130,7 +1130,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1178,7 +1178,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1210,7 +1210,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
}
},
"403": {
Expand Down Expand Up @@ -1379,7 +1379,7 @@
}
},
"oneof_empty": {
"$ref": "#/definitions/protobufEmpty"
"properties": {}
},
"oneof_string": {
"type": "string"
Expand Down Expand Up @@ -1569,11 +1569,6 @@
],
"default": "ABC"
},
"protobufEmpty": {
"type": "object",
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
"title": "A generic empty message that you can re-use to avoid defining duplicated\nempty messages in your APIs. A typical example is to use it as the request\nor the response type of an API method. For instance:"
},
"subStringMessage": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit e8c93a5

Please sign in to comment.