-
Notifications
You must be signed in to change notification settings - Fork 4
feat: AIP-140 – Field names #33
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 2 commits
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,131 @@ | ||||||
| # Field names | ||||||
|
|
||||||
| Naming fields in a way that is intuitive to users can often be one of the most | ||||||
| challenging aspects of designing an API. This is true for many reasons; often a | ||||||
| field name that seems entirely intuitive to the author can baffle a reader. | ||||||
|
|
||||||
| Additionally, users rarely use only one API; they use many APIs together. As a | ||||||
| result, a single company using the same name to mean different things (or | ||||||
| different names to mean the same thing) can often cause unnecessary confusion, | ||||||
| because users can no longer take what they've already learned from one API and | ||||||
| apply that to another. | ||||||
|
|
||||||
| In short, APIs are easiest to understand when field names are simple, | ||||||
| intuitive, and consistent with one another. | ||||||
|
|
||||||
| ## Guidance | ||||||
|
|
||||||
| Field names **should** be in correct American English. | ||||||
|
|
||||||
| Field names **should** clearly and precisely communicate the concept being | ||||||
| presented and avoid overly general names that are ambiguous. That said, field | ||||||
| names **should** avoid including unnecessary words. In particular, avoid | ||||||
| including adjectives that always apply and add little cognitive value. For | ||||||
| example, a `proxy_settings` field might be as helpful as | ||||||
| `shared_proxy_settings` if there is no unshared variant. | ||||||
|
|
||||||
| ### Case | ||||||
|
|
||||||
| Field definitions **must** use the appropriate case for the IDL being used | ||||||
| (`camelCase` for TypeScript, `lower_snake_case` for protocol buffers, and so | ||||||
| on). These names **should** be mapped to an appropriate naming convention in | ||||||
| JSON and in generated code. | ||||||
|
|
||||||
| Additionally, each word in the field **must not** begin with a number, because | ||||||
| it creates ambiguity when converting between snake case and camel case. | ||||||
| Similarly, snake case fields **must not** contain leading, trailing, or | ||||||
| adjacent underscores. | ||||||
|
|
||||||
| ### Consistency | ||||||
|
|
||||||
| APIs **should** endeavor to use the same name for the same concept and | ||||||
| different names for different concepts wherever possible. This includes names | ||||||
| across multiple APIs, in particular if those APIs are likely to be used | ||||||
| together. | ||||||
|
|
||||||
| ### Array fields | ||||||
|
|
||||||
| Repeated fields **must** use the proper plural form, such as `books` or | ||||||
|
||||||
| `authors`. On the other hand, non-array fields **should** use the singular form | ||||||
| such as `book` or `author`.. | ||||||
|
||||||
| such as `book` or `author`.. | |
| such as `book` or `author`. |
lukesneeringer marked this conversation as resolved.
Show resolved
Hide resolved
lukesneeringer marked this conversation as resolved.
Show resolved
Hide resolved
lukesneeringer marked this conversation as resolved.
Show resolved
Hide resolved
lukesneeringer marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are -> must or should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
| URLs, and URIs for URI segment. Field names **may** use a prefix in front of | |
| URLs, and `uri` for URI segment. Field names **may** use a prefix in front of |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| id: 140 | ||
| state: approved | ||
| created: 2019-07-22 | ||
| placement: | ||
| category: fields | ||
| order: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkistler: One thing we do is check type / name consistency.