rest-guide
rest-guide copied to clipboard
Use additionalProperties instead of separate key-value properties
From Smals guideline:
Can we adopt it? Similar: http://opensource.zalando.com/restful-api-guidelines/#216
Current guideline: https://www.belgif.be/specification/rest/api-guide/#rule-addi-prop
additionalProperties SHOULD be used exclusively to describe an object representing a map of key-value pairs. The keys of such maps don’t need to respect the naming rules for JSON properties (lowerCamelCase and English).
This describes when additionalProperties may be used; but doesn't explicitly recommend its use instead of separate key/value properties for the above use case.
Possible complications:
- additional metadata on a key or a value
- cases where multiple occurrences of keys are allowed
- using the property as query search parameter on collection resource requires that the API handles query params not defined in the OpenAPI file; which is in a grey area of the OpenAPI standard
Examples:
"alternateIds": [
{
"sourceConfidenceLevel": 90,
"type": "belgianEnterpriseNumber",
"value": 244640631,
"status": "validated"
}
],
"criteria": [
{
"name": "hasReferenceAddress",
"dataSource": "cbss",
"value": true
},
{
"name": "hasReferenceAddress",
"dataSource": "requester",
"value": false
}]