Skip to main content
The 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 a true 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

If readOnly 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

The id field is generated by the server and cannot be set by clients.

Timestamps

Timestamps are managed by the server and cannot be modified by clients.

Computed Fields

Computed fields are derived by the server and cannot be set directly.

Status Fields

Status and calculated fields are controlled by the system.

writeOnly

If writeOnly 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

The password is accepted during registration but never returned in API responses.

Sensitive Data

Sensitive payment information is write-only for security.

API Keys

API keys are only revealed once and then stored in hashed form.

Combined Usage

User Account Schema

Combining both keywords for complete API resource modeling.

Password Change Request

Password change operations use write-only inputs and read-only confirmation.

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

Form generators can:
  • Hide the userId field on creation forms (readOnly)
  • Use password input widgets for password (writeOnly)
  • Omit write-only fields from display forms

Best Practices

Mark Server-Managed Fields as readOnly

Mark Secrets as writeOnly

Never Use Both on the Same Field

A field cannot be both readOnly and writeOnly:

Document the Reason