Add some more reserved type annotations (#134)

I think it would be useful to get these few more common data types into 
For the decimal floating types, I referenced [this protobuf discussion](https://github.com/protocolbuffers/protobuf/pull/7039#issuecomment-679083593) and [this](https://github.com/googleapis/googleapis/blob/master/google/type/decimal.proto)

I'm not sure what to call out for the currency format, I can't find a standard for that yet. There's a [protobuf money type](https://github.com/googleapis/googleapis/blob/master/google/type/money.proto) that's basically a ISO 4217 currency code plus a decimal number, but I don't really want to invent a suggested money format if there's a real one out there somewhere.
For this PR, can we just leave it TBD in order to reserve the type keyword?
This commit is contained in:
Eric Sampson 2021-09-11 22:46:32 -05:00 committed by GitHub
parent 0cdda0b711
commit f0bc492021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View File

@ -273,10 +273,16 @@ and property names when the `node-names` or `prop-names` options are activated.
* `pattern`: Regex pattern or patterns to test prop values against. Specific regex syntax may be implementation-dependent. * `pattern`: Regex pattern or patterns to test prop values against. Specific regex syntax may be implementation-dependent.
* `min-length`: Minimum length, if a string. * `min-length`: Minimum length, if a string.
* `max-length`: Maximum length, if a string. * `max-length`: Maximum length, if a string.
* `format`: Intended data format, if the value is a string. Possible values are: * `format`: Intended data format, if the value is a string. Reserved values are:
* `date-time`: ISO8601 date/time format. * `date-time`: ISO8601 date/time format.
* `time`: "Time" section of ISO8601. * `time`: "Time" section of ISO8601.
* `date`: "Date" section of ISO8601. * `date`: "Date" section of ISO8601.
* `duration`: ISO8601 duration format.
* `decimal`: IEEE 754-2008 decimal string format.
* `currency`: ISO 4217 currency code.
* `country-2`: ISO 3166-1 alpha-2 country code.
* `country-3`: ISO 3166-1 alpha-3 country code.
* `country-subdivision`: ISO 3166-2 country subdivision code.
* `email`: RFC5302 email address. * `email`: RFC5302 email address.
* `idn-email`: RFC6531 internationalized email address. * `idn-email`: RFC6531 internationalized email address.
* `hostname`: RFC1132 internet hostname. * `hostname`: RFC1132 internet hostname.
@ -300,6 +306,21 @@ and property names when the `node-names` or `prop-names` options are activated.
* `>=`: Greater than or equal to. * `>=`: Greater than or equal to.
* `<`: Less than. * `<`: Less than.
* `<=`: Less than or equal to. * `<=`: Less than or equal to.
* `format`: Intended data format for numeric values. Reserved values are:
* `i8`: 8-bit signed integer
* `i16`: 16-bit signed integer
* `i32`: 32-bit signed integer
* `i64`: 64-bit signed integer
* `u8`: 8-bit unsigned integer
* `u16`: 16-bit unsigned integer
* `u32`: 32-bit unsigned integer
* `u64`: 64-bit unsigned integer
* `isize`: Platform-dependent signed integer
* `usize`: Platform-dependent unsigned integer
* `f32`: IEEE 754 single (32-bit) precision floating point number
* `f64`: IEEE 754 double (64-bit) precision floating point number
* `decimal64`: IEEE 754-2008 64-bit decimal floating point number
* `decimal128`: IEEE 754-2008 128-bit decimal floating point number
### `definitions` node ### `definitions` node

13
SPEC.md
View File

@ -236,16 +236,29 @@ Platform-dependent integer types, both signed and unsigned:
* `isize` * `isize`
* `usize` * `usize`
#### Reserved Type Annotations for Numbers With Decimals:
IEEE 754 floating point numbers, both single (32) and double (64) precision: IEEE 754 floating point numbers, both single (32) and double (64) precision:
* `f32` * `f32`
* `f64` * `f64`
IEEE 754-2008 decimal floating point numbers
* `decimal64`
* `decimal128`
#### Reserved Type Annotations for Strings: #### Reserved Type Annotations for Strings:
* `date-time`: ISO8601 date/time format. * `date-time`: ISO8601 date/time format.
* `time`: "Time" section of ISO8601. * `time`: "Time" section of ISO8601.
* `date`: "Date" section of ISO8601. * `date`: "Date" section of ISO8601.
* `duration`: ISO8601 duration format.
* `decimal`: IEEE 754-2008 decimal string format.
* `currency`: ISO 4217 currency code.
* `country-2`: ISO 3166-1 alpha-2 country code.
* `country-3`: ISO 3166-1 alpha-3 country code.
* `country-subdivision`: ISO 3166-2 country subdivision code.
* `email`: RFC5302 email address. * `email`: RFC5302 email address.
* `idn-email`: RFC6531 internationalized email address. * `idn-email`: RFC6531 internationalized email address.
* `hostname`: RFC1132 internet hostname. * `hostname`: RFC1132 internet hostname.

View File

@ -263,13 +263,13 @@ document {
type "number" type "number"
} }
} }
node "format" description="Intended data format, if the value is a string." { node "format" description="Intended data format." {
max 1 max 1
value { value {
min 1 min 1
type "string" type "string"
// https://json-schema.org/understanding-json-schema/reference/string.html#format // https://json-schema.org/understanding-json-schema/reference/string.html#format
enum "date-time" "date" "time" "email" "idn-email" "hostname" "idn-hostname" "ipv4" "ipv6" "uri" "uri-reference" "iri", "iri-reference" "uri-template" "regex" "uuid" "kdl-query" enum "date-time" "date" "time" "duration" "decimal" "currency" "country-2" "country-3" "country-subdivision" "email" "idn-email" "hostname" "idn-hostname" "ipv4" "ipv6" "uri" "uri-reference" "iri", "iri-reference" "uri-template" "regex" "uuid" "kdl-query" "i8" "i16" "i32" "i64" "u8" "u16" "u32" "u64" "isize" "usize" "f32" "f64" "decimal64" "decimal128"
} }
} }
node "%" description="Only used for numeric values. Constrains them to be multiples of the given number(s)" { node "%" description="Only used for numeric values. Constrains them to be multiples of the given number(s)" {