1// Copyright 2018 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto3"; 16 17import "google/api/annotations.proto"; 18import "google/api/client.proto"; 19import "google/api/field_behavior.proto"; 20import "google/api/resource.proto"; 21import "google/longrunning/operations.proto"; 22import "google/protobuf/duration.proto"; 23import "google/protobuf/struct.proto"; 24import "google/protobuf/timestamp.proto"; 25import "google/rpc/status.proto"; 26import "google/protobuf/field_mask.proto"; 27 28package google.showcase.grpcrest.v1beta1; 29 30option go_package = "github.com/googleapis/gapic-showcase-grpcrest/server/genproto"; 31option java_package = "com.google.showcase.grpcrest.v1beta1"; 32option java_multiple_files = true; 33 34option (google.api.resource_definition) = { 35 type: "showcase.googleapis.com/AnythingGoes" 36 pattern: "*" 37}; 38 39// This service is used showcase the four main types of rpcs - unary, server 40// side streaming, client side streaming, and bidirectional streaming. This 41// service also exposes methods that explicitly implement server delay, and 42// paginated calls. Set the 'showcase-trailer' metadata key on any method 43// to have the values echoed in the response trailers. 44service Echo { 45 // This service is meant to only run locally on the port 7469 (keypad digits 46 // for "show"). 47 option (google.api.default_host) = "localhost:7469"; 48 option (google.api.oauth_scopes) = 49 "https://www.googleapis.com/auth/cloud-platform"; 50 51 // This method simply echos the request. This method is showcases unary rpcs. 52 rpc Echo(EchoRequest) returns (EchoResponse) { 53 option (google.api.http) = { 54 post: "/v1beta1/echo:echo" 55 body: "*" 56 }; 57 option (google.api.method_signature) = "content"; 58 option (google.api.method_signature) = "error"; 59 option (google.api.method_signature) = "content,severity"; 60 option (google.api.method_signature) = "name"; 61 option (google.api.method_signature) = "parent"; 62 option (google.api.method_signature) = ""; 63 } 64 65 // This method split the given content into words and will pass each word back 66 // through the stream. This method showcases server-side streaming rpcs. 67 rpc Expand(ExpandRequest) returns (stream EchoResponse) { 68 option (google.api.http) = { 69 post: "/v1beta1/echo:expand" 70 body: "error" 71 }; 72 option (google.api.method_signature) = "content,error"; 73 } 74 75 // This is similar to the Expand method but instead of returning a stream of 76 // expanded words, this method returns a paged list of expanded words. 77 rpc PagedExpand(PagedExpandRequest) returns (PagedExpandResponse) { 78 option (google.api.http) = { 79 post: "/v1beta1/echo:pagedExpand" 80 body: "*" 81 }; 82 } 83 84 rpc SimplePagedExpand(PagedExpandRequest) returns (PagedExpandResponse) { 85 option (google.api.http) = { 86 post: "/v1beta1/echo:pagedExpand" 87 body: "*" 88 }; 89 option (google.api.method_signature) = ""; 90 } 91 92 // This method will wait the requested amount of and then return. 93 // This method showcases how a client handles a request timing out. 94 rpc Wait(WaitRequest) returns (google.longrunning.Operation) { 95 option (google.api.http) = { 96 post: "/v1beta1/echo:wait" 97 body: "*" 98 }; 99 option (google.longrunning.operation_info) = { 100 response_type: "WaitResponse" 101 metadata_type: "WaitMetadata" 102 }; 103 option (google.api.method_signature) = "end_time"; 104 option (google.api.method_signature) = "ttl"; 105 } 106 107 // This method will block (wait) for the requested amount of time 108 // and then return the response or error. 109 // This method showcases how a client handles delays or retries. 110 rpc Block(BlockRequest) returns (BlockResponse) { 111 option (google.api.http) = { 112 post: "/v1beta1/echo:block" 113 body: "*" 114 }; 115 }; 116 117 // This method primarily tests Java name collisions by using the Object 118 // message. 119 rpc CollideName(EchoRequest) returns (Object) { 120 option (google.api.http) = { 121 post: "/v1beta1/echo:foo" 122 body: "*" 123 }; 124 } 125 126 rpc NestedBinding(EchoRequest) returns (Object) { 127 option (google.api.http) = { 128 post: "/v1beta1/{foo_bar.name=projects/*/foobars/*}/echo:foo" 129 body: "*" 130 additional_bindings { 131 post: "/v1beta1/{foo_bar.name=cats/*/dogs/*}/echo:foo" 132 body: "*" 133 } 134 additional_bindings { 135 post: "/v1beta1/{foo_bar.name=turtles/*/parrots/*}/echo:foo" 136 body: "*" 137 } 138 }; 139 } 140 141 rpc Chat(stream EchoRequest) returns (stream EchoResponse) { 142 option (google.api.http) = { 143 post: "/v1beta1/chat:chat" 144 body: "error" 145 }; 146 } 147 148 rpc NoBinding(EchoRequest) returns (EchoResponse); 149 150 //The request message contains a field name that is a Java keyword(case), 151 //the field is also a resource and used in http annotations 152 rpc UpdateCase(UpdateCaseRequest) returns (Case) { 153 option (google.api.http) = { 154 patch: "/v2beta/{case.name=projects/*/cases/*}" 155 body: "case" 156 additional_bindings { 157 patch: "/v2beta/{case.name=organizations/*/cases/*}" 158 body: "case" 159 } 160 }; 161 option (google.api.method_signature) = "case,update_mask"; 162 } 163} 164 165// Generator should not fail when encounter a service without methods 166service EchoEmpy { 167 option (google.api.default_host) = "localhost:7469"; 168} 169 170// A severity enum used to test enum capabilities in GAPIC surfaces 171enum Severity { 172 UNNECESSARY = 0; 173 NECESSARY = 1; 174 URGENT = 2; 175 CRITICAL = 3; 176} 177 178message UpdateCaseRequest { 179 Case case = 1 [(google.api.field_behavior) = REQUIRED]; 180 181 google.protobuf.FieldMask update_mask = 2; 182} 183 184message Case { 185 option (google.api.resource) = { 186 type: "cloudsupport.googleapis.com/Case" 187 pattern: "organizations/{organization}/cases/{case}" 188 pattern: "projects/{project}/cases/{case}" 189 }; 190 191 // The resource name for the case. 192 string name = 1; 193 194 string display_name = 2; 195 196 string description = 3; 197} 198 199message Foobar { 200 option (google.api.resource) = { 201 type: "showcase.googleapis.com/Foobar" 202 pattern: "projects/{project}/foobars/{foobar}" 203 pattern: "projects/{project}/chocolate/variants/{variant}/foobars/{foobar}" 204 pattern: "foobars/{foobar}" 205 pattern: "bar_foos/{bar_foo}/foobars/{foobar}" 206 pattern: "*" 207 }; 208 209 string name = 1; 210 string info = 2; 211} 212 213// The request message used for the Echo, Collect and Chat methods. 214// If content or opt are set in this message then the request will succeed. 215// If status is set in this message 216// then the status will be returned as an error. 217message EchoRequest { 218 string name = 5 [ 219 (google.api.resource_reference).type = "showcase.googleapis.com/Foobar", 220 (google.api.field_behavior) = REQUIRED 221 ]; 222 223 string parent = 6 [ 224 (google.api.resource_reference).child_type = 225 "showcase.googleapis.com/AnythingGoes", 226 (google.api.field_behavior) = REQUIRED 227 ]; 228 229 oneof response { 230 // The content to be echoed by the server. 231 string content = 1; 232 233 // The error to be thrown by the server. 234 google.rpc.Status error = 2; 235 } 236 237 // The severity to be echoed by the server. 238 Severity severity = 3; 239 240 Foobar foo_bar = 4; 241} 242 243// The response message for the Echo methods. 244message EchoResponse { 245 // The content specified in the request. 246 string content = 1; 247 248 // The severity specified in the request. 249 Severity severity = 2; 250 251 // Value field to test special case in Value type serialization. 252 google.protobuf.Value value_field = 3; 253} 254 255// Tests name collisions with java.lang.Object. 256message Object { 257 // The content specified in the request. 258 string content = 1; 259} 260 261// The request message for the Expand method. 262message ExpandRequest { 263 // The content that will be split into words and returned on the stream. 264 string content = 1; 265 266 // The error that is thrown after all words are sent on the stream. 267 google.rpc.Status error = 2; 268 269 repeated string info = 3; 270} 271 272// The request for the PagedExpand method. 273message PagedExpandRequest { 274 // The string to expand. 275 string content = 1 [(google.api.field_behavior) = REQUIRED]; 276 277 // The amount of words to returned in each page. 278 int32 page_size = 2; 279 280 // The position of the page to be returned. 281 string page_token = 3; 282} 283 284// The response for the PagedExpand method. 285message PagedExpandResponse { 286 // The words that were expanded. 287 repeated EchoResponse responses = 1; 288 289 // The next page token. 290 string next_page_token = 2; 291} 292 293// The request for Wait method. 294message WaitRequest { 295 oneof end { 296 // The time that this operation will complete. 297 google.protobuf.Timestamp end_time = 1; 298 299 // The duration of this operation. 300 google.protobuf.Duration ttl = 4; 301 } 302 303 oneof response { 304 // The error that will be returned by the server. If this code is specified 305 // to be the OK rpc code, an empty response will be returned. 306 google.rpc.Status error = 2; 307 308 // The response to be returned on operation completion. 309 WaitResponse success = 3; 310 } 311} 312 313// The result of the Wait operation. 314message WaitResponse { 315 // This content of the result. 316 string content = 1; 317} 318 319// The metadata for Wait operation. 320message WaitMetadata { 321 // The time that this operation will complete. 322 google.protobuf.Timestamp end_time = 1; 323} 324 325// The request for Block method. 326message BlockRequest { 327 // The amount of time to block before returning a response. 328 google.protobuf.Duration response_delay = 1; 329 330 oneof response { 331 // The error that will be returned by the server. If this code is specified 332 // to be the OK rpc code, an empty response will be returned. 333 google.rpc.Status error = 2; 334 335 // The response to be returned that will signify successful method call. 336 BlockResponse success = 3; 337 } 338} 339 340// The response for Block method. 341message BlockResponse { 342 // This content can contain anything, the server will not depend on a value 343 // here. 344 string content = 1; 345} 346