v1.0.0
Quickstart GitHub

Schema & Validation Reference

AtoZAPI uses a unified, declarative schema syntax that powers both runtime input validation (returning FastAPI-standard HTTP 422 errors) and automatic OpenAPI 3.0 / Swagger UI documentation generation.

---

Supported Data Types

AtoZAPI schemas support the following core primitive and composite data types:

TypeOpenAPI 3.0 MappingDescription
string{ "type": "string" }Text values, UTF-8 strings, emails, UUIDs
number{ "type": "number" }Floating-point decimal numbers
integer / int{ "type": "integer" }Whole numbers
boolean / bool{ "type": "boolean" }true or false boolean values
array / list{ "type": "array" }Lists/arrays of items (defined via items)
object{ "type": "object" }Nested JSON objects (defined via properties)

---

Validation Constraints & Rules

Attach these properties to any field definition in your schema:

RuleTypeApplicable TypesDescriptionExample
requiredbooleanAllWhether the field is mandatory (default: true)required: true
optionalbooleanAllInverse of required; skips validation if omittedoptional: true
minLengthnumberstringMinimum character lengthminLength: 3
maxLengthnumberstringMaximum character lengthmaxLength: 100
minnumbernumber, integerMinimum numeric value (inclusive)min: 0
maxnumbernumber, integerMaximum numeric value (inclusive)max: 120
patternstring \RegExpstringRegex expression the value must matchpattern: '^[A-Z0-9]+$'
formatstringstringSemantic format (e.g., email, uuid, uri, date-time)format: 'email'
itemsobjectarraySchema definition for array elementsitems: { type: 'string' }
propertiesobjectobjectSub-schema properties for nested objectsproperties: { city: { type: 'string' } }
descriptionstringAllHuman-readable documentation for Swagger UIdescription: 'Primary email'
defaultanyAllDefault fallback value if not provideddefault: 'active'

---

Multi-Framework Syntax Comparison

AtoZAPI allows you to write schemas in the native idiomatic style of your backend language:

1. JavaScript & TypeScript (Express & Next.js)

javascript
const userRegistrationSchema = {
  name: {
    type: 'string',
    required: true,
    minLength: 2,
    maxLength: 50,
    description: 'User full name'
  },
  email: {
    type: 'string',
    required: true,
    format: 'email',
    description: 'Valid contact email'
  },
  age: {
    type: 'number',
    required: true,
    min: 18,
    max: 120,
    description: 'Age in years'
  },
  role: {
    type: 'string',
    optional: true,
    default: 'member',
    description: 'Access role'
  },
  tags: {
    type: 'array',
    optional: true,
    items: { type: 'string' },
    description: 'Profile tags'
  },
  address: {
    type: 'object',
    optional: true,
    properties: {
      street: { type: 'string', required: true },
      city: { type: 'string', required: true },
      zipCode: { type: 'string', required: true, pattern: '^[0-9]{5}$' }
    }
  }
};

2. Go (Gin) Struct Tags

In Go, use standard struct tags with json and binding directives:

go
type UserRegistrationRequest struct {
    Name    string   `json:"name" binding:"required,min=2,max=50"`
    Email   string   `json:"email" binding:"required,email"`
    Age     int      `json:"age" binding:"required,gte=18,lte=120"`
    Role    string   `json:"role" binding:"omitempty"`
    Tags    []string `json:"tags" binding:"omitempty"`
}

Supported Go binding rules: - required / omitempty - min=N / max=N (for strings, slices, or numbers) - gte=N / lte=N / gt=N / lt=N - email

3. PHP (Laravel) Controller Attributes

In Laravel, pass standard Laravel validation rule strings into the #[Post] attribute:

php
#[Post(
    path: '/api/users',
    summary: 'Register new user',
    rules: [
        'name'  => 'required|string|min:2|max:50',
        'email' => 'required|email',
        'age'   => 'required|integer|min:18|max:120',
        'role'  => 'string',
        'tags'  => 'array',
    ]
)]
public function store(Request $request): JsonResponse
{
    // ...
}

---

Standardized HTTP 422 Error Format

When a field fails validation against the schema, AtoZAPI halts execution and returns a standardized error matching FastAPI's Pydantic model:

json
{
  "detail": [
    {
      "loc": ["body", "age"],
      "msg": "Input should be greater than or equal to 18",
      "type": "greater_than_equal",
      "ctx": { "ge": 18 }
    },
    {
      "loc": ["body", "email"],
      "msg": "Input should be a valid email address",
      "type": "value_error.email"
    }
  ]
}

Each item in detail includes: - loc: Array describing the path to the invalid field (e.g., ["body", "field_name"]). - msg: Clear, user-friendly validation error message. - type: Machine-readable error code (e.g. missing, greater_than_equal, string_too_short, value_error.email). - ctx: Optional context parameters (such as minimum limit ge or character count min_length).

Type to search documentation...