generated from json-schema-org/repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add boolean property to employee object schema
- Loading branch information
1 parent
a1b5c7d
commit 129690b
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const code: any = { | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "string", | ||
}, | ||
age: { | ||
type: "number", | ||
}, | ||
}, | ||
}; | ||
|
||
const validationSchema = { | ||
type: "object", | ||
properties: { | ||
type: { | ||
type: "string", | ||
const: "object", | ||
}, | ||
properties: { | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "object", | ||
properties: { | ||
type: { | ||
type: "string", | ||
const: "string", | ||
}, | ||
}, | ||
required: ["type"], | ||
}, | ||
age: { | ||
type: "object", | ||
properties: { | ||
type: { | ||
type: "string", | ||
const: "number", | ||
}, | ||
}, | ||
required: ["type"], | ||
}, | ||
isFullTime: { | ||
type: "object", | ||
properties: { | ||
type: { | ||
type: "string", | ||
const: "boolean", | ||
}, | ||
}, | ||
required: ["type"], | ||
}, | ||
}, | ||
required: ["name", "age", "isFullTime"], | ||
}, | ||
}, | ||
required: ["type", "properties"], | ||
}; | ||
|
||
const solution = structuredClone(code); | ||
solution.properties.isFullTime = { | ||
type: "boolean", | ||
}; | ||
module.exports = { | ||
code, | ||
solution, | ||
validationSchema, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: "Boolean" | ||
description: "Define a boolean property in a JSON Schema." | ||
keywords: "$schema, type, array, items, string, number" | ||
--- | ||
|
||
# Boolean | ||
|
||
Now we want to define a boolean property for our employee object - `isFullTime` | ||
|
||
```json highlightLineStart={4} | ||
{ | ||
"name": "John Doe ", | ||
"age": 25, | ||
"isFullTime": true | ||
} | ||
``` | ||
|
||
|
||
## Schema Definition | ||
|
||
We just need to define the `isFullTime` property in the schema with the type `boolean`. | ||
|
||
```json | ||
{ | ||
... | ||
"isFullTime": { | ||
"type": "boolean" | ||
} | ||
} | ||
|
||
``` | ||
add this definition to the schema which is given to you in the editor | ||
|