From eb33f6d710ec838a9967f04623593405aada9f88 Mon Sep 17 00:00:00 2001 From: JeelRajodiya Date: Sat, 2 Nov 2024 15:05:10 +0530 Subject: [PATCH] docs: remove unevaluated items lesson related to #61 and #96 --- .../04-Arrays/08-Unevaluated-Items/code.ts | 93 ------------------- .../08-Unevaluated-Items/instructions.mdx | 56 ----------- 2 files changed, 149 deletions(-) delete mode 100644 content/04-Arrays/08-Unevaluated-Items/code.ts delete mode 100644 content/04-Arrays/08-Unevaluated-Items/instructions.mdx diff --git a/content/04-Arrays/08-Unevaluated-Items/code.ts b/content/04-Arrays/08-Unevaluated-Items/code.ts deleted file mode 100644 index e49c34a..0000000 --- a/content/04-Arrays/08-Unevaluated-Items/code.ts +++ /dev/null @@ -1,93 +0,0 @@ -const code: any = { - type: "object", - properties: { - name: { - type: "string", - }, - age: { - type: "integer", - }, - skills: { - type: "array", - }, - }, -}; - -const solution = structuredClone(code); - -solution.properties.skills = { - ...solution.properties.skills, - prefixItems: [ - { enum: ["HTML", "CSS", "JavaScript"] }, - { enum: ["HTML", "CSS", "JavaScript"] }, - { enum: ["HTML", "CSS", "JavaScript"] }, - ], - unevaluatedItems: { - type: "string", - }, -}; - -const testCases = [ - { - input: { - name: "John Doe", - age: 30, - skills: ["HTML", "CSS", "JavaScript", "TypeScript"], - }, - expected: true, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["JavaScript", "CSS", "HTML", "TypeScript"], - }, - expected: true, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["JavaScript", "HTML", "CSS", "TypeScript"], - }, - expected: true, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["HTML", "CSS", "JavaScript", 123], - }, - expected: false, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["HTML", "CSS", "JavaScript", "TypeScript", "React"], - }, - expected: true, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["React", "Java", "Vue.js"], - }, - expected: false, - }, - { - input: { - name: "John Doe", - age: 30, - skills: ["HTML", "JavaScript", "TypeScript", "React", "Vue"], - }, - expected: false, - }, -]; - -module.exports = { - code, - solution, - testCases, -}; diff --git a/content/04-Arrays/08-Unevaluated-Items/instructions.mdx b/content/04-Arrays/08-Unevaluated-Items/instructions.mdx deleted file mode 100644 index bc783bf..0000000 --- a/content/04-Arrays/08-Unevaluated-Items/instructions.mdx +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: Unevaluated Items -description: Learn to handle unevaluated array items in JSON Schema. -keywords: unevaluatedItems, array, validation, JSON Schema, additionalItems ---- - - -# Unevaluated Items - -**What are Unevaluated Items?** - -So far, we have used `items`, `prefixItems` and `contains` [keywords](https://json-schema.org/learn/glossary#keyword) to define [subschemas](https://json-schema.org/learn/glossary#subschema) for the elements of an array. However, sometimes you many want to handle the items that are unevaluated by these keywords. - -In such cases, you can use the `unevaluatedItems` keyword to define a subschema for the unevaluated items in the array. - -- By definition, the `unevaluatedItems` subschema is always applied after `prefixItems`, `items`, and `contains` subschemas. -- As its name implies, `unevaluatedItems` applies to any array index that has not been previously evaluated. - - - -## Example - -Consider, we have defined array items with `prefixItems`. When you have items more than the defined `prefixItems`, you can use `unevaluatedItems` to define a subschemas for the remaining items. - - -```json -{ - "type": "array", - "prefixItems": [ - { "type": "number" }, - { "type": "string" } - ], - "unevaluatedItems": { "type": "number" } -} -``` - -In this case, first two items are evaluated by `prefixItems` and the remaining items are evaluated by `unevaluatedItems`. - - -## Task - -```json -{ - "name": "John Doe", - "age": 30, - "skills": ["HTML", "CSS", "JavaScript", "React", "Node.js"] -} -``` - -Modify the `skills` property of the given [schema](https://json-schema.org/learn/glossary#schema) on the such that, -- First three elements can have only "HTML", "CSS" and "JavaScript" as values (in any order), not anything else. -- The remaining elements are of type string. - -> **Hints:** -> - For the first constraint use `prefixItems` combined with `enum` keyword. -> - For the second constraint use `unevaluatedItems` keyword.