Docs/validationv1.0.0-rc.1

HTTP validation schemas

ValidationSchema is a public structural type used by validationMiddleware and controller route schemas. It is not JSON Schema or Zod; do not pass an unrelated schema object and assume it is enforced.

Supported fields include type, required, min, max, pattern, enum, items, properties and a synchronous custom predicate. Types include string, number, boolean, object, array, email, url and uuid.

Controller route schema

import 'reflect-metadata';
import assert from 'node:assert/strict';
import { Controller, Post, Body } from '@tagna/udiot';
import { toExpressRouter } from '@tagna/udiot/server';

@Controller('/contacts')
class ContactController {
  @Post({ path: '/', body: { email: { type: 'email', required: true } } })
  create(@Body() body: { email: string }) {
    return { email: body.email };
  }
}
const router = toExpressRouter(ContactController);
assert.equal(typeof router, 'function');

Mount the router in an Express application after express.json(). The server adapter returns validation failures through its Problem Details handling. Test missing bodies, invalid types, nested values and oversized input. The example checks route construction; it does not start an HTTP listener.

For pipeline integration, validationMiddleware({ body, query, params, headers }) expects a correctly initialized HttpContext. Missing context slots can be skipped by the standalone middleware: populate/guard required request data before invoking it. Do not infer data coercion or stripping beyond the options of the specific integration.

See server setup and error responses.

From the canonical UDIOT public documentation.Try it in the playground ↗