Skip to content

VineJS

The AdonisJS target writes its own VineJS validators from your contract when you link none. AdonisJS validates with VineJS already, and the server names each issue by the contract rule.

Used by: AdonisJS only, when its entry has no validators link.

Nothing to add: the AdonisJS starter depends on @vinejs/vine, and the @seampact/codegen-adonis target writes the validators in its own validators/ folder. There is no separate validators target.

To use zod or yup instead, add a validators entry and link it (Switch the validator).

The files have the same layout as the zod ones: schemas/input.ts, schemas/output.ts, operations/input.ts and wire-checks.ts, plus a vine-support.ts.

A generated schema is not a chain of vine.object() calls. It is a plan: a plain object that lists each field, its type and its checks (a rule name, its limit and its message). vine-support.ts reads the plan and builds the VineJS validator. So you read the contract to know what is checked, and you do not edit the plan.

For CreateTask, the plan says:

  • title is a required string with a minimum length of 1 and a maximum length of 200.
  • effort is an optional integer with a minimum of 0.
  • Any other key is refused.

An operation validator checks path, query, headers and body together.

Each VineJS error becomes one issue of the 400 body, named by the contract rule.

@seampact/codegen-adonis takes the rules option (native by default). With native, the validators use VineJS’s own rules, which differ from the contract in a few places.

  • Lengths count UTF-16 units: an emoji counts 2, so maxLength: 1 refuses “😀”.
  • uuid also checks the version and variant digits. 00000000-0000-9000-8000-000000000000 is refused.
  • date-time, exclusiveMinimum, exclusiveMaximum and multipleOf have no VineJS rule: they stay the contract’s checks.
  • Under the native rules, an issue’s message may be VineJS’s own text; the rule name is the same in both modes.

Set rules: seampact-consistent on the server entry for the contract’s exact checks (AdonisJS options).

The generator refuses by name a oneOf, a property default, a nullable value other than an opaque one and the other forms in Generate fails.