Overview
Annotation keywords provide commonly used information for documentation and user interface display purposes. They are not intended to form a comprehensive set of features. Rather, additional keywords can be defined for more complex annotation-based applications.Annotation keywords produce no assertion result and therefore are not considered during validation. They provide metadata about the schema and instances.
Characteristics
Annotation keywords:- Do not affect validation success or failure
- Provide information for documentation
- Guide user interface generation
- Describe the purpose and usage of data
- Can be collected by implementations for reporting
Documentation Keywords
title
Provides a short, human-readable title for the schema.
Value: String
description
Provides a detailed explanation about the purpose of the schema or property.
Value: String
Example: Combined Title and Description
Default Values
default
Supplies a default JSON value associated with a particular schema.
Value: Any JSON value
It is RECOMMENDED that a default value be valid against the associated schema. However, this is not enforced.
Behavior with Multiple Occurrences
Behavior with Multiple Occurrences
When multiple occurrences of this keyword are applicable to a single sub-instance, implementations SHOULD remove duplicates.
Deprecation
deprecated
Indicates that a property or schema should not be used in new implementations.
Value: Boolean
Behavior
- Omitting this keyword has the same behavior as a value of
false - When multiple occurrences are applicable to a single sub-instance, applications SHOULD consider the instance location deprecated if any occurrence specifies
true - A root schema containing
deprecated: trueindicates that the entire resource being described may be removed in the future
Deprecation with Arrays and Objects
Deprecation with Arrays and Objects
The In this example, each item in the array is marked as deprecated, but the array itself is not deprecated.
deprecated keyword applies to each instance location to which the schema object successfully applies. This can result in scenarios where every array item or object property is deprecated even though the containing array or object is not.Example:Read/Write Semantics
These keywords indicate directionality of data flow between client and server.readOnly
Indicates that a value is managed exclusively by the owning authority.
Value: Boolean
If
readOnly has a value of boolean true, it indicates that attempts by an application to modify the value are expected to be ignored or rejected by the owning authority.Behavior
- An instance document marked as
readOnlyfor the entire document may be ignored if sent to the owning authority, or may result in an error - Typically used for database-generated values like IDs, timestamps, or calculated fields
- User interfaces MAY display read-only fields as non-editable
writeOnly
Indicates that a value is never present when retrieved from the owning authority.
Value: Boolean
Behavior
- An instance document marked as
writeOnlyfor the entire document may be returned as a blank document, produce an error upon retrieval, or have the retrieval request ignored - Typically used for sensitive fields like passwords, API keys, or credit card numbers
- User interfaces MAY use a widget that hides input values (e.g., password field) for write-only fields
Common Use Cases
Common Use Cases
readOnly examples:- Database-generated serial numbers
- Created/updated timestamps
- Calculated fields (e.g., full name derived from first + last)
- System status fields
writeOnly examples:- Passwords
- API keys
- Credit card numbers
- Security tokens
Combined Example
Omitting
readOnly or writeOnly has the same behavior as values of false.Behavior with Multiple Occurrences
Behavior with Multiple Occurrences
When multiple occurrences of these keywords are applicable to a single sub-instance, the resulting behavior SHOULD be as for a
true value if any occurrence specifies a true value, and SHOULD be as for a false value otherwise.Examples
examples
Provides sample JSON values associated with a schema for illustrating usage.
Value: Array (no restrictions on values within the array)
Multiple Examples for Complex Objects
Behavior with Multiple Occurrences
Behavior with Multiple Occurrences
When multiple occurrences of this keyword are applicable to a single sub-instance, implementations MUST provide a flat array of all values rather than an array of arrays.
Implementations MAY use the value(s) of
default, if present, as an additional example. If examples is absent, default MAY still be used in this manner.Complete Example: API Resource Schema
Use Cases
API Documentation
Generate comprehensive API documentation from schemas with titles, descriptions, and examples
Form Generation
Build user interfaces that respect readOnly/writeOnly semantics and provide helpful labels
Code Generation
Generate model classes with appropriate access modifiers based on read/write semantics
Validation Messages
Provide user-friendly error messages using titles and descriptions
Best Practices
- Always include descriptions: Make schemas self-documenting with clear, concise descriptions
- Use titles for UI labels: Provide short, user-friendly titles for form field labels
- Validate defaults: Ensure default values actually validate against the schema
- Provide realistic examples: Use examples that demonstrate actual, valid use cases
-
Mark sensitive fields writeOnly: Always use
writeOnly: truefor passwords and secrets - Document deprecated features: When deprecating, explain what to use instead and when removal is planned
- Be consistent: Use annotation keywords consistently across your API schemas
Related Topics
- Structural Validation - Type and structural constraints
- Format Validation - Semantic format validation
- Content Validation - String-encoded data keywords