Skip to main content
Version: Next (unreleased)

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.

RoleWhat it isIts duties
ExporterTurns rules written in a server's validation library into x-validonce dataMUST 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
EvaluatorParses rule data and runs it against an objectMUST 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/
HostThe 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​

FieldRequiredMeaning
idyesLetters, 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
kindyesOne of the five kinds below
pathnoThe field the error is reported on. Defaults per kind (below)
messageyes{ "key": string, "params"?: object }. Params values are strings, numbers, booleans or null
server_onlynotrue 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​

KindFieldsFails whenDefault path
required_whenfield, when (condition)when is true and field is blankfield
compareleft ({ "field" }), op, right ({ "field" } or { "value" }), typeboth sides pass the type check and the comparison is falseleft.field
at_least_one_offields (2 or more)every listed field is blankfirst of fields
exactly_one_offields (2 or more)the number of non-blank fields is not exactly onefirst of fields
all_or_nonefields (2 or more)some, but not all, listed fields are blankfirst 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.

ConditionShapeTrue 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.json rejects is invalid. That covers a missing or unknown version, a missing rules array, an unknown kind, op, type or condition, and a missing required field.
  • Objects are closed. The rule set, each rule, message, left, right and every condition body allow only the keys this document lists. An unknown key (including x- annotations) is an error, not ignored. Descriptions belong on the schema, not inside a rule.
  • Ids. id matches ^[A-Za-z0-9_.:-]+$, and no two rules in a rule set share an id. Issues carry ruleId, so duplicates would make them ambiguous.
  • Non-empty names. message.key, path and every field name are non-empty strings. server_only is a boolean. message.params values are strings, numbers, booleans or null.
  • Groups. fields lists 2 or more distinct names.
  • Conditions. right and each condition have exactly one key. in has a non-empty values list; all and any have a non-empty list. Condition values are strings, numbers or booleans, never null.
  • Constants fit their type. A compare constant passes the type check of its type (dates in years 0001 to 9999, real days only, so 2026-02-30 is 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.

  1. 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).
  2. Blank means: the key is missing, the value is null, the value is "", or the value is []. Nothing else is blank: " ", 0, false and {} are not blank.
  3. No type coercion. "1" is not 1. "true" is not true. A boolean is never a number (Python's bool is a subclass of int; implementations must check for it).
  4. Strict equality (eq, ne, in, and compare with eq/ne): same JSON type and same value. Numbers compare numerically (1 equals 1.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, so eq on it is false.
  5. Numbers are compared as IEEE 754 double-precision values. -0 equals 0. Integers beyond 2^53 lose precision (9007199254740993 equals 9007199254740992), the same as in a JavaScript client, so values that need exact large integers (ids, money in minor units) SHOULD be sent as strings.
  6. Strings in compare with lt/le/gt/ge are 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.)
  7. date is a string YYYY-MM-DD naming 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. Year 0000 is outside this range even though ISO 8601 and some libraries allow it (Zod's z.iso.date() accepts 0000-01-01), so a compare of type date passes when either side is 0000-01-01. In Zod, isoDate() and isoDateTime() from validonce/zod match this range.
  8. datetime is a string YYYY-MM-DDTHH:MM:SS[.fraction](Z|±HH:MM), with an uppercase T and Z, 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:00 is accepted and means UTC, like Z. A leap second (:60) fails the type check, although JSON Schema's format: date-time allows it. Values compare as instants in time, at millisecond precision: fraction digits after the third are ignored.
  9. Order and count of issues. Rules are evaluated in array order. Each failing rule yields exactly one issue. Issues are returned in rule order.
  10. 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's path (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 ~0 and / as ~1: ["items", "3", "end"] is /items/3/end.
  • params: exactly the rule's message.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 named validonce, 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: issuesFromProblemDetails in validonce/server-errors reads this shape; issuesFromResponse reads 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 against rules-v1.json and 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 treats x-validonce as an annotation. Validating a schema against either dialect checks the shape of its rules, in nested schemas too.
DialectBuilds onUse it for
https://schemas.metatoy.com/validonce/dialect-oas31-v1.jsonOpenAPI 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.jsonplain JSON Schema 2020-12standalone 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​

DateChange
2026-11-28Stable. 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-22Version 1 released with validonce 0.1.0