field_mask_pb.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # Copyright (c) 2025-2026 Buf Technologies, Inc.
  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. # Generated from google/protobuf/field_mask.proto. DO NOT EDIT.
  15. # Generated by protoc-gen-py v0.1.1 with parameter "no_fmt_off".
  16. # ruff: noqa: PGH004
  17. # ruff: noqa
  18. from __future__ import annotations
  19. from typing import Literal, TYPE_CHECKING, TypeAlias
  20. from protobuf import Message
  21. from protobuf._codegen import file_desc
  22. if TYPE_CHECKING:
  23. from protobuf import DescFile
  24. _FieldMaskFields: TypeAlias = Literal["paths"]
  25. class FieldMask(Message[_FieldMaskFields]):
  26. """
  27. `FieldMask` represents a set of symbolic field paths, for example:
  28. paths: "f.a"
  29. paths: "f.b.d"
  30. Here `f` represents a field in some root message, `a` and `b`
  31. fields in the message found in `f`, and `d` a field found in the
  32. message in `f.b`.
  33. Field masks are used to specify a subset of fields that should be
  34. returned by a get operation or modified by an update operation.
  35. Field masks also have a custom JSON encoding (see below).
  36. # Field Masks in Projections
  37. When used in the context of a projection, a response message or
  38. sub-message is filtered by the API to only contain those fields as
  39. specified in the mask. For example, if the mask in the previous
  40. example is applied to a response message as follows:
  41. f {
  42. a : 22
  43. b {
  44. d : 1
  45. x : 2
  46. }
  47. y : 13
  48. }
  49. z: 8
  50. The result will not contain specific values for fields x,y and z
  51. (their value will be set to the default, and omitted in proto text
  52. output):
  53. f {
  54. a : 22
  55. b {
  56. d : 1
  57. }
  58. }
  59. A repeated field is not allowed except at the last position of a
  60. paths string.
  61. If a FieldMask object is not present in a get operation, the
  62. operation applies to all fields (as if a FieldMask of all fields
  63. had been specified).
  64. Note that a field mask does not necessarily apply to the
  65. top-level response message. In case of a REST get operation, the
  66. field mask applies directly to the response, but in case of a REST
  67. list operation, the mask instead applies to each individual message
  68. in the returned resource list. In case of a REST custom method,
  69. other definitions may be used. Where the mask applies will be
  70. clearly documented together with its declaration in the API. In
  71. any case, the effect on the returned resource/resources is required
  72. behavior for APIs.
  73. # Field Masks in Update Operations
  74. A field mask in update operations specifies which fields of the
  75. targeted resource are going to be updated. The API is required
  76. to only change the values of the fields as specified in the mask
  77. and leave the others untouched. If a resource is passed in to
  78. describe the updated values, the API ignores the values of all
  79. fields not covered by the mask.
  80. If a repeated field is specified for an update operation, new values will
  81. be appended to the existing repeated field in the target resource. Note that
  82. a repeated field is only allowed in the last position of a `paths` string.
  83. If a sub-message is specified in the last position of the field mask for an
  84. update operation, then new value will be merged into the existing sub-message
  85. in the target resource.
  86. For example, given the target message:
  87. f {
  88. b {
  89. d: 1
  90. x: 2
  91. }
  92. c: [1]
  93. }
  94. And an update message:
  95. f {
  96. b {
  97. d: 10
  98. }
  99. c: [2]
  100. }
  101. then if the field mask is:
  102. paths: ["f.b", "f.c"]
  103. then the result will be:
  104. f {
  105. b {
  106. d: 10
  107. x: 2
  108. }
  109. c: [1, 2]
  110. }
  111. An implementation may provide options to override this default behavior for
  112. repeated and message fields.
  113. Note that libraries which implement FieldMask resolution have various
  114. different behaviors in the face of empty masks or the special "*" mask.
  115. When implementing a service you should confirm these cases have the
  116. appropriate behavior in the underlying FieldMask library that you desire,
  117. and you may need to special case those cases in your application code if
  118. the underlying field mask library behavior differs from your intended
  119. service semantics.
  120. Update methods implementing https://google.aip.dev/134
  121. - MUST support the special value * meaning "full replace"
  122. - MUST treat an omitted field mask as "replace fields which are present".
  123. Other methods implementing https://google.aip.dev/157
  124. - SHOULD support the special value "*" to mean "get all".
  125. - MUST treat an omitted field mask to mean "get all", unless otherwise
  126. documented.
  127. ## Considerations for HTTP REST
  128. The HTTP kind of an update operation which uses a field mask must
  129. be set to PATCH instead of PUT in order to satisfy HTTP semantics
  130. (PUT must only be used for full updates).
  131. # JSON Encoding of Field Masks
  132. In JSON, a field mask is encoded as a single string where paths are
  133. separated by a comma. Fields name in each path are converted
  134. to/from lower-camel naming conventions.
  135. As an example, consider the following message declarations:
  136. message Profile {
  137. User user = 1;
  138. Photo photo = 2;
  139. }
  140. message User {
  141. string display_name = 1;
  142. string address = 2;
  143. }
  144. In proto a field mask for `Profile` may look as such:
  145. mask {
  146. paths: "user.display_name"
  147. paths: "photo"
  148. }
  149. In JSON, the same mask is represented as below:
  150. {
  151. mask: "user.displayName,photo"
  152. }
  153. # Field Masks and Oneof Fields
  154. Field masks treat fields in oneofs just as regular fields. Consider the
  155. following message:
  156. message SampleMessage {
  157. oneof test_oneof {
  158. string name = 4;
  159. SubMessage sub_message = 9;
  160. }
  161. }
  162. The field mask can be:
  163. mask {
  164. paths: "name"
  165. }
  166. Or:
  167. mask {
  168. paths: "sub_message"
  169. }
  170. Note that oneof type names ("test_oneof" in this case) cannot be used in
  171. paths.
  172. ## Field Mask Verification
  173. The implementation of any API method which has a FieldMask type field in the
  174. request should verify the included field paths, and return an
  175. `INVALID_ARGUMENT` error if any path is unmappable.
  176. ```proto
  177. message google.protobuf.FieldMask
  178. ```
  179. Attributes:
  180. paths:
  181. The set of field mask paths.
  182. ```proto
  183. repeated string paths = 1;
  184. ```
  185. """
  186. __slots__ = ("paths",)
  187. if TYPE_CHECKING:
  188. def __init__(self, *, paths: list[str] | None = None) -> None:
  189. pass
  190. paths: list[str]
  191. _DESC = file_desc(
  192. b'\n google/protobuf/field_mask.proto\x12\x0fgoogle.protobuf"!\n\tFieldMask\x12\x14\n\x05paths\x18\x01 \x03(\tR\x05pathsB\x85\x01\n\x13com.google.protobufB\x0eFieldMaskProtoP\x01Z2google.golang.org/protobuf/types/known/fieldmaskpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3',
  193. [],
  194. {"FieldMask": FieldMask},
  195. )
  196. def desc() -> DescFile:
  197. """Returns the descriptor for the file `google/protobuf/field_mask.proto`."""
  198. return _DESC