github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/_example/proto/issue_128/grpc-gateway_a_bit_of_everything.proto (about) 1 syntax = "proto3"; 2 option go_package = "examplepb"; 3 package grpc.gateway.examples.internal.examplepb; 4 5 import "google/api/annotations.proto"; 6 import "google/protobuf/field_mask.proto"; 7 import "google/protobuf/empty.proto"; 8 import "google/protobuf/duration.proto"; 9 import "google/protobuf/wrappers.proto"; 10 import "examples/internal/proto/pathenum/path_enum.proto"; 11 import "examples/internal/proto/sub/message.proto"; 12 import "examples/internal/proto/sub2/message.proto"; 13 import "google/protobuf/timestamp.proto"; 14 import "protoc-gen-swagger/options/annotations.proto"; 15 16 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { 17 info: { 18 title: "A Bit of Everything"; 19 version: "1.0"; 20 contact: { 21 name: "gRPC-Gateway project"; 22 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 23 email: "none@example.com"; 24 }; 25 license: { 26 name: "BSD 3-Clause License"; 27 url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt"; 28 }; 29 extensions: { 30 key: "x-something-something"; 31 value { 32 string_value: "yadda"; 33 } 34 } 35 }; 36 // Overwriting host entry breaks tests, so this is not done here. 37 external_docs: { 38 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 39 description: "More about gRPC-Gateway"; 40 } 41 schemes: HTTP; 42 schemes: HTTPS; 43 schemes: WSS; 44 consumes: "application/json"; 45 consumes: "application/x-foo-mime"; 46 produces: "application/json"; 47 produces: "application/x-foo-mime"; 48 security_definitions: { 49 security: { 50 key: "BasicAuth"; 51 value: { 52 type: TYPE_BASIC; 53 } 54 } 55 security: { 56 key: "ApiKeyAuth"; 57 value: { 58 type: TYPE_API_KEY; 59 in: IN_HEADER; 60 name: "X-API-Key"; 61 extensions: { 62 key: "x-amazon-apigateway-authtype"; 63 value { 64 string_value: "oauth2"; 65 } 66 } 67 extensions: { 68 key: "x-amazon-apigateway-authorizer"; 69 value { 70 struct_value { 71 fields { 72 key: "type"; 73 value { 74 string_value: "token"; 75 } 76 } 77 fields { 78 key: "authorizerResultTtlInSeconds"; 79 value { 80 number_value: 60; 81 } 82 } 83 } 84 } 85 } 86 } 87 } 88 security: { 89 key: "OAuth2"; 90 value: { 91 type: TYPE_OAUTH2; 92 flow: FLOW_ACCESS_CODE; 93 authorization_url: "https://example.com/oauth/authorize"; 94 token_url: "https://example.com/oauth/token"; 95 scopes: { 96 scope: { 97 key: "read"; 98 value: "Grants read access"; 99 } 100 scope: { 101 key: "write"; 102 value: "Grants write access"; 103 } 104 scope: { 105 key: "admin"; 106 value: "Grants read and write access to administrative information"; 107 } 108 } 109 } 110 } 111 } 112 security: { 113 security_requirement: { 114 key: "BasicAuth"; 115 value: {}; 116 } 117 security_requirement: { 118 key: "ApiKeyAuth"; 119 value: {}; 120 } 121 } 122 security: { 123 security_requirement: { 124 key: "OAuth2"; 125 value: { 126 scope: "read"; 127 scope: "write"; 128 } 129 } 130 security_requirement: { 131 key: "ApiKeyAuth"; 132 value: {}; 133 } 134 } 135 responses: { 136 key: "403"; 137 value: { 138 description: "Returned when the user does not have permission to access the resource."; 139 } 140 } 141 responses: { 142 key: "404"; 143 value: { 144 description: "Returned when the resource does not exist."; 145 schema: { 146 json_schema: { 147 type: STRING; 148 } 149 } 150 } 151 } 152 responses: { 153 key: "418"; 154 value: { 155 description: "I'm a teapot."; 156 schema: { 157 json_schema: { 158 ref: ".grpc.gateway.examples.internal.examplepb.NumericEnum"; 159 } 160 } 161 } 162 } 163 extensions: { 164 key: "x-grpc-gateway-foo"; 165 value { 166 string_value: "bar"; 167 } 168 } 169 extensions: { 170 key: "x-grpc-gateway-baz-list"; 171 value { 172 list_value: { 173 values: { 174 string_value: "one"; 175 } 176 values: { 177 bool_value: true; 178 } 179 } 180 } 181 } 182 }; 183 184 185 // Intentionally complicated message type to cover many features of Protobuf. 186 message ABitOfEverything { 187 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = { 188 json_schema: { 189 title: "A bit of everything" 190 description: "Intentionaly complicated message type to cover many features of Protobuf." 191 required: ["uuid", "int64_value", "double_value"] 192 } 193 external_docs: { 194 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 195 description: "Find out more about ABitOfEverything"; 196 } 197 example: { value: '{ "uuid": "0cf361e1-4b44-483d-a159-54dabdf7e814" }' } 198 }; 199 200 // Nested is nested type. 201 message Nested { 202 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = { 203 example: { value: '{ "ok": "TRUE" }' } 204 }; 205 // name is nested field. 206 string name = 1; 207 uint32 amount = 2; 208 // DeepEnum is one or zero. 209 enum DeepEnum { 210 // FALSE is false. 211 FALSE = 0; 212 // TRUE is true. 213 TRUE = 1; 214 } 215 216 // DeepEnum comment. 217 DeepEnum ok = 3 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {description: "DeepEnum description."}]; 218 } 219 Nested single_nested = 25; 220 221 string uuid = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", min_length: 1}]; 222 repeated Nested nested = 2; 223 float float_value = 3 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {description: "Float value field", default: "0.2", required: ['float_value']}]; 224 double double_value = 4; 225 int64 int64_value = 5; 226 uint64 uint64_value = 6; 227 int32 int32_value = 7; 228 fixed64 fixed64_value = 8; 229 fixed32 fixed32_value = 9; 230 bool bool_value = 10; 231 string string_value = 11; 232 bytes bytes_value = 29; 233 uint32 uint32_value = 13; 234 NumericEnum enum_value = 14; 235 pathenum.PathEnum path_enum_value = 30; 236 pathenum.MessagePathEnum.NestedPathEnum nested_path_enum_value = 31; 237 sfixed32 sfixed32_value = 15; 238 sfixed64 sfixed64_value = 16; 239 sint32 sint32_value = 17; 240 sint64 sint64_value = 18; 241 repeated string repeated_string_value = 19; 242 oneof oneof_value { 243 google.protobuf.Empty oneof_empty = 20; 244 string oneof_string = 21; 245 } 246 247 map<string, NumericEnum> map_value = 22; 248 map<string, string> mapped_string_value = 23; 249 map<string, Nested> mapped_nested_value = 24; 250 251 string nonConventionalNameValue = 26; 252 253 google.protobuf.Timestamp timestamp_value = 27; 254 255 // repeated enum value. it is comma-separated in query 256 repeated NumericEnum repeated_enum_value = 28; 257 258 // repeated numeric enum comment (This comment is overridden by the field annotation) 259 repeated NumericEnum repeated_enum_annotation = 32 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {title: "Repeated numeric enum title", description: "Repeated numeric enum description."}]; 260 261 // numeric enum comment (This comment is overridden by the field annotation) 262 NumericEnum enum_value_annotation = 33 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {title: "Numeric enum title", description: "Numeric enum description."}]; 263 264 // repeated string comment (This comment is overridden by the field annotation) 265 repeated string repeated_string_annotation = 34 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {title: "Repeated string title", description: "Repeated string description."}]; 266 267 // repeated nested object comment (This comment is overridden by the field annotation) 268 repeated Nested repeated_nested_annotation = 35 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {title: "Repeated nested object title", description: "Repeated nested object description."}]; 269 270 // nested object comments (This comment is overridden by the field annotation) 271 Nested nested_annotation = 36 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {title: "Nested object title", description: "Nested object description."}]; 272 273 int64 int64_override_type = 37 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {type: INTEGER}]; 274 } 275 276 // ABitOfEverythingRepeated is used to validate repeated path parameter functionality 277 message ABitOfEverythingRepeated { 278 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = { 279 example: { value: '{ "path_repeated_bool_value": [true, true, false, true], "path_repeated_int32_value": [1, 2, 3] }' } 280 }; 281 282 // repeated values. they are comma-separated in path 283 repeated float path_repeated_float_value = 1; 284 repeated double path_repeated_double_value = 2; 285 repeated int64 path_repeated_int64_value = 3; 286 repeated uint64 path_repeated_uint64_value = 4; 287 repeated int32 path_repeated_int32_value = 5; 288 repeated fixed64 path_repeated_fixed64_value = 6; 289 repeated fixed32 path_repeated_fixed32_value = 7; 290 repeated bool path_repeated_bool_value = 8; 291 repeated string path_repeated_string_value = 9; 292 repeated bytes path_repeated_bytes_value = 10; 293 repeated uint32 path_repeated_uint32_value = 11; 294 repeated NumericEnum path_repeated_enum_value = 12; 295 repeated sfixed32 path_repeated_sfixed32_value = 13; 296 repeated sfixed64 path_repeated_sfixed64_value = 14; 297 repeated sint32 path_repeated_sint32_value = 15; 298 repeated sint64 path_repeated_sint64_value = 16; 299 } 300 301 message Body { 302 string name = 1; 303 } 304 305 message MessageWithBody { 306 string id = 1; 307 Body data = 2; 308 } 309 310 311 // NumericEnum is one or zero. 312 enum NumericEnum { 313 // ZERO means 0 314 ZERO = 0; 315 // ONE means 1 316 ONE = 1; 317 } 318 319 // UpdateV2Request request for update includes the message and the update mask 320 message UpdateV2Request { 321 ABitOfEverything abe = 1; 322 google.protobuf.FieldMask update_mask = 2; 323 } 324 325 // ABitOfEverything service is used to validate that APIs with complicated 326 // proto messages and URL templates are still processed correctly. 327 service ABitOfEverythingService { 328 329 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_tag) = { 330 description: "ABitOfEverythingService description -- which should not be used in place of the documentation comment!" 331 external_docs: { 332 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 333 description: "Find out more about EchoService"; 334 } 335 }; 336 337 // Create a new ABitOfEverything 338 // 339 // This API creates a new ABitOfEverything 340 rpc Create(ABitOfEverything) returns (ABitOfEverything) { 341 option (google.api.http) = { 342 post: "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value=strprefix/*}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}/{enum_value}/{path_enum_value}/{nested_path_enum_value}/{enum_value_annotation}" 343 }; 344 } 345 rpc CreateBody(ABitOfEverything) returns (ABitOfEverything) { 346 option (google.api.http) = { 347 post: "/v1/example/a_bit_of_everything" 348 body: "*" 349 }; 350 } 351 rpc Lookup(sub2.IdMessage) returns (ABitOfEverything) { 352 option (google.api.http) = { 353 get: "/v1/example/a_bit_of_everything/{uuid}" 354 }; 355 } 356 rpc Update(ABitOfEverything) returns (google.protobuf.Empty) { 357 option (google.api.http) = { 358 put: "/v1/example/a_bit_of_everything/{uuid}" 359 body: "*" 360 }; 361 } 362 rpc UpdateV2(UpdateV2Request) returns (google.protobuf.Empty) { 363 option (google.api.http) = { 364 put: "/v2/example/a_bit_of_everything/{abe.uuid}" 365 body: "abe" 366 additional_bindings: [ 367 { 368 patch: "/v2/example/a_bit_of_everything/{abe.uuid}" 369 body: "abe" 370 }, 371 { 372 patch: "/v2a/example/a_bit_of_everything/{abe.uuid}" 373 body: "*" 374 } 375 ] 376 }; 377 } 378 379 rpc Delete(sub2.IdMessage) returns (google.protobuf.Empty) { 380 option (google.api.http) = { 381 delete: "/v1/example/a_bit_of_everything/{uuid}" 382 }; 383 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { 384 security: { 385 security_requirement: { 386 key: "ApiKeyAuth"; 387 value: {} 388 } 389 security_requirement: { 390 key: "OAuth2"; 391 value: { 392 scope: "read"; 393 scope: "write"; 394 } 395 } 396 } 397 extensions: { 398 key: "x-irreversible"; 399 value { 400 bool_value: true; 401 } 402 } 403 }; 404 } 405 rpc GetQuery(ABitOfEverything) returns (google.protobuf.Empty) { 406 option (google.api.http) = { 407 get: "/v1/example/a_bit_of_everything/query/{uuid}" 408 }; 409 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { 410 deprecated: true // For testing purposes. 411 external_docs: { 412 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 413 description: "Find out more about GetQuery"; 414 } 415 security: { 416 } 417 }; 418 } 419 rpc GetRepeatedQuery(ABitOfEverythingRepeated) returns (ABitOfEverythingRepeated) { 420 option (google.api.http) = { 421 get: "/v1/example/a_bit_of_everything_repeated/{path_repeated_float_value}/{path_repeated_double_value}/{path_repeated_int64_value}/{path_repeated_uint64_value}/{path_repeated_int32_value}/{path_repeated_fixed64_value}/{path_repeated_fixed32_value}/{path_repeated_bool_value}/{path_repeated_string_value}/{path_repeated_bytes_value}/{path_repeated_uint32_value}/{path_repeated_enum_value}/{path_repeated_sfixed32_value}/{path_repeated_sfixed64_value}/{path_repeated_sint32_value}/{path_repeated_sint64_value}" 422 }; 423 } 424 // Echo allows posting a StringMessage value. 425 // 426 // It also exposes multiple bindings. 427 // 428 // This makes it useful when validating that the OpenAPI v2 API 429 // description exposes documentation correctly on all paths 430 // defined as additional_bindings in the proto. 431 rpc Echo(grpc.gateway.examples.internal.sub.StringMessage) returns (grpc.gateway.examples.internal.sub.StringMessage) { 432 option (google.api.http) = { 433 get: "/v1/example/a_bit_of_everything/echo/{value}" 434 additional_bindings { 435 post: "/v2/example/echo" 436 body: "value" 437 } 438 additional_bindings { 439 get: "/v2/example/echo" 440 } 441 }; 442 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { 443 description: "Description Echo"; 444 summary: "Summary: Echo rpc"; 445 tags: "echo rpc"; 446 external_docs: { 447 url: "https://github.com/grpc-ecosystem/grpc-gateway"; 448 description: "Find out more Echo"; 449 } 450 responses: { 451 key: "200" 452 value: { 453 examples: { 454 key: "application/json" 455 value: '{"value": "the input value"}' 456 } 457 } 458 } 459 responses: { 460 key: "503"; 461 value: { 462 description: "Returned when the resource is temporarily unavailable."; 463 extensions: { 464 key: "x-number"; 465 value { 466 number_value: 100; 467 } 468 } 469 } 470 } 471 responses: { 472 // Overwrites global definition. 473 key: "404"; 474 value: { 475 description: "Returned when the resource does not exist."; 476 schema: { 477 json_schema: { 478 type: INTEGER; 479 } 480 } 481 } 482 } 483 }; 484 } 485 rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) { 486 option (google.api.http) = { 487 post: "/v1/example/a_bit_of_everything/{single_nested.name}" 488 body: "*" 489 }; 490 } 491 rpc NoBindings(google.protobuf.Duration) returns (google.protobuf.Empty) {} 492 rpc Timeout(google.protobuf.Empty) returns (google.protobuf.Empty) { 493 option (google.api.http) = { 494 get: "/v2/example/timeout", 495 }; 496 } 497 rpc ErrorWithDetails(google.protobuf.Empty) returns (google.protobuf.Empty) { 498 option (google.api.http) = { 499 get: "/v2/example/errorwithdetails", 500 }; 501 } 502 rpc GetMessageWithBody(MessageWithBody) returns (google.protobuf.Empty) { 503 option (google.api.http) = { 504 post: "/v2/example/withbody/{id}", 505 body: "data" 506 }; 507 } 508 rpc PostWithEmptyBody(Body) returns (google.protobuf.Empty) { 509 option (google.api.http) = { 510 post: "/v2/example/postwithemptybody/{name}", 511 body: "*" 512 }; 513 } 514 rpc CheckGetQueryParams(ABitOfEverything) returns (ABitOfEverything) { 515 option (google.api.http) = { 516 get: "/v1/example/a_bit_of_everything/params/get/{single_nested.name}" 517 }; 518 } 519 rpc CheckNestedEnumGetQueryParams(ABitOfEverything) returns (ABitOfEverything) { 520 option (google.api.http) = { 521 get: "/v1/example/a_bit_of_everything/params/get/nested_enum/{single_nested.ok}" 522 }; 523 } 524 rpc CheckPostQueryParams(ABitOfEverything) returns (ABitOfEverything) { 525 option (google.api.http) = { 526 post: "/v1/example/a_bit_of_everything/params/post/{string_value}" 527 body: "single_nested" 528 }; 529 } 530 rpc OverwriteResponseContentType(google.protobuf.Empty) returns (google.protobuf.StringValue) { 531 option (google.api.http) = { 532 get: "/v2/example/overwriteresponsecontenttype" 533 }; 534 option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { 535 produces: "application/text" 536 }; 537 } 538 } 539 540 // camelCase and lowercase service names are valid but not recommended (use TitleCase instead) 541 service camelCaseServiceName { 542 rpc Empty(google.protobuf.Empty) returns (google.protobuf.Empty) { 543 option (google.api.http) = { 544 get: "/v2/example/empty", 545 }; 546 } 547 } 548 service AnotherServiceWithNoBindings { 549 rpc NoBindings(google.protobuf.Empty) returns (google.protobuf.Empty) {} 550 }