Skip to content

Commit 6b3dc9a

Browse files
authored
feat(143): adopt AEP 143 from google.aip.dev (#90)
Notable changes: - added OAS format.
1 parent d8d5935 commit 6b3dc9a

1 file changed

Lines changed: 116 additions & 3 deletions

File tree

aep/general/0143/aep.md.j2

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,118 @@
11
# Standardized codes
22

3-
**Note:** This AEP has not yet been adopted. See
4-
[this GitHub issue](https://github.com/aep-dev/aep.dev/issues/24) for more
5-
information.
3+
Many common concepts, such as spoken languages, countries, currency, and so on,
4+
have common codes (usually formalized by the [International Organization for
5+
Standardization][iso]) that are used in data communication and processing.
6+
These codes address the issue that there are often different ways to express
7+
the same concept in written language (for example, "United States" and "USA",
8+
or "Español" and "Spanish").
9+
10+
## Guidance
11+
12+
For concepts where a standardized code exists and is in common use, fields
13+
representing these concepts **should** use the standardized code for both input
14+
and output.
15+
16+
{% tab proto %}
17+
18+
```proto
19+
// A message representing a book.
20+
message Book {
21+
// Other fields...
22+
23+
// The IETF BCP-47 language code representing the language in which
24+
// the book was originally written.
25+
// https://en.wikipedia.org/wiki/IETF_language_tag
26+
string language_code = 99;
27+
}
28+
```
29+
30+
{% tab oas %}
31+
32+
```json
33+
34+
{
35+
"type": "object",
36+
"properties": {
37+
"language_code": {
38+
"type": "string",
39+
"description": "The IETF BCP-47 language code
40+
representing the language in which the book was originally written. See
41+
https://en.wikipedia.org/wiki/IETF_language_tag"
42+
}
43+
}
44+
}
45+
46+
```
47+
48+
{% endtabs %}
49+
50+
- Fields representing standardized concepts **must** use the appropriate data
51+
type for the standard code (usually `string`).
52+
- Fields representing standardized concepts **should not** use enums, even if
53+
they only allow a small subset of possible values. Using enums in this
54+
situation often leads to frustrating lookup tables when using multiple APIs
55+
together.
56+
- Fields representing standardized concepts **must** indicate which standard
57+
they follow, preferably with a link (either to the standard itself, the
58+
Wikipedia description, or something similar).
59+
- The field name **should** end in `_code` or `_type` unless the concept has an
60+
obviously clearer suffix.
61+
- When accepting values provided by users, validation **should** be
62+
case-insensitive unless this would introduce ambiguity (for example, accept
63+
both `en-gb` and `en-GB`). When providing values to users, APIs **should**
64+
use the canonical case (in the example above, `en-GB`).
65+
66+
### Content types
67+
68+
Fields representing a content or media type **must** use [IANA media types][].
69+
For legacy reasons, the field **should** be called `mime_type`.
70+
71+
### Countries and regions
72+
73+
Fields representing individual countries or nations **must** use the [Unicode
74+
CLDR region codes][cldr] ([list][]), such as `US` or `CH`, and the field
75+
**must** be called `region_code`.
76+
77+
**Important:** We use `region_code` and not `country_code` to include regions
78+
distinct from any country, and avoid political disputes over whether or not
79+
some regions are countries.
80+
81+
### Currency
82+
83+
Fields representing currency **must** use [ISO-4217 currency codes][iso-4217],
84+
such as `USD` or `CHF`, and the field **must** be called `currency_code`.
85+
86+
**Note:** For representing an amount of money in a particular currency, rather
87+
than the currency code itself, use the [aep type.money schema][money]
88+
89+
### Language
90+
91+
Fields representing spoken languages **must** use [IETF BCP-47 language
92+
codes][bcp-47] ([list][]), such as `en-US` or `de-CH`, and the field **must**
93+
be called `language_code`.
94+
95+
### Time zones
96+
97+
Fields representing a time zone **should** use the [IANA TZ][] codes, and the
98+
field **must** be called `time_zone`.
99+
100+
Fields also **may** represent a UTC offset rather than a time zone (note that
101+
these are subtly different). In this case, the field **must** use the [ISO-8601
102+
format][] to represent this, and the field **must** be named `utc_offset`.
103+
104+
## Changelog
105+
106+
- **2024-02-09**: Adopted text from https://google.aip.dev/143.
107+
108+
<!-- prettier-ignore-start -->
109+
[bcp-47]: https://en.wikipedia.org/wiki/IETF_language_tag
110+
[cldr]: http://cldr.unicode.org/
111+
[iana media types]: https://www.iana.org/assignments/media-types/media-types.xhtml
112+
[iana tz]: http://www.iana.org/time-zones
113+
[iso]: https://www.iso.org/
114+
[iso-4217]: https://en.wikipedia.org/wiki/ISO_4217
115+
[iso-8601 format]: https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
116+
[list]: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
117+
[money]: https://github.com/aep-dev/aep/blob/main/schemas/type/money.md
118+
<!-- prettier-ignore-end -->

0 commit comments

Comments
 (0)