-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for property & schema dependencies
- Loading branch information
Showing
9 changed files
with
508 additions
and
26 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
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,86 @@ | ||
module.exports = { | ||
schema: { | ||
title: "Property dependencies", | ||
description: "These samples are best viewed without live validation.", | ||
type: "object", | ||
properties: { | ||
unidirectional: { | ||
title: "Unidirectional", | ||
src: | ||
"https://spacetelescope.github.io/understanding-json-schema/reference/object.html#dependencies", | ||
description: | ||
"In the following example, whenever a `credit_card` property is provided, a `billing_address` property must also be present.", | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "string", | ||
}, | ||
credit_card: { | ||
type: "number", | ||
}, | ||
billing_address: { | ||
type: "string", | ||
}, | ||
}, | ||
required: ["name"], | ||
dependencies: { | ||
credit_card: ["billing_address"], | ||
}, | ||
}, | ||
bidirectional: { | ||
title: "Bidirectional", | ||
src: | ||
"https://spacetelescope.github.io/understanding-json-schema/reference/object.html#dependencies", | ||
description: | ||
"Dependencies are not bidirectional, you can, of course, define the bidirectional dependencies explicitly.", | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "string", | ||
}, | ||
credit_card: { | ||
type: "number", | ||
}, | ||
billing_address: { | ||
type: "string", | ||
}, | ||
}, | ||
required: ["name"], | ||
dependencies: { | ||
credit_card: ["billing_address"], | ||
billing_address: ["credit_card"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
uiSchema: { | ||
unidirectional: { | ||
credit_card: { | ||
"ui:help": | ||
"If you enter anything here then `billing_address` will become required.", | ||
}, | ||
billing_address: { | ||
"ui:help": | ||
"It’s okay to have a billing address without a credit card number.", | ||
}, | ||
}, | ||
bidirectional: { | ||
credit_card: { | ||
"ui:help": | ||
"If you enter anything here then `billing_address` will become required.", | ||
}, | ||
billing_address: { | ||
"ui:help": | ||
"If you enter anything here then `credit_card` will become required.", | ||
}, | ||
}, | ||
}, | ||
formData: { | ||
unidirectional: { | ||
name: "Tim", | ||
}, | ||
bidirectional: { | ||
name: "Jill", | ||
}, | ||
}, | ||
}; |
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,171 @@ | ||
module.exports = { | ||
schema: { | ||
title: "Schema dependencies", | ||
description: "These samples are best viewed without live validation.", | ||
type: "object", | ||
properties: { | ||
simple: { | ||
src: | ||
"https://spacetelescope.github.io/understanding-json-schema/reference/object.html#dependencies", | ||
title: "Simple", | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "string", | ||
}, | ||
credit_card: { | ||
type: "number", | ||
}, | ||
}, | ||
required: ["name"], | ||
dependencies: { | ||
credit_card: { | ||
properties: { | ||
billing_address: { | ||
type: "string", | ||
}, | ||
}, | ||
required: ["billing_address"], | ||
}, | ||
}, | ||
}, | ||
conditional: { | ||
title: "Conditional", | ||
$ref: "#/definitions/person", | ||
}, | ||
arrayOfConditionals: { | ||
title: "Array of conditionals", | ||
type: "array", | ||
items: { | ||
$ref: "#/definitions/person", | ||
}, | ||
}, | ||
fixedArrayOfConditionals: { | ||
title: "Fixed array of conditionals", | ||
type: "array", | ||
items: [ | ||
{ | ||
title: "Primary person", | ||
$ref: "#/definitions/person", | ||
}, | ||
], | ||
additionalItems: { | ||
title: "Additional person", | ||
$ref: "#/definitions/person", | ||
}, | ||
}, | ||
}, | ||
definitions: { | ||
person: { | ||
title: "Person", | ||
type: "object", | ||
properties: { | ||
"Do you have any pets?": { | ||
type: "string", | ||
enum: ["No", "Yes: One", "Yes: More than one"], | ||
default: "No", | ||
}, | ||
}, | ||
required: ["Do you have any pets?"], | ||
dependencies: { | ||
"Do you have any pets?": { | ||
oneOf: [ | ||
{ | ||
properties: { | ||
"Do you have any pets?": { | ||
enum: ["No"], | ||
}, | ||
}, | ||
}, | ||
{ | ||
properties: { | ||
"Do you have any pets?": { | ||
enum: ["Yes: One"], | ||
}, | ||
"How old is your pet?": { | ||
type: "number", | ||
}, | ||
}, | ||
required: ["How old is your pet?"], | ||
}, | ||
{ | ||
properties: { | ||
"Do you have any pets?": { | ||
enum: ["Yes: More than one"], | ||
}, | ||
"Do you want to get rid of any?": { | ||
type: "boolean", | ||
}, | ||
}, | ||
required: ["Do you want to get rid of any?"], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
uiSchema: { | ||
simple: { | ||
credit_card: { | ||
"ui:help": | ||
"If you enter anything here then `billing_address` will be dynamically added to the form.", | ||
}, | ||
}, | ||
conditional: { | ||
"Do you want to get rid of any?": { | ||
"ui:widget": "radio", | ||
}, | ||
}, | ||
arrayOfConditionals: { | ||
items: { | ||
"Do you want to get rid of any?": { | ||
"ui:widget": "radio", | ||
}, | ||
}, | ||
}, | ||
fixedArrayOfConditionals: { | ||
items: { | ||
"Do you want to get rid of any?": { | ||
"ui:widget": "radio", | ||
}, | ||
}, | ||
additionalItems: { | ||
"Do you want to get rid of any?": { | ||
"ui:widget": "radio", | ||
}, | ||
}, | ||
}, | ||
}, | ||
formData: { | ||
simple: { | ||
name: "Randy", | ||
}, | ||
conditional: { | ||
"Do you have any pets?": "No", | ||
}, | ||
arrayOfConditionals: [ | ||
{ | ||
"Do you have any pets?": "Yes: One", | ||
"How old is your pet?": 6, | ||
}, | ||
{ | ||
"Do you have any pets?": "Yes: More than one", | ||
"Do you want to get rid of any?": false, | ||
}, | ||
], | ||
fixedArrayOfConditionals: [ | ||
{ | ||
"Do you have any pets?": "No", | ||
}, | ||
{ | ||
"Do you have any pets?": "Yes: One", | ||
"How old is your pet?": 6, | ||
}, | ||
{ | ||
"Do you have any pets?": "Yes: More than one", | ||
"Do you want to get rid of any?": true, | ||
}, | ||
], | ||
}, | ||
}; |
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
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
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
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
Oops, something went wrong.