Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 4df1a5c

Browse files
committed
Document const keyword
1 parent ffd5185 commit 4df1a5c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

source/reference/generic.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,38 @@ be valid against the enclosing schema:
9797
// This is in the ``enum``, but it's invalid against ``{ "type":
9898
// "string" }``, so it's ultimately invalid:
9999
null
100+
101+
.. index::
102+
single: const
103+
single: constant values
104+
105+
.. _const:
106+
107+
Constant values
108+
---------------
109+
110+
|draft6|
111+
112+
The ``const`` keyword is used to restrict a value to a single value.
113+
114+
For example, to if you only support shipping to the United States for export reasons:
115+
116+
.. schema_example::
117+
118+
{
119+
"properties": {
120+
"country": {
121+
"const": "United States of America"
122+
}
123+
}
124+
}
125+
--
126+
{ "country": "United States of America" }
127+
--X
128+
{ "country": "Canada" }
129+
130+
It should be noted that ``const`` is merely syntactic sugar for an ``enum`` with a single element, therefore the following are equivalent::
131+
132+
{ "const": "United States of America" }
133+
134+
{ "enum": [ "United States of America" ] }

0 commit comments

Comments
 (0)