Skip to content

Commit a6d35a6

Browse files
committed
feat(field_behavior, proto): add field behavior
Adding an AEP fork of field behavior. Adding and requiring these annotations will ensure an AEP-maintained annotation will be used in aep-2025 and beyond, future-proofing the need to add these annotations in APIs in lieu of Google's field behavior.
1 parent 9798ea1 commit a6d35a6

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2025 Google LLC
2+
// Copyright 2025 Yusuke Fredrick Tsutsumi
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+
syntax = "proto3";
17+
18+
package aep.api;
19+
20+
option cc_enable_arenas = true;
21+
option java_multiple_files = true;
22+
option java_outer_classname = "FieldBehaviorProto";
23+
option java_package = "dev.aep.api";
24+
option objc_class_prefix = "AEP";
25+
26+
// An indicator of the behavior of a given field (for example, that a field
27+
// is required in requests, or given as output but ignored as input).
28+
// This **does not** change the behavior in protocol buffers itself; it only
29+
// denotes the behavior and may affect how API tooling handles the field.
30+
//
31+
// Note: This enum **may** receive new values in the future.
32+
enum FieldBehavior {
33+
// Conventional default for enums. Do not use this.
34+
FIELD_BEHAVIOR_UNSPECIFIED = 0;
35+
36+
// Specifically denotes a field as optional.
37+
// While all fields in protocol buffers are optional, this may be specified
38+
// for emphasis if appropriate.
39+
OPTIONAL = 1;
40+
41+
// Denotes a field as required.
42+
// This indicates that the field **must** be provided as part of the request,
43+
// and failure to do so will cause an error (usually `INVALID_ARGUMENT`).
44+
REQUIRED = 2;
45+
46+
// Denotes a field as output only.
47+
// This indicates that the field is provided in responses, but including the
48+
// field in a request does nothing (the server *must* ignore it and
49+
// *must not* throw an error as a result of the field's presence).
50+
OUTPUT_ONLY = 3;
51+
52+
// Denotes a field as input only.
53+
// This indicates that the field is provided in requests, and the
54+
// corresponding field is not included in output.
55+
INPUT_ONLY = 4;
56+
57+
// Denotes a field as immutable.
58+
// This indicates that the field may be set once in a request to create a
59+
// resource, but may not be changed thereafter.
60+
IMMUTABLE = 5;
61+
62+
// Denotes that a (repeated) field is an unordered list.
63+
// This indicates that the service may provide the elements of the list
64+
// in any arbitrary order, rather than the order the user originally
65+
// provided. Additionally, the list's order may or may not be stable.
66+
UNORDERED_LIST = 6;
67+
68+
// Denotes that this field returns a non-empty default value if not set.
69+
// This indicates that if the user provides the empty value in a request,
70+
// a non-empty value will be returned. The user will not be aware of what
71+
// non-empty value to expect.
72+
NON_EMPTY_DEFAULT = 7;
73+
}

proto/aep-api/aep/api/field_info.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ package aep.api;
44

55
option cc_enable_arenas = true;
66
option java_multiple_files = true;
7-
option java_outer_classname = "FieldBehaviorProto";
7+
option java_outer_classname = "FieldInfoProto";
88
option java_package = "dev.aep.api";
99
option objc_class_prefix = "AEP";
1010

1111
import "google/protobuf/descriptor.proto";
1212
import "google/protobuf/duration.proto";
13+
import "aep/api/field_behavior.proto";
1314

1415
// A field option documenting the applicable lifetime of a field, e.g. an
1516
// idempotency key.
@@ -56,4 +57,7 @@ message FieldInfo {
5657
// }];
5758
// }
5859
repeated string resource_reference = 2;
60+
61+
// Describes the behavior of the field in requests and responses.
62+
repeated FieldBehavior field_behavior = 3;
5963
}

0 commit comments

Comments
 (0)