Skip to main content

Validate a record without saving it

A release test, a form or an integration can ask OpenRegister whether a record would be accepted, and if not on which properties, without saving it. The answer comes from the same checks a save runs, so validate says invalid exactly when a save would refuse the record for one of those rules.

API​

POST /api/objects/{register}/{schema}/validate
POST /api/objects/{register}/{schema}/validate?id={object}

The body is the sample record. Without id it is checked as a create; with id it is merged onto that stored object and checked as an update of it.

The answer is 200 for a well-formed request, valid or not:

{
"valid": false,
"errors": [
{ "property": "gemeente", "message": "Atlantis is not in the list.", "rule": "coded-value" }
]
}
StatusWhen
200The verdict, valid true or false.
403The caller may not create in this schema, or may not update the named object. A verdict can reveal whether a unique value exists, so it asks the same right a save would.
404The register or schema does not exist, or the named object cannot be read by the caller.

Nothing is written: no object, no audit entry, no object event, no webhook.

What is checked​

Each error names the rule that refused it:

ruleWhat refused the property
write-ruleDeclared bounds, repeating groups, geometry, read-only fields on an update, lenses. These name no single property (property is null).
schemaThe schema validator, when the schema validates hard or the record is a draft (as on save).
uniqueA unique field whose value another object already holds.
field-typeAn extended field type (colour, recurrence).
coded-valueA value outside its coded list.
concept-shapeA concept that does not match its scheme's declared shape.
dependent-valueA value its dependent-value table does not allow for the controlling property.

The coded-value and dependent-value rules run through ObjectSaveCheck, the same check their save listeners call, so the two cannot disagree. A rule whose own machinery fails refuses nothing, exactly as the save then goes ahead.

Other listeners that can refuse a save (administered validation rules, decision tables, state rules, quota) do not yet implement ObjectSaveCheck; until they do, validate does not report them.

From PHP​

Apps that consume the published contract call:

$verdict = $objectService->validateObject(object: $sample, register: 'zaken', schema: 'aanvraag', id: null);
$verdict->isValid(); // bool
$verdict->errors; // list of {property, message, rule}

OCA\OpenRegister\Contract\ObjectServiceInterface::validateObject() returns an ObjectValidationVerdict.