readOnly and writeOnly keywords indicate whether a property should be included in requests or responses. These are essential for API documentation and data flow control.
Syntax
The value of both keywords must be a boolean.Purpose
These keywords are metadata annotations that:- Control the directionality of data flow in APIs
- Indicate which properties are managed by the server (
readOnly) - Indicate which properties are never returned by the server (
writeOnly) - Help generate appropriate user interfaces
- Can be used by API documentation tools
- Have no effect on validation (they are purely informational)
Behavior
When multiple occurrences of these keywords are applicable to a single sub-instance, the resulting behavior should be as for atrue value if any occurrence specifies a true value, and should be as for a false value otherwise.
Omitting these keywords has the same behavior as values of false.
readOnly
IfreadOnly has a value of boolean true, it indicates that the corresponding value in the instance is managed exclusively by the owning authority, and attempts by an application to modify the value are expected to be ignored or rejected by that owning authority.
An instance document that is marked as readOnly for the entire document may be ignored if sent to the owning authority, or may result in an error, at the authority’s discretion.
readOnly Examples
Database-Generated ID
id field is generated by the server and cannot be set by clients.
Timestamps
Computed Fields
Status Fields
writeOnly
IfwriteOnly has a value of boolean true, it indicates that the value is never present when the instance is retrieved from the owning authority. It can be present when sent to the owning authority to update or create the document (or the resource it represents), but it will not be included in any updated or newly created version of the instance.
An instance document that is marked as writeOnly for the entire document may be returned as a blank document of some sort, or may produce an error upon retrieval, or have the retrieval request ignored, at the authority’s discretion.
writeOnly Examples
Password Field
Sensitive Data
API Keys
Combined Usage
User Account Schema
Password Change Request
User Interface Applications
These keywords can be used to assist in user interface instance generation. In particular, an application may choose to use a widget that hides input values as they are typed for write-only fields.Form Generation Example
- Hide the
userIdfield on creation forms (readOnly) - Use password input widgets for
password(writeOnly) - Omit write-only fields from display forms