-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Requirement
Add additional flexibility to imperativeConfiguration to allow for the containing property name to be considered when setting required fields for a type.
This functionality would mean that, for example, validating the below Organization type would depend on the property within which it was found - e.g. "broker".
"broker": {
"@type": "Organization",
"name": "Acme leisure"
}
Suggested design
Use imperativeConfigurationWithContext within the model files, which includes a map within requiredFields, recommendedFields, shallNotInclude and requiredOptions. This is an additional map of property names (see example below). These changes already exist dormantly in Organization.json and Person.json - just remove the placeholder empty "imperativeConfiguration".
Implementation hints
Implementation of this likely requires changes to src/rules/core/required-optional-fields-rule.js, src/rules/core/required-fields-rule.js, src/rules/core/recommended-fields-rule.js, and src/rules/core/shall-not-include-fields-rule.js within data-model-validator.
Example
"imperativeConfigurationWithContext": {
"request": {
"requiredFields": {
"broker": [
"id",
"name"
],
"seller": [
"id"
],
"customer": [
"email",
"name",
"address"
]
},
"recommendedFields": {
"broker": [
"email",
"url",
"logo"
],
"seller": [
],
"customer": [
]
}
},
"response": {
"requiredFields": {
"broker": [
],
"seller": [
"id",
"name",
"legalName",
"taxMode",
"vatID",
"address"
],
"customer": [
]
},
"recommendedFields": {
"broker": [
],
"seller": [
"email",
"url",
"logo"
],
"customer": [
]
}
}
},