Skip to content

Commit bb610fd

Browse files
rofrankelgibson042
andauthored
Create the Money type. (#116)
* Add a schema definition for the `Money` type. * Add a protobuf implementation of the Money type. * Update common-components/proto/api/type/money.proto * Update common-components/proto/api/type/money.proto * Update common-components/proto/api/type/money.proto * Change currency code extension prefix to X-. * Update decimal import. * Consistency updates * Add a JSON schema for Money. * Make JSON schema examples look like JSON. * Improvements to JSON schema for Money: * Specify required fields * Disallow additional properties * Add trailing newline. * Rename amount to quantity. Also, fix the "One and a half Bitcoin" example. * Update common-components/json_schema/money.yaml Co-authored-by: Richard Gibson <[email protected]> --------- Co-authored-by: Richard Gibson <[email protected]>
1 parent f77c497 commit bb610fd

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$schema: https://json-schema.org/draft/2020-12/schema
2+
$id: https://example.com/product.schema.json
3+
title: Money
4+
description: |
5+
Represents an amount of money with its currency type.
6+
7+
Examples:
8+
9+
Five US dollars === `{"currency_code": "USD", "quantity": {"significand": 5}}`
10+
One and a half Bitcoin ===
11+
`{"currency_code": "X-BTC", "quantity": {"significand": 15, "exponent": -1}}`
12+
type: object
13+
required:
14+
- currency_code
15+
- quantity
16+
additionalProperties: false
17+
properties:
18+
currency_code:
19+
description: |
20+
A currency code.
21+
22+
This may be a three-letter currency code defined in ISO 4217.
23+
24+
APIs may define additional currency codes that are not included in the ISO
25+
4217 standard (for example, virtual currencies or cryptocurrencies). These
26+
must start with "X-", in order to distinguish them from potential future
27+
ISO 4217 codes.
28+
29+
Examples:
30+
"USD" - ISO 4217 code for United States dollar.
31+
"X-BTC" - Potential API-defined extension for Bitcoin.
32+
"X-RBX" - Potential API-defined extension for the virtual currency Robux.
33+
type: string
34+
quantity:
35+
description: The quantity of currency.
36+
$ref: decimal.yaml#/definitions/Decimal
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
syntax = "proto3";
2+
3+
package aip.type;
4+
5+
option cc_enable_arenas = true;
6+
option go_package = "aip.golang.org/genproto/common-components/type/money;money";
7+
option java_multiple_files = true;
8+
option java_outer_classname = "MoneyProto";
9+
option java_package = "dev.aip.type";
10+
option objc_class_prefix = "AIP";
11+
12+
import "aip/type/decimal.proto";
13+
14+
// Represents an amount of money with its currency type.
15+
//
16+
// Examples:
17+
//
18+
// Five US dollars === `{currency_code: "USD" quantity: {significand: 5}}`
19+
// One and a half Bitcoin ===
20+
// `{currency_code: "X-BTC" quantity: {significand: 15 exponent: -1}}`
21+
message Money {
22+
// A currency code.
23+
//
24+
// This may be a three-letter currency code defined in ISO 4217.
25+
//
26+
// APIs may define additional currency codes that are not included in the ISO
27+
// 4217 standard (for example, virtual currencies or cryptocurrencies). These
28+
// must start with "X-", in order to distinguish them from potential future
29+
// ISO 4217 codes.
30+
//
31+
// Examples:
32+
// "USD" - ISO 4217 code for United States dollar.
33+
// "X-BTC" - Potential API-defined extension for Bitcoin.
34+
// "X-RBX" - Potential API-defined extension for the virtual currency Robux.
35+
string currency_code = 1;
36+
37+
// The quantity of currency.
38+
Decimal quantity = 2;
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Money
2+
3+
The `Money` type represents an amount of money in a specified currency.
4+
5+
## Schema
6+
7+
A `Money` has two fields:
8+
9+
- The `currency_code` field is a string containing a currency code.
10+
11+
The three-letter currency codes defined in the ISO 4217 standard are always
12+
supported.
13+
14+
APIs may define additional currency codes that are not included in ISO 4217
15+
(for example, virtual currencies or cryptocurrencies). These must start with
16+
with "X-", in order to distinguish them from potential future ISO 4217 codes.
17+
18+
Examples:
19+
20+
- "USD" - ISO 4217 code for United States dollar
21+
- "X-BTC" - Potential API-defined extension for Bitcoin.
22+
- "X-.RBX" - Potential API-defined extension for the virtual currency Robux
23+
24+
- The `quantity` field is a field of type [`Decimal`][], representing the
25+
quantity of currency.
26+
27+
## Examples
28+
29+
- Five US dollars === `{currency_code: "USD", quantity: {significand: 5}}`
30+
- One and a half Bitcoin ===
31+
`{currency_code: "X-BTC", quantity: {significand: 15, exponent: -1}}`
32+
33+
<!--prettier-ignore-start-->
34+
[`Decimal`]: ./decimal.md
35+
<!--prettier-ignore-end-->

0 commit comments

Comments
 (0)