library.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. // Copyright 2019 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. // http://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. //
  15. syntax = "proto3";
  16. package google.example.library.v1;
  17. import "google/api/annotations.proto";
  18. import "google/api/client.proto";
  19. import "google/api/field_behavior.proto";
  20. import "google/api/resource.proto";
  21. import "google/protobuf/empty.proto";
  22. import "google/protobuf/field_mask.proto";
  23. option go_package = "google.golang.org/genproto/googleapis/example/library/v1;library";
  24. option java_multiple_files = true;
  25. option java_outer_classname = "LibraryProto";
  26. option java_package = "com.google.example.library.v1";
  27. option php_namespace = "Google\\Cloud\\Example\\Library\\V1";
  28. // This API represents a simple digital library. It lets you manage Shelf
  29. // resources and Book resources in the library. It defines the following
  30. // resource model:
  31. //
  32. // - The API has a collection of [Shelf][google.example.library.v1.Shelf]
  33. // resources, named `shelves/*`
  34. //
  35. // - Each Shelf has a collection of [Book][google.example.library.v1.Book]
  36. // resources, named `shelves/*/books/*`
  37. service LibraryService {
  38. option (google.api.default_host) = "library-example.googleapis.com";
  39. // Creates a shelf, and returns the new Shelf.
  40. rpc CreateShelf(CreateShelfRequest) returns (Shelf) {
  41. option (google.api.http) = {
  42. post: "/v1/shelves"
  43. body: "shelf"
  44. };
  45. option (google.api.method_signature) = "shelf";
  46. }
  47. // Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
  48. rpc GetShelf(GetShelfRequest) returns (Shelf) {
  49. option (google.api.http) = {
  50. get: "/v1/{name=shelves/*}"
  51. };
  52. option (google.api.method_signature) = "name";
  53. }
  54. // Lists shelves. The order is unspecified but deterministic. Newly created
  55. // shelves will not necessarily be added to the end of this list.
  56. rpc ListShelves(ListShelvesRequest) returns (ListShelvesResponse) {
  57. option (google.api.http) = {
  58. get: "/v1/shelves"
  59. };
  60. }
  61. // Deletes a shelf. Returns NOT_FOUND if the shelf does not exist.
  62. rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {
  63. option (google.api.http) = {
  64. delete: "/v1/{name=shelves/*}"
  65. };
  66. option (google.api.method_signature) = "name";
  67. }
  68. // Merges two shelves by adding all books from the shelf named
  69. // `other_shelf_name` to shelf `name`, and deletes
  70. // `other_shelf_name`. Returns the updated shelf.
  71. // The book ids of the moved books may not be the same as the original books.
  72. //
  73. // Returns NOT_FOUND if either shelf does not exist.
  74. // This call is a no-op if the specified shelves are the same.
  75. rpc MergeShelves(MergeShelvesRequest) returns (Shelf) {
  76. option (google.api.http) = {
  77. post: "/v1/{name=shelves/*}:merge"
  78. body: "*"
  79. };
  80. option (google.api.method_signature) = "name,other_shelf";
  81. }
  82. // Creates a book, and returns the new Book.
  83. rpc CreateBook(CreateBookRequest) returns (Book) {
  84. option (google.api.http) = {
  85. post: "/v1/{parent=shelves/*}/books"
  86. body: "book"
  87. };
  88. option (google.api.method_signature) = "parent,book";
  89. }
  90. // Gets a book. Returns NOT_FOUND if the book does not exist.
  91. rpc GetBook(GetBookRequest) returns (Book) {
  92. option (google.api.http) = {
  93. get: "/v1/{name=shelves/*/books/*}"
  94. };
  95. option (google.api.method_signature) = "name";
  96. }
  97. // Lists books in a shelf. The order is unspecified but deterministic. Newly
  98. // created books will not necessarily be added to the end of this list.
  99. // Returns NOT_FOUND if the shelf does not exist.
  100. rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {
  101. option (google.api.http) = {
  102. get: "/v1/{parent=shelves/*}/books"
  103. };
  104. option (google.api.method_signature) = "parent";
  105. }
  106. // Deletes a book. Returns NOT_FOUND if the book does not exist.
  107. rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {
  108. option (google.api.http) = {
  109. delete: "/v1/{name=shelves/*/books/*}"
  110. };
  111. option (google.api.method_signature) = "name";
  112. }
  113. // Updates a book. Returns INVALID_ARGUMENT if the name of the book
  114. // is non-empty and does not equal the existing name.
  115. rpc UpdateBook(UpdateBookRequest) returns (Book) {
  116. option (google.api.http) = {
  117. patch: "/v1/{book.name=shelves/*/books/*}"
  118. body: "book"
  119. };
  120. option (google.api.method_signature) = "book,update_mask";
  121. }
  122. // Moves a book to another shelf, and returns the new book. The book
  123. // id of the new book may not be the same as the original book.
  124. rpc MoveBook(MoveBookRequest) returns (Book) {
  125. option (google.api.http) = {
  126. post: "/v1/{name=shelves/*/books/*}:move"
  127. body: "*"
  128. };
  129. option (google.api.method_signature) = "name,other_shelf_name";
  130. }
  131. }
  132. // A single book in the library.
  133. message Book {
  134. option (google.api.resource) = {
  135. type: "library-example.googleapis.com/Book",
  136. pattern: "shelves/{shelf}/books/{book}"
  137. };
  138. // The resource name of the book.
  139. // Book names have the form `shelves/{shelf_id}/books/{book_id}`.
  140. // The name is ignored when creating a book.
  141. string name = 1;
  142. // The name of the book author.
  143. string author = 2;
  144. // The title of the book.
  145. string title = 3;
  146. // Value indicating whether the book has been read.
  147. bool read = 4;
  148. }
  149. // A Shelf contains a collection of books with a theme.
  150. message Shelf {
  151. option (google.api.resource) = {
  152. type: "library-example.googleapis.com/Shelf",
  153. pattern: "shelves/{shelf_id}"
  154. };
  155. // The resource name of the shelf.
  156. // Shelf names have the form `shelves/{shelf_id}`.
  157. // The name is ignored when creating a shelf.
  158. string name = 1;
  159. // The theme of the shelf
  160. string theme = 2;
  161. }
  162. // Request message for LibraryService.CreateShelf.
  163. message CreateShelfRequest {
  164. // The shelf to create.
  165. Shelf shelf = 1 [(google.api.field_behavior) = REQUIRED];
  166. }
  167. // Request message for LibraryService.GetShelf.
  168. message GetShelfRequest {
  169. // The name of the shelf to retrieve.
  170. string name = 1 [
  171. (google.api.field_behavior) = REQUIRED,
  172. (google.api.resource_reference).type =
  173. "library-example.googleapis.com/Shelf"
  174. ];
  175. }
  176. // Request message for LibraryService.ListShelves.
  177. message ListShelvesRequest {
  178. // Requested page size. Server may return fewer shelves than requested.
  179. // If unspecified, server will pick an appropriate default.
  180. int32 page_size = 1;
  181. // A token identifying a page of results the server should return.
  182. // Typically, this is the value of
  183. // [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token]
  184. // returned from the previous call to `ListShelves` method.
  185. string page_token = 2;
  186. }
  187. // Response message for LibraryService.ListShelves.
  188. message ListShelvesResponse {
  189. // The list of shelves.
  190. repeated Shelf shelves = 1;
  191. // A token to retrieve next page of results.
  192. // Pass this value in the
  193. // [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token]
  194. // field in the subsequent call to `ListShelves` method to retrieve the next
  195. // page of results.
  196. string next_page_token = 2;
  197. }
  198. // Request message for LibraryService.DeleteShelf.
  199. message DeleteShelfRequest {
  200. // The name of the shelf to delete.
  201. string name = 1 [
  202. (google.api.field_behavior) = REQUIRED,
  203. (google.api.resource_reference).type =
  204. "library-example.googleapis.com/Shelf"
  205. ];
  206. }
  207. // Describes the shelf being removed (other_shelf_name) and updated
  208. // (name) in this merge.
  209. message MergeShelvesRequest {
  210. // The name of the shelf we're adding books to.
  211. string name = 1 [
  212. (google.api.field_behavior) = REQUIRED,
  213. (google.api.resource_reference).type =
  214. "library-example.googleapis.com/Shelf"
  215. ];
  216. // The name of the shelf we're removing books from and deleting.
  217. string other_shelf = 2 [
  218. (google.api.field_behavior) = REQUIRED,
  219. (google.api.resource_reference).type =
  220. "library-example.googleapis.com/Shelf"
  221. ];
  222. }
  223. // Request message for LibraryService.CreateBook.
  224. message CreateBookRequest {
  225. // The name of the shelf in which the book is created.
  226. string parent = 1 [
  227. (google.api.field_behavior) = REQUIRED,
  228. (google.api.resource_reference).type =
  229. "library-example.googleapis.com/Shelf"
  230. ];
  231. // The book to create.
  232. Book book = 2 [(google.api.field_behavior) = REQUIRED];
  233. }
  234. // Request message for LibraryService.GetBook.
  235. message GetBookRequest {
  236. // The name of the book to retrieve.
  237. string name = 1 [
  238. (google.api.field_behavior) = REQUIRED,
  239. (google.api.resource_reference).type = "library-example.googleapis.com/Book"
  240. ];
  241. }
  242. // Request message for LibraryService.ListBooks.
  243. message ListBooksRequest {
  244. // The name of the shelf whose books we'd like to list.
  245. string parent = 1 [
  246. (google.api.field_behavior) = REQUIRED,
  247. (google.api.resource_reference).type =
  248. "library-example.googleapis.com/Shelf"
  249. ];
  250. // Requested page size. Server may return fewer books than requested.
  251. // If unspecified, server will pick an appropriate default.
  252. int32 page_size = 2;
  253. // A token identifying a page of results the server should return.
  254. // Typically, this is the value of
  255. // [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token].
  256. // returned from the previous call to `ListBooks` method.
  257. string page_token = 3;
  258. }
  259. // Response message for LibraryService.ListBooks.
  260. message ListBooksResponse {
  261. // The list of books.
  262. repeated Book books = 1;
  263. // A token to retrieve next page of results.
  264. // Pass this value in the
  265. // [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token]
  266. // field in the subsequent call to `ListBooks` method to retrieve the next
  267. // page of results.
  268. string next_page_token = 2;
  269. }
  270. // Request message for LibraryService.UpdateBook.
  271. message UpdateBookRequest {
  272. // The name of the book to update.
  273. Book book = 1 [(google.api.field_behavior) = REQUIRED];
  274. // Required. Mask of fields to update.
  275. google.protobuf.FieldMask update_mask = 2
  276. [(google.api.field_behavior) = REQUIRED];
  277. }
  278. // Request message for LibraryService.DeleteBook.
  279. message DeleteBookRequest {
  280. // The name of the book to delete.
  281. string name = 1 [
  282. (google.api.field_behavior) = REQUIRED,
  283. (google.api.resource_reference).type = "library-example.googleapis.com/Book"
  284. ];
  285. }
  286. // Describes what book to move (name) and what shelf we're moving it
  287. // to (other_shelf_name).
  288. message MoveBookRequest {
  289. // The name of the book to move.
  290. string name = 1 [
  291. (google.api.field_behavior) = REQUIRED,
  292. (google.api.resource_reference).type = "library-example.googleapis.com/Book"
  293. ];
  294. // The name of the destination shelf.
  295. string other_shelf_name = 2 [
  296. (google.api.field_behavior) = REQUIRED,
  297. (google.api.resource_reference).type =
  298. "library-example.googleapis.com/Shelf"
  299. ];
  300. }