Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google LLC |
| 2 | // Modififications (C) 2018, Open Networking Foundation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | // NOTE: On the provenance of and modifications to http.proto and |
| 17 | // annotations.proto |
| 18 | // |
| 19 | // TL;DR: The files http.proto and annotations.proto are originally from here: |
| 20 | // https://github.com/googleapis/googleapis |
| 21 | // They have been modified slightly to avoid a namespace conflict. |
| 22 | // |
| 23 | // Long winded explanation: |
| 24 | // These files are designed to interact with Google's first party API's, and |
| 25 | // the recommended way to use them is to compiled them to code with protoc and |
| 26 | // included in your codebase before being used. Due to the fact that we're not |
| 27 | // using them that way, and because of how Chameleon and XOS work (dynamically |
| 28 | // defining our own API's), we have to ship these *.proto files as a part of |
| 29 | // our artifacts. |
| 30 | // |
| 31 | // The problems start when you try to include these specific .proto files in |
| 32 | // python. The protoc compiler includes the `google.protobuf` classes, which |
| 33 | // python can look up in the standard python library path. Unfortunately these |
| 34 | // files are namespaced with `google.api` in the path and aren't shipped with |
| 35 | // protoc. This leads to a path conflict - you can't have two library paths |
| 36 | // start with the same path component (`google` in this case) without getting |
| 37 | // an "ImportError: No module named ..." on one of the paths when you import |
| 38 | // them. |
| 39 | // |
| 40 | // Historically, various confusing hacks were implemented to override and |
| 41 | // special-case the python `include` directive to include a file at a different |
| 42 | // path than was specified. These hacks also failed when updating the base OS, |
| 43 | // and would likely continue to fail in other, stranger ways as we update the |
| 44 | // codebase. Specifically, Python 3 reimplemented these features in the |
| 45 | // importlib section of the standard library, so there's little confidence our |
| 46 | // hacks would continue to work. As an aside, there are various protobuf |
| 47 | // `options` statements to deal with this sort of issue in other languages (see |
| 48 | // the `go_package` and `java_package` below ) but these don't currently exist |
| 49 | // for python: https://github.com/google/protobuf/issues/973 |
| 50 | // |
| 51 | // To avoid this entire psychotic namespace hellscape, it's much easier to |
| 52 | // modify these files to remove the google.api path component, and have them |
| 53 | // included directly at a path of our own choice. |
| 54 | |
| 55 | syntax = "proto3"; |
| 56 | |
| 57 | package googleapi; |
| 58 | |
| 59 | option cc_enable_arenas = true; |
| 60 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; |
| 61 | option java_multiple_files = true; |
| 62 | option java_outer_classname = "HttpProto"; |
| 63 | option java_package = "com.google.api"; |
| 64 | option objc_class_prefix = "GAPI"; |
| 65 | |
| 66 | |
| 67 | // Defines the HTTP configuration for an API service. It contains a list of |
| 68 | // [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method |
| 69 | // to one or more HTTP REST API methods. |
| 70 | message Http { |
| 71 | // A list of HTTP configuration rules that apply to individual API methods. |
| 72 | // |
| 73 | // **NOTE:** All service configuration rules follow "last one wins" order. |
| 74 | repeated HttpRule rules = 1; |
| 75 | |
| 76 | // When set to true, URL path parmeters will be fully URI-decoded except in |
| 77 | // cases of single segment matches in reserved expansion, where "%2F" will be |
| 78 | // left encoded. |
| 79 | // |
| 80 | // The default behavior is to not decode RFC 6570 reserved characters in multi |
| 81 | // segment matches. |
| 82 | bool fully_decode_reserved_expansion = 2; |
| 83 | } |
| 84 | |
| 85 | // `HttpRule` defines the mapping of an RPC method to one or more HTTP |
| 86 | // REST API methods. The mapping specifies how different portions of the RPC |
| 87 | // request message are mapped to URL path, URL query parameters, and |
| 88 | // HTTP request body. The mapping is typically specified as an |
| 89 | // `google.api.http` annotation on the RPC method, |
| 90 | // see "google/api/annotations.proto" for details. |
| 91 | // |
| 92 | // The mapping consists of a field specifying the path template and |
| 93 | // method kind. The path template can refer to fields in the request |
| 94 | // message, as in the example below which describes a REST GET |
| 95 | // operation on a resource collection of messages: |
| 96 | // |
| 97 | // |
| 98 | // service Messaging { |
| 99 | // rpc GetMessage(GetMessageRequest) returns (Message) { |
| 100 | // option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}"; |
| 101 | // } |
| 102 | // } |
| 103 | // message GetMessageRequest { |
| 104 | // message SubMessage { |
| 105 | // string subfield = 1; |
| 106 | // } |
| 107 | // string message_id = 1; // mapped to the URL |
| 108 | // SubMessage sub = 2; // `sub.subfield` is url-mapped |
| 109 | // } |
| 110 | // message Message { |
| 111 | // string text = 1; // content of the resource |
| 112 | // } |
| 113 | // |
| 114 | // The same http annotation can alternatively be expressed inside the |
| 115 | // `GRPC API Configuration` YAML file. |
| 116 | // |
| 117 | // http: |
| 118 | // rules: |
| 119 | // - selector: <proto_package_name>.Messaging.GetMessage |
| 120 | // get: /v1/messages/{message_id}/{sub.subfield} |
| 121 | // |
| 122 | // This definition enables an automatic, bidrectional mapping of HTTP |
| 123 | // JSON to RPC. Example: |
| 124 | // |
| 125 | // HTTP | RPC |
| 126 | // -----|----- |
| 127 | // `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))` |
| 128 | // |
| 129 | // In general, not only fields but also field paths can be referenced |
| 130 | // from a path pattern. Fields mapped to the path pattern cannot be |
| 131 | // repeated and must have a primitive (non-message) type. |
| 132 | // |
| 133 | // Any fields in the request message which are not bound by the path |
| 134 | // pattern automatically become (optional) HTTP query |
| 135 | // parameters. Assume the following definition of the request message: |
| 136 | // |
| 137 | // |
| 138 | // service Messaging { |
| 139 | // rpc GetMessage(GetMessageRequest) returns (Message) { |
| 140 | // option (google.api.http).get = "/v1/messages/{message_id}"; |
| 141 | // } |
| 142 | // } |
| 143 | // message GetMessageRequest { |
| 144 | // message SubMessage { |
| 145 | // string subfield = 1; |
| 146 | // } |
| 147 | // string message_id = 1; // mapped to the URL |
| 148 | // int64 revision = 2; // becomes a parameter |
| 149 | // SubMessage sub = 3; // `sub.subfield` becomes a parameter |
| 150 | // } |
| 151 | // |
| 152 | // |
| 153 | // This enables a HTTP JSON to RPC mapping as below: |
| 154 | // |
| 155 | // HTTP | RPC |
| 156 | // -----|----- |
| 157 | // `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))` |
| 158 | // |
| 159 | // Note that fields which are mapped to HTTP parameters must have a |
| 160 | // primitive type or a repeated primitive type. Message types are not |
| 161 | // allowed. In the case of a repeated type, the parameter can be |
| 162 | // repeated in the URL, as in `...?param=A¶m=B`. |
| 163 | // |
| 164 | // For HTTP method kinds which allow a request body, the `body` field |
| 165 | // specifies the mapping. Consider a REST update method on the |
| 166 | // message resource collection: |
| 167 | // |
| 168 | // |
| 169 | // service Messaging { |
| 170 | // rpc UpdateMessage(UpdateMessageRequest) returns (Message) { |
| 171 | // option (google.api.http) = { |
| 172 | // put: "/v1/messages/{message_id}" |
| 173 | // body: "message" |
| 174 | // }; |
| 175 | // } |
| 176 | // } |
| 177 | // message UpdateMessageRequest { |
| 178 | // string message_id = 1; // mapped to the URL |
| 179 | // Message message = 2; // mapped to the body |
| 180 | // } |
| 181 | // |
| 182 | // |
| 183 | // The following HTTP JSON to RPC mapping is enabled, where the |
| 184 | // representation of the JSON in the request body is determined by |
| 185 | // protos JSON encoding: |
| 186 | // |
| 187 | // HTTP | RPC |
| 188 | // -----|----- |
| 189 | // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })` |
| 190 | // |
| 191 | // The special name `*` can be used in the body mapping to define that |
| 192 | // every field not bound by the path template should be mapped to the |
| 193 | // request body. This enables the following alternative definition of |
| 194 | // the update method: |
| 195 | // |
| 196 | // service Messaging { |
| 197 | // rpc UpdateMessage(Message) returns (Message) { |
| 198 | // option (google.api.http) = { |
| 199 | // put: "/v1/messages/{message_id}" |
| 200 | // body: "*" |
| 201 | // }; |
| 202 | // } |
| 203 | // } |
| 204 | // message Message { |
| 205 | // string message_id = 1; |
| 206 | // string text = 2; |
| 207 | // } |
| 208 | // |
| 209 | // |
| 210 | // The following HTTP JSON to RPC mapping is enabled: |
| 211 | // |
| 212 | // HTTP | RPC |
| 213 | // -----|----- |
| 214 | // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")` |
| 215 | // |
| 216 | // Note that when using `*` in the body mapping, it is not possible to |
| 217 | // have HTTP parameters, as all fields not bound by the path end in |
| 218 | // the body. This makes this option more rarely used in practice of |
| 219 | // defining REST APIs. The common usage of `*` is in custom methods |
| 220 | // which don't use the URL at all for transferring data. |
| 221 | // |
| 222 | // It is possible to define multiple HTTP methods for one RPC by using |
| 223 | // the `additional_bindings` option. Example: |
| 224 | // |
| 225 | // service Messaging { |
| 226 | // rpc GetMessage(GetMessageRequest) returns (Message) { |
| 227 | // option (google.api.http) = { |
| 228 | // get: "/v1/messages/{message_id}" |
| 229 | // additional_bindings { |
| 230 | // get: "/v1/users/{user_id}/messages/{message_id}" |
| 231 | // } |
| 232 | // }; |
| 233 | // } |
| 234 | // } |
| 235 | // message GetMessageRequest { |
| 236 | // string message_id = 1; |
| 237 | // string user_id = 2; |
| 238 | // } |
| 239 | // |
| 240 | // |
| 241 | // This enables the following two alternative HTTP JSON to RPC |
| 242 | // mappings: |
| 243 | // |
| 244 | // HTTP | RPC |
| 245 | // -----|----- |
| 246 | // `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` |
| 247 | // `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")` |
| 248 | // |
| 249 | // # Rules for HTTP mapping |
| 250 | // |
| 251 | // The rules for mapping HTTP path, query parameters, and body fields |
| 252 | // to the request message are as follows: |
| 253 | // |
| 254 | // 1. The `body` field specifies either `*` or a field path, or is |
| 255 | // omitted. If omitted, it indicates there is no HTTP request body. |
| 256 | // 2. Leaf fields (recursive expansion of nested messages in the |
| 257 | // request) can be classified into three types: |
| 258 | // (a) Matched in the URL template. |
| 259 | // (b) Covered by body (if body is `*`, everything except (a) fields; |
| 260 | // else everything under the body field) |
| 261 | // (c) All other fields. |
| 262 | // 3. URL query parameters found in the HTTP request are mapped to (c) fields. |
| 263 | // 4. Any body sent with an HTTP request can contain only (b) fields. |
| 264 | // |
| 265 | // The syntax of the path template is as follows: |
| 266 | // |
| 267 | // Template = "/" Segments [ Verb ] ; |
| 268 | // Segments = Segment { "/" Segment } ; |
| 269 | // Segment = "*" | "**" | LITERAL | Variable ; |
| 270 | // Variable = "{" FieldPath [ "=" Segments ] "}" ; |
| 271 | // FieldPath = IDENT { "." IDENT } ; |
| 272 | // Verb = ":" LITERAL ; |
| 273 | // |
| 274 | // The syntax `*` matches a single path segment. The syntax `**` matches zero |
| 275 | // or more path segments, which must be the last part of the path except the |
| 276 | // `Verb`. The syntax `LITERAL` matches literal text in the path. |
| 277 | // |
| 278 | // The syntax `Variable` matches part of the URL path as specified by its |
| 279 | // template. A variable template must not contain other variables. If a variable |
| 280 | // matches a single path segment, its template may be omitted, e.g. `{var}` |
| 281 | // is equivalent to `{var=*}`. |
| 282 | // |
| 283 | // If a variable contains exactly one path segment, such as `"{var}"` or |
| 284 | // `"{var=*}"`, when such a variable is expanded into a URL path, all characters |
| 285 | // except `[-_.~0-9a-zA-Z]` are percent-encoded. Such variables show up in the |
| 286 | // Discovery Document as `{var}`. |
| 287 | // |
| 288 | // If a variable contains one or more path segments, such as `"{var=foo/*}"` |
| 289 | // or `"{var=**}"`, when such a variable is expanded into a URL path, all |
| 290 | // characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. Such variables |
| 291 | // show up in the Discovery Document as `{+var}`. |
| 292 | // |
| 293 | // NOTE: While the single segment variable matches the semantics of |
| 294 | // [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 |
| 295 | // Simple String Expansion, the multi segment variable **does not** match |
| 296 | // RFC 6570 Reserved Expansion. The reason is that the Reserved Expansion |
| 297 | // does not expand special characters like `?` and `#`, which would lead |
| 298 | // to invalid URLs. |
| 299 | // |
| 300 | // NOTE: the field paths in variables and in the `body` must not refer to |
| 301 | // repeated fields or map fields. |
| 302 | message HttpRule { |
| 303 | // Selects methods to which this rule applies. |
| 304 | // |
| 305 | // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. |
| 306 | string selector = 1; |
| 307 | |
| 308 | // Determines the URL pattern is matched by this rules. This pattern can be |
| 309 | // used with any of the {get|put|post|delete|patch} methods. A custom method |
| 310 | // can be defined using the 'custom' field. |
| 311 | oneof pattern { |
| 312 | // Used for listing and getting information about resources. |
| 313 | string get = 2; |
| 314 | |
| 315 | // Used for updating a resource. |
| 316 | string put = 3; |
| 317 | |
| 318 | // Used for creating a resource. |
| 319 | string post = 4; |
| 320 | |
| 321 | // Used for deleting a resource. |
| 322 | string delete = 5; |
| 323 | |
| 324 | // Used for updating a resource. |
| 325 | string patch = 6; |
| 326 | |
| 327 | // The custom pattern is used for specifying an HTTP method that is not |
| 328 | // included in the `pattern` field, such as HEAD, or "*" to leave the |
| 329 | // HTTP method unspecified for this rule. The wild-card rule is useful |
| 330 | // for services that provide content to Web (HTML) clients. |
| 331 | CustomHttpPattern custom = 8; |
| 332 | } |
| 333 | |
| 334 | // The name of the request field whose value is mapped to the HTTP body, or |
| 335 | // `*` for mapping all fields not captured by the path pattern to the HTTP |
| 336 | // body. NOTE: the referred field must not be a repeated field and must be |
| 337 | // present at the top-level of request message type. |
| 338 | string body = 7; |
| 339 | |
| 340 | // Additional HTTP bindings for the selector. Nested bindings must |
| 341 | // not contain an `additional_bindings` field themselves (that is, |
| 342 | // the nesting may only be one level deep). |
| 343 | repeated HttpRule additional_bindings = 11; |
| 344 | } |
| 345 | |
| 346 | // A custom pattern is used for defining custom HTTP verb. |
| 347 | message CustomHttpPattern { |
| 348 | // The name of this custom HTTP verb. |
| 349 | string kind = 1; |
| 350 | |
| 351 | // The path matched by this custom verb. |
| 352 | string path = 2; |
| 353 | } |