validonce rule format, version 1
Status: stable. Version 1 has shipped in every validonce release since 0.1.0 (2026-11-22). Changes to this file change the contract every implementation is tested against, so each change also updates conformance/. See "Change log" and "Errata" at the end.
Purpose
A server writes its cross-field validation rules once, in its own stack: FluentValidation with ASP.NET Core (C#), Pydantic with FastAPI (Python), Fastify or NestJS (TypeScript), Huma or go-playground/validator (Go), or Bean Validation with Spring Boot (Java, Kotlin). Kubernetes custom resources can supply them too, translated from CEL. validonce exports those rules as data in this format. Every evaluator (C#, TypeScript, Python, Go, Java) 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.
Conformance language and roles
The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are used as described in RFC 2119 and RFC 8174, when they appear in capitals.
| Role | What it is | Its duties |
|---|---|---|
| Exporter | Turns rules written in a server's validation library into x-validonce data | MUST write only valid rule sets (see "Invalid rule sets"). MUST derive a unique id when the author gives none, and fail on a collision. MUST reject a compare whose type does not match the JSON Schema type of its fields. MUST use wire names |
| Evaluator | Parses rule data and runs it against an object | MUST reject an invalid rule set as a whole, and a version it does not know. MUST follow "Pinned behavior" exactly. MUST return issues in the shape and order of "Issues". MUST pass every case in conformance/ |
| Host | The server or client code around an evaluator (a framework integration, a form library adapter) | A server MUST evaluate every rule, server_only ones included. A client MUST skip server_only rules. A host MUST prefix issue paths for nested objects. A server SHOULD report issues as described in "Transport" |
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 | Letters, digits and _ . : - only (^[A-Za-z0-9_.:-]+$), unique within the rule set. 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. A constant (right.value) must itself pass the type check of type: a number for number, a string for string, a real calendar date for date, a datetime with an offset for datetime. Otherwise the rule could never fail, so the rule set is invalid (see "Invalid rule sets"). 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.
Invalid rule sets
A parser MUST reject a rule set, as a format error, when any of these hold. It never skips a bad rule and keeps the rest.
- The schema rejects it. Anything
rules-v1.jsonrejects is invalid. That covers a missing or unknownversion, a missingrulesarray, an unknownkind,op,typeor condition, and a missing required field. - Objects are closed. The rule set, each rule,
message,left,rightand every condition body allow only the keys this document lists. An unknown key (includingx-annotations) is an error, not ignored. Descriptions belong on the schema, not inside a rule. - Ids.
idmatches^[A-Za-z0-9_.:-]+$, and no two rules in a rule set share an id. Issues carryruleId, so duplicates would make them ambiguous. - Non-empty names.
message.key,pathand every field name are non-empty strings.server_onlyis a boolean.message.paramsvalues are strings, numbers, booleans or null. - Groups.
fieldslists 2 or more distinct names. - Conditions.
rightand each condition have exactly one key.inhas a non-emptyvalueslist;allandanyhave a non-empty list. Condition values are strings, numbers or booleans, never null. - Constants fit their type. A
compareconstant passes the type check of itstype(dates in years 0001 to 9999, real days only, so2026-02-30is invalid).
JSON Schema can't express two of these: duplicate ids, and a date pattern that names no real day. Those are checked by parsers only.
conformance/invalid/*.json lists rule sets that every parser must reject, each with its reason. The files follow conformance/schema/invalid-case.schema.json (published as https://schemas.metatoy.com/validonce/invalid-case-v1.json). A case marked "schemaRejects": false passes rules-v1.json and is rejected by parsers only.
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.
-0equals0. Integers beyond 2^53 lose precision (9007199254740993equals9007199254740992), the same as in a JavaScript client, so values that need exact large integers (ids, money in minor units) SHOULD be sent as strings. - 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 to 9999, in ASCII digits, with nothing before or after it (not even a trailing newline). 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-01-01. 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 in years 0001 to 9999, hours 00 to 23, minutes and seconds 00 to 59, and an offset whose hours are 00 to 23 and minutes 00 to 59, in ASCII digits with nothing after it. A value with no offset fails the type check. The offset-00:00is accepted and means UTC, likeZ. A leap second (:60) fails the type check, although JSON Schema'sformat: date-timeallows it. 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. Evaluators may assume the rule data has already been parsed as described in "Invalid rule sets".
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. Each element is one step into the JSON body, so a path maps to a JSON Pointer (RFC 6901) by joining the elements with/, after escaping~as~0and/as~1:["items", "3", "end"]is/items/3/end.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.
Rule sets that must fail to parse are in conformance/invalid/ (see "Invalid rule sets"). Every runner checks that its parser rejects each one, and asserts the case count.
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. - Vocabulary meta-schema: https://schemas.metatoy.com/validonce/meta/rules-v1.json, the vocabulary on its own, in the usual 2020-12 layout. Both dialects include it.
- Two dialects, each marking the vocabulary optional (
false), so a validator that does not implement it still processes the schema and treatsx-validonceas an annotation. Validating a schema against either dialect checks the shape of its rules, in nested schemas too.
| Dialect | Builds on | Use it for |
|---|---|---|
| https://schemas.metatoy.com/validonce/dialect-oas31-v1.json | OpenAPI 3.1's default dialect, https://spec.openapis.org/oas/3.1/dialect/base (2020-12 plus discriminator, xml, externalDocs, example) | OpenAPI 3.1 documents |
| https://schemas.metatoy.com/validonce/dialect-v1.json | plain JSON Schema 2020-12 | standalone JSON Schema |
Using it is opt-in. In OpenAPI 3.1, point the document's jsonSchemaDialect at the OpenAPI dialect. dialect-v1.json would replace OpenAPI's default dialect, so strict tools would stop recognizing discriminator and the other OpenAPI keywords:
{
"openapi": "3.1.0",
"jsonSchemaDialect": "https://schemas.metatoy.com/validonce/dialect-oas31-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.
Errata
Version 1 is stable. Its published schemas (rules-v1.json and the files beside it on schemas.metatoy.com) change only to fix a bug, or to tighten them towards what this document already says. A valid rule never changes its result. Each such change is listed below, with a conformance case, and a rule set that newly fails to load is always one that could not have worked as written.
Change log
| Date | Change |
|---|---|
| 2026-11-28 | Stable. Conformance language and the three roles. "Invalid rule sets": closed objects, unique ids, non-empty names, and compare constants that must fit their type (rules-v1.json checks the constants too; 43 cases in conformance/invalid/). Pinned: -0 equals 0, integers beyond 2^53, the -00:00 offset, leap seconds, ASCII digits only. Issue paths as JSON Pointers. OpenAPI 3.1 dialect (dialect-oas31-v1.json) and the vocabulary meta-schema (meta/rules-v1.json) |
| 2026-11-24 | "Transport" (problem details with a validonce member). Canonical schema URLs on schemas.metatoy.com, the vocabulary and dialect-v1.json (validonce 0.3.3 and 0.4.0) |
| 2026-11-22 | Version 1 released with validonce 0.1.0 |