-
-
Notifications
You must be signed in to change notification settings - Fork 311
✨ Proposal: at least one property is required #1602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey there. Thanks for the idea. This is quite easy to do with the current keywords: {
"anyOf": [
{ "required": [ "to" ] },
{ "required": [ "bcc" ] }
]
} This requires that at least one of the properties to be present. |
Thank you, and I'm sorry for not reading the docs properly. Your suggestion works with a small tweak as below. schema.json{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "urn:hm:schemas:move-file-sftp-config",
"type": "object",
"title": "Move File Over SFTP Configuration",
"description": "Configuration schema for moving files over SFTP.",
"properties": {
"Settings": {
"type": "object",
"title": "Settings",
"description": "Various script settings.",
"properties": {
"SendMail": {
"type": "object",
"title": "Send Mail Settings",
"description": "Settings for sending email notifications.",
"properties": {
"To": {
"type": "array",
"title": "To",
"description": "An array of recipient email addresses.",
"items": { "type": "string", "format": "email" },
"uniqueItems": true
},
"Bcc": {
"type": "array",
"title": "Bcc",
"description": "An array of BCC email addresses.",
"items": { "type": "string", "format": "email" },
"uniqueItems": true
}
},
"required": [],
"anyOf": [
{ "required": ["To"], "properties": { "To": { "minItems": 1 } } },
{ "required": ["Bcc"], "properties": { "Bcc": { "minItems": 1 } } }
],
"errorMessage": "Either 'To' or 'Bcc' must contain at least one email address."
}
},
"required": ["SendMail"]
}
},
"required": ["Settings"]
} test.json{
"Settings": {
"SendMail": {
"To": ["[email protected]"],
"Bcc": []
}
}
} |
Hmmm,
Instead of the string
Found a similar issue on StackOverflow. |
|
Ah, got it. Thanks for clarifying. So there's no way to have a custom error message in case an |
Custom error messages would be an implementation thing. JSON Schema doesn't mandate any kind of messaging. |
Would be a great new feature I think. But thx anyway, this was really helpful. |
Describe the inspiration for your proposal
It would be great if it was possible to define that either field y or x is required.
Describe the proposal
If you want to send an email you can either have a
to
field orbcc
field or both, but none is not acceptable.Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: