-
Notifications
You must be signed in to change notification settings - Fork 18
Adopt AEP-202: Fields #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
20c5dce
671cf6e
29efd03
64bd912
bbdfbd1
7d015e6
9e8378f
d7855ab
511125d
302d83a
4aa9c22
fafbd0d
5f38c6f
1eaa4e1
bd557c0
20dd825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Fields | ||
|
||
In many cases, a field's particular value can be represented in many different ways. | ||
String representations of dates are an excellent example, where a date can be represented in multiple ways | ||
and an API cannot necessarily normalize the data without additional information about its format. | ||
|
||
The allowed formats for a field's value must be properly documented and enforced so that the API | ||
can ensure that it receives data in a way that it can properly handle and send it back in a way | ||
that consumers expect. | ||
|
||
The [`buf.validate.FieldConstraints`][protovalidate] type, through its accompanying | ||
extension `buf.validate.field`, enriches a field's schema beyond the basic | ||
name and type information by specifying constraints or validation rules. | ||
|
||
## Guidance | ||
|
||
If a field follows a set pattern, it **should** be annotated with a `buf.validate.field` annotation. | ||
|
||
If a field has a `buf.validate.field` annotation, that annotation **must** be included on all requests and responses. | ||
|
||
If a field has a `buf.validate.field`, any values that do not follow the `buf.validate.field` annotation must return an error. | ||
|
||
If a field has a `buf.validate.field`, an API **must** return an error if it attempts to return a value that does not follow the annotation. | ||
|
||
|
||
#### Backwards compatibility | ||
|
||
Adding a validation rule to an existing, unspecified field **is not** backwards | ||
compatible, *unless* the field in question has always been documented as conforming to the format | ||
being specified. | ||
|
||
Changing an existing validation rule to a different one in all cases **is not** | ||
backwards compatible. | ||
|
||
## Rationale | ||
|
||
#### Why add a format specifier? | ||
|
||
The format of a primitive-typed field can be critical to its usability. Some | ||
programming languages may convey a specific type format as a standalone type, | ||
as Java does with [UUID][java uuid]. Most have specific structural requirements | ||
that are validated by the service, so conveying the format to the user ahead of | ||
time is critical to their experience. | ||
|
||
#### Why document value normalizations? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, what guidance does this refer to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above guidance should satisfy this rationale. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which guidance, specifically? As in, which line of the file says to document value normalization? The word "normalization" doesn't appear before line 37. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wasn't being precise enough about that. It was implicit. I've added some information in the beginning explaining how validators are useful for field normalization and why that process occurs. Let me know if it isn't precise enough. |
||
|
||
In many cases, the API will be responsible for parsing the user input and normalizing it | ||
into a value that the API expects. | ||
|
||
While primitive comparison is not recommended for any of the supported formats, | ||
uniform normalization of values is important to set consumer expectations, and | ||
create a user-friendly surface. | ||
|
||
[protovalidate]: https://github.com/bufbuild/protovalidate/tree/main/proto/protovalidate |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
id: 202 | ||
state: approved | ||
slug: fields | ||
created: 2024-07-12 | ||
placement: | ||
category: protobuf |
Uh oh!
There was an error while loading. Please reload this page.