Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support oneof fields in body #634

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ ECHO_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/echo/api_client.go \
$(EXAMPLE_CLIENT_DIR)/echo/api_response.go \
$(EXAMPLE_CLIENT_DIR)/echo/configuration.go \
$(EXAMPLE_CLIENT_DIR)/echo/echo_service_api.go \
$(EXAMPLE_CLIENT_DIR)/echo/examplepb_simple_message.go \
$(EXAMPLE_CLIENT_DIR)/echo/examplepb_embedded.go
$(EXAMPLE_CLIENT_DIR)/echo/examplepb_simple_message.go
ABE_EXAMPLE_SPEC=examples/proto/examplepb/a_bit_of_everything.swagger.json
ABE_EXAMPLE_SRCS=$(EXAMPLE_CLIENT_DIR)/abe/a_bit_of_everything_nested.go \
$(EXAMPLE_CLIENT_DIR)/abe/a_bit_of_everything_service_api.go \
Expand Down
3 changes: 2 additions & 1 deletion examples/browser/a_bit_of_everything_service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('ABitOfEverythingService', function() {
sfixed64_value: "-4611686018427387904",
sint32_value: 2147483647,
sint64_value: "4611686018427387903",
oneof_value_string: "foo",
nonConventionalNameValue: "camelCase",
};

Expand Down Expand Up @@ -78,7 +79,7 @@ describe('ABitOfEverythingService', function() {
{ name: "baz", amount: 20 },
],
repeated_string_value: ["a", "b", "c"],
oneof_string: "x",
oneof_value_string: "x",
// TODO(yugui) Support enum by name
map_value: { a: 1, b: 2 },
mapped_string_value: { a: "x", b: "y" },
Expand Down
7 changes: 6 additions & 1 deletion examples/clients/abe/a_bit_of_everything_nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package abe

// Nested is nested type.
type ABitOfEverythingNested struct {

// name is nested field.
Expand All @@ -19,4 +18,10 @@ type ABitOfEverythingNested struct {
Amount int64 `json:"amount,omitempty"`

Ok NestedDeepEnum `json:"ok,omitempty"`

DeeperNestedValue SubStringMessage `json:"deeper_nested_value,omitempty"`

OneofValueDeeperNested SubStringMessage `json:"oneof_value_deeper_nested,omitempty"`

OneofValueTerminal string `json:"oneof_value_terminal,omitempty"`
}
718 changes: 711 additions & 7 deletions examples/clients/abe/a_bit_of_everything_service_api.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/clients/abe/examplepb_a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ type ExamplepbABitOfEverything struct {

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

OneofEmpty ProtobufEmpty `json:"oneof_empty,omitempty"`
OneofValueString string `json:"oneof_value_string,omitempty"`

OneofString string `json:"oneof_string,omitempty"`
OneofValueNested ABitOfEverythingNested `json:"oneof_value_nested,omitempty"`

MapValue map[string]ExamplepbNumericEnum `json:"map_value,omitempty"`

Expand Down
1 change: 0 additions & 1 deletion examples/clients/echo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
"api_response.go",
"configuration.go",
"echo_service_api.go",
"examplepb_embedded.go",
"examplepb_simple_message.go",
],
importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo",
Expand Down
259 changes: 2 additions & 257 deletions examples/clients/echo/echo_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,9 @@ func (a EchoServiceApi) Echo(id string) (*ExamplepbSimpleMessage, *APIResponse,
*
* @param id
* @param num
* @param lineNum
* @param lang
* @param statusProgress
* @param statusNote
* @param en
* @param noProgress
* @param noNote
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) Echo2(id string, num string, lineNum string, lang string, statusProgress string, statusNote string, en string, noProgress string, noNote string) (*ExamplepbSimpleMessage, *APIResponse, error) {
func (a EchoServiceApi) Echo2(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand All @@ -131,13 +124,6 @@ func (a EchoServiceApi) Echo2(id string, num string, lineNum string, lang string
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("line_num", a.Configuration.APIClient.ParameterToString(lineNum, ""))
localVarQueryParams.Add("lang", a.Configuration.APIClient.ParameterToString(lang, ""))
localVarQueryParams.Add("status.progress", a.Configuration.APIClient.ParameterToString(statusProgress, ""))
localVarQueryParams.Add("status.note", a.Configuration.APIClient.ParameterToString(statusNote, ""))
localVarQueryParams.Add("en", a.Configuration.APIClient.ParameterToString(en, ""))
localVarQueryParams.Add("no.progress", a.Configuration.APIClient.ParameterToString(noProgress, ""))
localVarQueryParams.Add("no.note", a.Configuration.APIClient.ParameterToString(noNote, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }
Expand Down Expand Up @@ -175,233 +161,6 @@ func (a EchoServiceApi) Echo2(id string, num string, lineNum string, lang string
return successPayload, localVarAPIResponse, err
}

/**
* Echo method receives a simple message and returns it.
* The message posted as the id parameter will also be returned.
*
* @param id
* @param num
* @param lang
* @param lineNum
* @param statusProgress
* @param statusNote
* @param en
* @param noProgress
* @param noNote
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) Echo3(id string, num string, lang string, lineNum string, statusProgress string, statusNote string, en string, noProgress string, noNote string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/v1/example/echo/{id}/{num}/{lang}"
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1)
localVarPath = strings.Replace(localVarPath, "{"+"num"+"}", fmt.Sprintf("%v", num), -1)
localVarPath = strings.Replace(localVarPath, "{"+"lang"+"}", fmt.Sprintf("%v", lang), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := make(map[string]string)
var localVarPostBody interface{}
var localVarFileName string
var localVarFileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("line_num", a.Configuration.APIClient.ParameterToString(lineNum, ""))
localVarQueryParams.Add("status.progress", a.Configuration.APIClient.ParameterToString(statusProgress, ""))
localVarQueryParams.Add("status.note", a.Configuration.APIClient.ParameterToString(statusNote, ""))
localVarQueryParams.Add("en", a.Configuration.APIClient.ParameterToString(en, ""))
localVarQueryParams.Add("no.progress", a.Configuration.APIClient.ParameterToString(noProgress, ""))
localVarQueryParams.Add("no.note", a.Configuration.APIClient.ParameterToString(noNote, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }

// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
}

// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ExamplepbSimpleMessage)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
localVarURL.RawQuery = localVarQueryParams.Encode()
var localVarAPIResponse = &APIResponse{Operation: "Echo3", Method: localVarHttpMethod, RequestURL: localVarURL.String()}
if localVarHttpResponse != nil {
localVarAPIResponse.Response = localVarHttpResponse.RawResponse
localVarAPIResponse.Payload = localVarHttpResponse.Body()
}

if err != nil {
return successPayload, localVarAPIResponse, err
}
err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload)
return successPayload, localVarAPIResponse, err
}

/**
* Echo method receives a simple message and returns it.
* The message posted as the id parameter will also be returned.
*
* @param id
* @param lineNum
* @param statusNote
* @param num
* @param lang
* @param statusProgress
* @param en
* @param noProgress
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) Echo4(id string, lineNum string, statusNote string, num string, lang string, statusProgress string, en string, noProgress string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/v1/example/echo1/{id}/{line_num}/{status.note}"
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", fmt.Sprintf("%v", id), -1)
localVarPath = strings.Replace(localVarPath, "{"+"line_num"+"}", fmt.Sprintf("%v", lineNum), -1)
localVarPath = strings.Replace(localVarPath, "{"+"status.note"+"}", fmt.Sprintf("%v", statusNote), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := make(map[string]string)
var localVarPostBody interface{}
var localVarFileName string
var localVarFileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("num", a.Configuration.APIClient.ParameterToString(num, ""))
localVarQueryParams.Add("lang", a.Configuration.APIClient.ParameterToString(lang, ""))
localVarQueryParams.Add("status.progress", a.Configuration.APIClient.ParameterToString(statusProgress, ""))
localVarQueryParams.Add("en", a.Configuration.APIClient.ParameterToString(en, ""))
localVarQueryParams.Add("no.progress", a.Configuration.APIClient.ParameterToString(noProgress, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }

// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
}

// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ExamplepbSimpleMessage)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
localVarURL.RawQuery = localVarQueryParams.Encode()
var localVarAPIResponse = &APIResponse{Operation: "Echo4", Method: localVarHttpMethod, RequestURL: localVarURL.String()}
if localVarHttpResponse != nil {
localVarAPIResponse.Response = localVarHttpResponse.RawResponse
localVarAPIResponse.Payload = localVarHttpResponse.Body()
}

if err != nil {
return successPayload, localVarAPIResponse, err
}
err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload)
return successPayload, localVarAPIResponse, err
}

/**
* Echo method receives a simple message and returns it.
* The message posted as the id parameter will also be returned.
*
* @param noNote
* @param id Id represents the message identifier.
* @param num
* @param lineNum
* @param lang
* @param statusProgress
* @param en
* @param noProgress
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) Echo5(noNote string, id string, num string, lineNum string, lang string, statusProgress string, en string, noProgress string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/v1/example/echo2/{no.note}"
localVarPath = strings.Replace(localVarPath, "{"+"no.note"+"}", fmt.Sprintf("%v", noNote), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := make(map[string]string)
var localVarPostBody interface{}
var localVarFileName string
var localVarFileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("id", a.Configuration.APIClient.ParameterToString(id, ""))
localVarQueryParams.Add("num", a.Configuration.APIClient.ParameterToString(num, ""))
localVarQueryParams.Add("line_num", a.Configuration.APIClient.ParameterToString(lineNum, ""))
localVarQueryParams.Add("lang", a.Configuration.APIClient.ParameterToString(lang, ""))
localVarQueryParams.Add("status.progress", a.Configuration.APIClient.ParameterToString(statusProgress, ""))
localVarQueryParams.Add("en", a.Configuration.APIClient.ParameterToString(en, ""))
localVarQueryParams.Add("no.progress", a.Configuration.APIClient.ParameterToString(noProgress, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }

// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
}

// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ExamplepbSimpleMessage)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
localVarURL.RawQuery = localVarQueryParams.Encode()
var localVarAPIResponse = &APIResponse{Operation: "Echo5", Method: localVarHttpMethod, RequestURL: localVarURL.String()}
if localVarHttpResponse != nil {
localVarAPIResponse.Response = localVarHttpResponse.RawResponse
localVarAPIResponse.Payload = localVarHttpResponse.Body()
}

if err != nil {
return successPayload, localVarAPIResponse, err
}
err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload)
return successPayload, localVarAPIResponse, err
}

/**
* EchoBody method receives a simple message and returns it.
*
Expand Down Expand Up @@ -468,16 +227,9 @@ func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleM
*
* @param id Id represents the message identifier.
* @param num
* @param lineNum
* @param lang
* @param statusProgress
* @param statusNote
* @param en
* @param noProgress
* @param noNote
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) EchoDelete(id string, num string, lineNum string, lang string, statusProgress string, statusNote string, en string, noProgress string, noNote string) (*ExamplepbSimpleMessage, *APIResponse, error) {
func (a EchoServiceApi) EchoDelete(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Delete")
// create path and map variables
Expand All @@ -495,13 +247,6 @@ func (a EchoServiceApi) EchoDelete(id string, num string, lineNum string, lang s
}
localVarQueryParams.Add("id", a.Configuration.APIClient.ParameterToString(id, ""))
localVarQueryParams.Add("num", a.Configuration.APIClient.ParameterToString(num, ""))
localVarQueryParams.Add("line_num", a.Configuration.APIClient.ParameterToString(lineNum, ""))
localVarQueryParams.Add("lang", a.Configuration.APIClient.ParameterToString(lang, ""))
localVarQueryParams.Add("status.progress", a.Configuration.APIClient.ParameterToString(statusProgress, ""))
localVarQueryParams.Add("status.note", a.Configuration.APIClient.ParameterToString(statusNote, ""))
localVarQueryParams.Add("en", a.Configuration.APIClient.ParameterToString(en, ""))
localVarQueryParams.Add("no.progress", a.Configuration.APIClient.ParameterToString(noProgress, ""))
localVarQueryParams.Add("no.note", a.Configuration.APIClient.ParameterToString(noNote, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }
Expand Down
19 changes: 0 additions & 19 deletions examples/clients/echo/examplepb_embedded.go

This file was deleted.

10 changes: 0 additions & 10 deletions examples/clients/echo/examplepb_simple_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,4 @@ type ExamplepbSimpleMessage struct {
Id string `json:"id,omitempty"`

Num string `json:"num,omitempty"`

LineNum string `json:"line_num,omitempty"`

Lang string `json:"lang,omitempty"`

Status ExamplepbEmbedded `json:"status,omitempty"`

En string `json:"en,omitempty"`

No ExamplepbEmbedded `json:"no,omitempty"`
}
Loading