From 492558e02072923617110b69913a01536e7ac7b6 Mon Sep 17 00:00:00 2001 From: techmannih Date: Tue, 14 Jan 2025 18:09:34 +0530 Subject: [PATCH 1/2] improve enum doc --- .../reference/enum.md | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pages/understanding-json-schema/reference/enum.md b/pages/understanding-json-schema/reference/enum.md index 2883bbad7..441e7b264 100644 --- a/pages/understanding-json-schema/reference/enum.md +++ b/pages/understanding-json-schema/reference/enum.md @@ -1,12 +1,6 @@ --- title: "Enumerated values" section: docs -prev: - label: Comments - url: /understanding-json-schema/reference/comments -next: - label: Constant values - url: /understanding-json-schema/reference/const --- The `enum` [keyword](../../learn/glossary#keyword) is used to restrict a value to a fixed set of values. @@ -18,16 +12,21 @@ The following is an example for validating street light colors: ```json // props { "isSchema": true } { - "enum": ["red", "amber", "green"] + "properties": { + "color": { + "enum": ["red", "amber", "green"] + } + } } ``` ```json // props { "indent": true, "valid": true } -"red" +{ "color": "red" } ``` + ```json // props { "indent": true, "valid": false } -"blue" +{ "color": "blue" } ``` You can use `enum` even without a type, to accept values of different @@ -37,22 +36,25 @@ also add 42, just for fun. ```json // props { "isSchema": true } { - "enum": ["red", "amber", "green", null, 42] + "properties": { + "color": { + "enum": ["red", "amber", "green", null, 42] + } + } } ``` + ```json // props { "indent": true, "valid": true } -"red" -``` -```json -// props { "indent": true, "valid": true } -null +{ "color": null } ``` + ```json // props { "indent": true, "valid": true } -42 +{ "color": 42 } ``` + ```json // props { "indent": true, "valid": false } -0 -``` +{ "color": "blue" } +``` \ No newline at end of file From 382fa99d87446d3004e7fe5274c64eba9d280531 Mon Sep 17 00:00:00 2001 From: techmannih Date: Tue, 14 Jan 2025 18:16:42 +0530 Subject: [PATCH 2/2] add prev and next --- pages/understanding-json-schema/reference/enum.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/understanding-json-schema/reference/enum.md b/pages/understanding-json-schema/reference/enum.md index 441e7b264..8a1914fbe 100644 --- a/pages/understanding-json-schema/reference/enum.md +++ b/pages/understanding-json-schema/reference/enum.md @@ -1,6 +1,12 @@ --- title: "Enumerated values" section: docs +prev: + label: Comments + url: /understanding-json-schema/reference/comments +next: + label: Constant values + url: /understanding-json-schema/reference/const --- The `enum` [keyword](../../learn/glossary#keyword) is used to restrict a value to a fixed set of values.