@@ -292,39 +292,46 @@ Structural validation alone may be insufficient to allow an application to
292
292
correctly utilize certain values. The ` format ` annotation keyword is defined to
293
293
allow schema authors to convey semantic information for a fixed subset of values
294
294
which are accurately described by authoritative resources, be they RFCs or other
295
- external specifications.
295
+ external specifications. Format values defined externally to this document
296
+ SHOULD also be based on such authoritative resources in order to foster
297
+ interoperability.
296
298
297
- The value of this keyword is called a format attribute. It MUST be a string. A
298
- format attribute can generally only validate a given set of instance types. If
299
- the type of the instance to validate is not in this set, validation for this
300
- format attribute and instance SHOULD succeed. All format attributes defined in
301
- this section apply to strings, but a format attribute can be specified to apply
302
- to any instance types defined in the data model defined in the [ core JSON
303
- Schema.] ( #json-schema ) [ ^ 1 ]
299
+ The value of this keyword MUST be a string. While this keyword can validate any
300
+ type, each distinct value will generally only validate a given set of instance
301
+ types. If the type of the instance to validate is not in this set, validation
302
+ for this keyword SHOULD succeed. All format values defined in this section apply
303
+ to strings, but a format value can be specified to apply to any instance types
304
+ defined in the data model defined in the [ core JSON Schema] ( #json-schema ) [ ^ 1 ] .
304
305
305
306
[ ^ 1 ] : Note that the ` type ` keyword in this specification defines an "integer"
306
307
type which is not part of the data model. Therefore a format attribute can be
307
308
limited to numbers, but not specifically to integers. However, a numeric format
308
- can be used alongside the ` type ` keyword with a value of "integer", or could be
309
- explicitly defined to always pass if the number is not an integer, which
309
+ can be used alongside the ` type ` keyword with a value of "integer", or it could
310
+ be explicitly defined to always pass if the number is not an integer, which
310
311
produces essentially the same behavior as only applying to integers.
311
312
312
- Implementing support for ` format ` as an annotation is REQUIRED (if the
313
- implementation supports annotation collection).
313
+ Implementations SHOULD provide assertion behavior for the format values defined
314
+ by this document[ ^ 2 ] and MUST refuse to process any schema which contains an
315
+ unsupported format value.
314
316
315
- Implementing support for ` format ` as an assertion is OPTIONAL. Implementations
316
- which choose to support assertion behavior:
317
+ [ ^ 2 ] : Assertion behavior is called out very explicitly because it is a departure
318
+ from previous iterations of this specification. Previously, ` format ` was an
319
+ annotation-only keyword by default and implementations that supported assertion
320
+ were required to offer some configuration that allowed users to explicitly
321
+ enable assertion. Assertion is now a requirement in order to meet user
322
+ expectations. See [ json-schema-org/json-schema-spec #1520 ] ( https://github.com/json-schema-org/json-schema-spec/issues/1520 ) for more.
323
+
324
+ In addition to the assertion behavior, this keyword also produces its value as
325
+ an annotation.
326
+
327
+ Implementations:
317
328
318
- - MUST still collect the keyword's value as an annotation (if the implementation
319
- supports annotation collection),
320
- - MUST provide a configuration option to enable assertion behavior, defaulting
321
- to annotation-only behavior
322
329
- SHOULD provide an implementation-specific best effort validation for each
323
- format attribute defined below ;[ ^ 3 ]
324
- - MAY choose to implement validation of any or all format attributes as a no-op
325
- by always producing a validation result of true; [ ^ 4 ]
326
- - SHOULD use a common parsing library for each format, or a well-known regular
327
- expression ;
330
+ format attribute defined in this document ;[ ^ 3 ]
331
+ - MAY support format values not defined in this document, but such support MUST
332
+ be configurable and disabled by default;
333
+ - SHOULD use a common parsing library or a well-known regular expression for
334
+ each format ;
328
335
- SHOULD clearly document how and to what degree each format attribute is
329
336
validated.
330
337
@@ -337,30 +344,18 @@ example, an instance string that does not contain an "@" is clearly not a valid
337
344
email address, and an "email" or "hostname" containing characters outside of
338
345
7-bit ASCII is likewise clearly invalid.
339
346
340
- [ ^ 4 ] : This matches the current reality of implementations, which provide widely
341
- varying levels of validation, including no validation at all, for some or all
342
- format attributes. It is also designed to encourage relying only on the
343
- annotation behavior and performing semantic validation in the application, which
344
- is the recommended best practice.
345
-
346
- The requirement for minimal validation of format attributes is
347
+ The requirement for minimal validation of format values in general is
347
348
intentionally vague and permissive, due to the complexity involved in many of
348
349
the attributes. Note in particular that the requirement is limited to syntactic
349
- checking; it is not to be expected that an implementation would send an email,
350
- attempt to connect to a URL, or otherwise check the existence of an entity
351
- identified by a format instance.
350
+ checking; implementations SHOULD NOT attempt to send an email, connect to a URL,
351
+ or otherwise check the existence of an entity identified by a format instance.
352
352
353
353
#### Custom format attributes
354
354
355
355
Implementations MAY support custom format attributes. Save for agreement between
356
356
parties, schema authors SHALL NOT expect a peer implementation to support such
357
357
custom format attributes.
358
358
359
- An implementation MUST NOT fail to collect unknown formats as annotations.
360
-
361
- When configured for assertion behavior for ` format ` , implementations MUST fail
362
- upon encountering unknown formats.
363
-
364
359
### Defined Formats
365
360
366
361
#### Dates, Times, and Duration
@@ -371,22 +366,17 @@ Date and time format names are derived from [RFC 3339, section 5.6](#rfc3339).
371
366
The duration format is from the ISO 8601 ABNF as given in Appendix A of RFC
372
367
3339 .
373
368
374
- Implementations supporting formats SHOULD implement support for the following
375
- attributes:
376
-
377
- - * date-time:* A string instance is valid against this attribute if it is a
369
+ - * date-time* : A string instance is valid against this attribute if it is a
378
370
valid representation according to the "date-time" ABNF rule (referenced above)
379
- - * date: * A string instance is valid against this attribute if it is a valid
371
+ - * date* : A string instance is valid against this attribute if it is a valid
380
372
representation according to the "full-date" ABNF rule (referenced above)
381
- - * time: * A string instance is valid against this attribute if it is a valid
373
+ - * time* : A string instance is valid against this attribute if it is a valid
382
374
representation according to the "full-time" ABNF rule (referenced above)
383
- - * duration: * A string instance is valid against this attribute if it is a valid
375
+ - * duration* : A string instance is valid against this attribute if it is a valid
384
376
representation according to the "duration" ABNF rule (referenced above)
385
377
386
378
Implementations MAY support additional attributes using the other format names
387
- defined anywhere in that RFC. If "full-date" or "full-time" are implemented, the
388
- corresponding short form ("date" or "time" respectively) MUST be implemented,
389
- and MUST behave identically. Implementations SHOULD NOT define extension
379
+ defined anywhere in that RFC. Implementations SHOULD NOT define extension
390
380
attributes with any name matching an RFC 3339 format unless it validates
391
381
according to the rules of that format.[ ^ 5 ]
392
382
@@ -400,7 +390,7 @@ likely either be promoted to fully specified attributes or dropped.
400
390
401
391
These attributes apply to string instances.
402
392
403
- A string instance is valid against these attributes if it is a valid Internet
393
+ A string instance is valid against these format values if it is a valid Internet
404
394
email address as follows:
405
395
406
396
- * email:* As defined by the "Mailbox" ABNF rule in [ RFC 5321, section
@@ -488,7 +478,7 @@ A regular expression, which SHOULD be valid according to the
488
478
[ ECMA-262] ( #ecma262 ) regular expression dialect.
489
479
490
480
Implementations that validate formats MUST accept at least the subset of
491
- ECMA-262 defined in {{regexinterop}}) , and SHOULD accept all valid ECMA-262
481
+ ECMA-262 defined in {{regexinterop}}, and SHOULD accept all valid ECMA-262
492
482
expressions.
493
483
494
484
## Keywords for the Contents of String-Encoded Data {#content}
0 commit comments