validonce rule format, version 1
Status: draft for Part 1 (2026-11-22). Changes to this file change the contract every implementation is tested against, so each change also updates conformance/.
Purpose
A server writes its cross-field validation rules once, in its own validation library (FluentValidation in C#, Pydantic in Python). validonce exports those rules as data in this format. Every evaluator — C#, TypeScript, Python — reads the same data and must reach the same result for the same input. The shared cases in conformance/rules/ are the proof.
Field-level rules (type, length, enum, pattern) are not part of this format. They already travel through standard JSON Schema keywords.
Where the data lives
On each object schema in an OpenAPI document (or a plain JSON Schema), under the key x-validonce:
{
"type": "object",
"properties": { "plan": { "type": "string" }, "company": { "type": ["string", "null"] } },
"x-validonce": {
"version": 1,
"rules": [
{
"id": "Signup.required_when.company",
"kind": "required_when",
"field": "company",
"when": { "eq": { "field": "plan", "value": "pro" } },
"message": { "key": "rules.company_required" }
}
]
}
}
The machine-readable schema for this object is conformance/schema/rule-format-v1.schema.json.
Canonical URL: https://schemas.metatoy.com/validonce/rules-v1.json (the schema's $id). Evaluators never fetch it; the URL is a stable name, so offline use is unaffected.
Common rule fields
| Field | Required | Meaning |
|---|---|---|
id | yes | Unique within the model. Exporters derive Model.kind.path when the author gives none, and fail on a collision |
kind | yes | One of the five kinds below |
path | no | The field the error is reported on. Defaults per kind (below) |
message | yes | { "key": string, "params"?: object }. Params values are strings, numbers, booleans or null |
server_only | no | true means clients skip the rule. The server always evaluates it |
All field names are wire names: the names in the JSON body, after aliases and naming policies are applied.
A v1 rule refers only to fields of the object it is attached to. A nested object carries its own rules; its issues are reported with the path prefix of where it sits (["items", "3", "end"]). Prefixing is the host's job, not the evaluator's.
Rule kinds
| Kind | Fields | Fails when | Default path |
|---|---|---|---|
required_when | field, when (condition) | when is true and field is blank | field |
compare | left ({ "field" }), op, right ({ "field" } or { "value" }), type | both sides pass the type check and the comparison is false | left.field |
at_least_one_of | fields (2 or more) | every listed field is blank | first of fields |
exactly_one_of | fields (2 or more) | the number of non-blank fields is not exactly one | first of fields |
all_or_none | fields (2 or more) | some, but not all, listed fields are blank | first of fields |
op is one of lt, le, gt, ge, eq, ne. type is one of number, string, date, datetime.
compare passes when either side is blank, and when either side fails its type check. Requiredness is always a separate rule. An exporter rejects a compare whose type does not match the JSON Schema type of its fields, so a type failure at runtime means the data is wrong, and field-level validation reports it.
Conditions (used by required_when)
Each condition is an object with exactly one key.
| Condition | Shape | True when |
|---|---|---|
eq | { "eq": { "field", "value" } } | the field's value strictly equals value |
ne | { "ne": { "field", "value" } } | eq would be false (so a blank field makes ne true) |
in | { "in": { "field", "values": [...] } } | eq is true for at least one of values |
present | { "present": { "field" } } | the field is not blank |
absent | { "absent": { "field" } } | the field is blank |
all | { "all": [conditions] } (1 or more) | every condition is true |
any | { "any": [conditions] } (1 or more) | at least one condition is true |
not | { "not": condition } | the condition is false |
value and the items of values are strings, numbers or booleans. null is not allowed; use absent.
Pinned behavior
These rules exist because languages disagree by default. Every evaluator follows them exactly.
- Evaluate the wire form. The evaluator receives the JSON value of the object, as it is or would be sent over the wire: C# evaluates the serialized JSON, Python evaluates
model_dump(mode="json", by_alias=True), TypeScript evaluates the parsed JSON (or the Zod-parsed output, which is the same shape). - Blank means: the key is missing, the value is
null, the value is"", or the value is[]. Nothing else is blank:" ",0,falseand{}are not blank. - No type coercion.
"1"is not1."true"is nottrue. A boolean is never a number (Python'sboolis a subclass ofint; implementations must check for it). - Strict equality (
eq,ne,in, andcomparewitheq/ne): same JSON type and same value. Numbers compare numerically (1equals1.0). Strings compare exactly, code point by code point, with no Unicode normalization and no case folding. An array or object value is never equal to anything, soeqon it is false. - Numbers are compared as IEEE 754 double-precision values.
- Strings in
comparewithlt/le/gt/geare ordered by Unicode code point, not by UTF-16 code unit. (JavaScript's<and C#'s ordinal comparison use UTF-16 code units and disagree with code-point order for characters above U+FFFF; implementations must compensate.) dateis a stringYYYY-MM-DDnaming a real calendar date, years 0001–9999. Anything else fails the type check. Year0000is outside this range even though ISO 8601 and some libraries allow it (Zod'sz.iso.date()accepts0000-01-01), so acompareof typedatepasses when either side is0000-…. In Zod,isoDate()andisoDateTime()fromvalidonce/zodmatch this range.datetimeis a stringYYYY-MM-DDTHH:MM:SS[.fraction](Z|±HH:MM), with an uppercaseTandZ, a real date, hours 00–23, minutes and seconds 00–59, and an offset whose hours are 00–23 and minutes 00–59. A value with no offset fails the type check. Values compare as instants in time, at millisecond precision: fraction digits after the third are ignored.- Order and count of issues. Rules are evaluated in array order. Each failing rule yields exactly one issue. Issues are returned in rule order.
- A field that is not in the data is blank. Rules may assume the rule data itself has been validated against the schema.
Issues
Every failing rule produces one issue, in the same shape everywhere — client evaluation, server responses after mapping, and the conformance cases:
{ "path": ["company"], "ruleId": "Signup.required_when.company", "key": "rules.company_required", "params": {} }
path: the rule'spath(or its default), as a one-element array at the evaluator; hosts add prefixes for nested objects.params: exactly the rule'smessage.params, or{}when it has none. Evaluators add nothing.
Server responses carry the same list: FastAPI's 422 body through each error's ctx, and ASP.NET through a ProblemDetails extension validonce. The JavaScript server-errors adapters turn either back into this list.
Transport (server responses)
How a server reports failing rules to a client. This is a convention for implementations, not part of the rule data, so it does not change the format version.
- Shape: an RFC 9457 problem details body (
application/problem+json) with the issue list as a top-level member namedvalidonce, holding the issues exactly as above. Other members (title,status,errors, …) are optional and free. - Status: 422 by default. A host may let users change it (ASP.NET:
ValidationStatusCode). - One response lists every failing rule, in the order the evaluator produced them.
- Who uses it: ASP.NET Core, and every backend added after it (Go, Spring, Fastify, NestJS). FastAPI keeps its native 422 body (the issues travel in each error's
ctx), because FastAPI clients already read that shape. - Clients:
issuesFromProblemDetailsinvalidonce/server-errorsreads this shape;issuesFromResponsereads it and FastAPI's.
{
"type": "about:blank",
"title": "One or more validation errors occurred.",
"status": 422,
"validonce": [
{ "path": ["company"], "ruleId": "Signup.required_when.company", "key": "rules.company_required", "params": {} }
]
}
Conformance cases
conformance/rules/*.json files follow conformance/schema/case.schema.json (published as https://schemas.metatoy.com/validonce/conformance-case-v1.json, so another implementation can run the same cases):
{
"version": 1,
"suite": "required_when",
"cases": [
{ "id": "rw-001", "description": "...", "rules": [ ... ], "data": { ... }, "expect": [ ... ] }
]
}
expect is the server-side result: every rule evaluated. The client-side result is expect with the issues of server_only rules removed. Every runner checks both.
Using the validonce dialect
x-validonce is also declared as a JSON Schema 2020-12 vocabulary, so tools that understand vocabularies know what the keyword is:
- Vocabulary:
https://schemas.metatoy.com/validonce/vocab/rules-v1, one keyword,x-validonce, whose value must validate againstrules-v1.jsonand whose meaning is this document. - Dialect: https://schemas.metatoy.com/validonce/dialect-v1.json, the standard 2020-12 vocabularies plus this one, marked optional (
false). A validator that does not implement it still processes the schema and treatsx-validonceas an annotation. Validating a schema against the dialect checks the shape of its rules, in nested schemas too.
Using it is opt-in. In OpenAPI 3.1, point the document's jsonSchemaDialect at the dialect:
{
"openapi": "3.1.0",
"jsonSchemaDialect": "https://schemas.metatoy.com/validonce/dialect-v1.json",
"components": { "schemas": { "Signup": { "type": "object", "x-validonce": { "version": 1, "rules": [] } } } }
}
The exporters do not set it for you; the rules work the same with or without it.
Versioning
version is the format version. A change that could alter the result for any valid input is a new version. Adding a rule kind or condition is a new version too, because an old evaluator cannot run it; evaluators reject versions they do not know rather than skipping rules silently.