github.com/googleapis/api-linter@v1.65.2/docs/rules/0133/response-message-name.md (about) 1 --- 2 rule: 3 aip: 133 4 name: [core, '0133', response-message-name] 5 summary: Create methods must return the resource. 6 permalink: /133/response-message-name 7 redirect_from: 8 - /0133/response-message-name 9 --- 10 11 # Create methods: Resource response message 12 13 This rule enforces that all `Create` RPCs have a response message of the 14 resource, as mandated in [AIP-133][]. 15 16 ## Details 17 18 This rule looks at any message matching beginning with `Create`, and complains 19 if the name of the corresponding output message does not match the name of the 20 RPC with the prefix `Create` removed. 21 22 It also permits a response of `google.longrunning.Operation`; in this case, it 23 checks the `response_type` in the `google.longrunning.operation_info` 24 annotation and ensures that _it_ corresponds to the name of the RPC with the 25 prefix `Create` removed. 26 27 ## Examples 28 29 ### Standard 30 31 **Incorrect** code for this rule: 32 33 ```proto 34 // Incorrect. 35 // Should be `Book`. 36 rpc CreateBook(CreateBookRequest) returns (CreateBookResponse) { 37 option (google.api.http) = { 38 post: "/v1/{name=publishers/*}/books" 39 body: "book" 40 }; 41 } 42 ``` 43 44 **Correct** code for this rule: 45 46 ```proto 47 // Correct. 48 rpc CreateBook(CreateBookRequest) returns (Book) { 49 option (google.api.http) = { 50 post: "/v1/{name=publishers/*}/books" 51 body: "book" 52 }; 53 } 54 ``` 55 56 ### Long-running operation 57 58 **Incorrect** code for this rule: 59 60 ```proto 61 // Incorrect. 62 rpc CreateBook(CreateBookRequest) returns (google.longrunning.Operation) { 63 option (google.api.http) = { 64 post: "/v1/{book.name=publishers/*}/books" 65 body: "book" 66 }; 67 option (google.longrunning.operation_info) = { 68 response_type: "CreateBookResponse" // Should be "Book". 69 metadata_type: "CreateBookMetadata" 70 }; 71 } 72 ``` 73 74 **Correct** code for this rule: 75 76 ```proto 77 // Correct. 78 rpc CreateBook(CreateBookRequest) returns (google.longrunning.Operation) { 79 option (google.api.http) = { 80 post: "/v1/{book.name=publishers/*}/books" 81 body: "book" 82 }; 83 option (google.longrunning.operation_info) = { 84 response_type: "Book" 85 metadata_type: "CreateBookMetadata" 86 }; 87 } 88 ``` 89 90 ## Disabling 91 92 If you need to violate this rule, use a leading comment above the method. 93 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 94 95 ```proto 96 // (-- api-linter: core::0133::response-message-name=disabled 97 // aip.dev/not-precedent: We need to do this because reasons. --) 98 rpc CreateBook(CreateBookRequest) returns (CreateBookResponse) { 99 option (google.api.http) = { 100 post: "/v1/{name=publishers/*}/books" 101 body: "book" 102 }; 103 } 104 ``` 105 106 If you need to violate this rule for an entire file, place the comment at the 107 top of the file. 108 109 [aip-133]: https://aip.dev/133 110 [aip.dev/not-precedent]: https://aip.dev/not-precedent