github.com/googleapis/api-linter@v1.65.2/docs/rules/0202/string-only-format.md (about) 1 --- 2 rule: 3 aip: 202 4 name: [core, '0202', string-only-format] 5 summary: Certain field formats can only be applied to a string field. 6 permalink: /202/string-only-format 7 redirect_from: 8 - /0202/string-only-format 9 --- 10 11 # String only format 12 13 This rule enforces that the following format specifiers are used only on fields 14 of type `string`, as mandated by [AIP-202][]: 15 16 - `UUID4` 17 - `IPV4` 18 - `IPV6` 19 - `IPV4_OR_IPV6` 20 21 ## Details 22 23 This rule looks at every non-string field with a 24 `(google.api.field_info).format` and complains if the format specifier is one 25 meant only for use on `string` fields. 26 27 ## Examples 28 29 **Incorrect** code for this rule: 30 31 ```proto 32 message Book { 33 string name = 1; 34 35 // Incorrect. Non-string must not be assigned format UUID4. 36 int32 edition = 2 [(google.api.field_info).format = UUID4]; 37 } 38 ``` 39 40 **Correct** code for this rule: 41 42 ```proto 43 message Book { 44 string name = 1; 45 46 int32 edition = 2; 47 48 // This is a correct example of a string-only format 49 // on a string field. 50 string uid = 3 [(google.api.field_info).format = UUID4]; 51 } 52 ``` 53 54 ## Disabling 55 56 If you need to violate this rule, use a leading comment above the field. 57 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 58 59 ```proto 60 message Book { 61 string name = 1; 62 63 // (-- api-linter: core::0202::string-only-format=disabled 64 // aip.dev/not-precedent: We need to do this because reasons. --) 65 int32 edition = 2 [(google.api.field_info).format = UUID4]; 66 } 67 ``` 68 69 If you need to violate this rule for an entire file, place the comment at the 70 top of the file. 71 72 [aip-202]: https://aip.dev/202 73 [aip.dev/not-precedent]: https://aip.dev/not-precedent