Skip to content

Commit

Permalink
Add an enum field to echo request and response (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
software-dov authored May 26, 2020
1 parent 00fe296 commit 4dd0c7c
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 175 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Temp directories
tmp/
dist/
coverage.txt
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"os"

statuspb "google.golang.org/genproto/googleapis/rpc/status"

"strings"
)

var EchoInput genprotopb.EchoRequest
Expand All @@ -30,6 +32,8 @@ var EchoInputResponseError genprotopb.EchoRequest_Error

var EchoInputResponseErrorDetails []string

var EchoInputSeverity string

func init() {
EchoServiceCmd.AddCommand(EchoCmd)

Expand All @@ -43,6 +47,8 @@ func init() {

EchoCmd.Flags().StringArrayVar(&EchoInputResponseErrorDetails, "response.error.details", []string{}, "A list of messages that carry the error details. ...")

EchoCmd.Flags().StringVar(&EchoInputSeverity, "severity", "", "The severity to be echoed by the server.")

EchoCmd.Flags().StringVar(&EchoInputResponse, "response", "", "Choices: content, error")

EchoCmd.Flags().StringVar(&EchoFromFile, "from_file", "", "Absolute path to JSON file containing request payload")
Expand Down Expand Up @@ -91,6 +97,8 @@ var EchoCmd = &cobra.Command{
return fmt.Errorf("Missing oneof choice for response")
}

EchoInput.Severity = genprotopb.Severity(genprotopb.Severity_value[strings.ToUpper(EchoInputSeverity)])

}

// unmarshal JSON strings into slice of structs
Expand Down
22 changes: 19 additions & 3 deletions schema/google/showcase/v1beta1/echo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ service Echo {
};
}

// The request message used for the Echo, Collect and Chat methods. If content
// is set in this message then the request will succeed. If status is set in
// this message then the status will be returned as an error.
// A severity enum used to test enum capabilities in GAPIC surfaces
enum Severity {
UNNECESSARY = 0;
NECESSARY = 1;
URGENT = 2;
CRITICAL = 3;
}


// The request message used for the Echo, Collect and Chat methods.
// If content or opt are set in this message then the request will succeed.
// If status is set in this message
// then the status will be returned as an error.
message EchoRequest {
oneof response {
// The content to be echoed by the server.
Expand All @@ -117,12 +127,18 @@ message EchoRequest {
// The error to be thrown by the server.
google.rpc.Status error = 2;
}

// The severity to be echoed by the server.
Severity severity = 3;
}

// The response message for the Echo methods.
message EchoResponse {
// The content specified in the request.
string content = 1;

// The severity specified in the request.
Severity severity = 2;
}

// The request message for the Expand method.
Expand Down
Loading

0 comments on commit 4dd0c7c

Please sign in to comment.