Skip to content

YAML & JSON Schemas

Describe your whole API in one declarative, versionable file: commit it, review it in PRs, regenerate at will.

YAML schema

Create api-schema.yaml at the project root:

yaml
options:
  query_builder: true
  pest: true

entities:
  Category:
    fields:
      name: string unique
    relations:
      posts: hasMany Post

  Post:
    soft_deletes: true
    fields:
      title: string
      content: text nullable
      status: enum(draft,published) default=draft
      views: { type: integer, default: 0 }
    relations:
      tags: belongsToMany Tag

  Tag:
    fields:
      name: string unique
bash
php artisan make:fullapi --schema=api-schema.yaml

When api-schema.yaml (or .yml / .json) exists at the project root, you can even drop the flag: a bare php artisan make:fullapi picks it up automatically.

Field syntax

Fields accept a shorthand (title: string) or a full mapping when you need extra keys like rules:

yaml
fields:
  title: string
  slug: string unique
  excerpt: text nullable
  code: string primary
  status: enum(draft,published) default=draft
  views: { type: integer, default: 0, rules: 'min:0' }

unique, nullable and default= decorate the shorthand, and primary promotes the field to custom primary key.

Options

Options can be global (under options:) or per entity:

OptionEffect
soft_deletes: trueSoftDeletes trait + restore/force-delete endpoints
query_builder: trueSpatie QueryBuilder filtering & sorting on index
pest: truePest tests instead of PHPUnit

What you get for free

  • Inverse relations synthesized: declare posts: hasMany Post on Category, and Post receives the belongsTo and its category_id migration column. Details.
  • Foreign-key-safe ordering: entities are generated parents-first so php artisan migrate never trips on a missing table.
  • Automatic pivots: every belongsToMany creates its pivot migration.

JSON bulk mode (class_data.json)

The original bulk format, still fully supported: create class_data.json at the project root and run php artisan make:fullapi with no arguments. See Relationships → JSON mode for the format, or download the sample Blog schema.

AI-friendly

A single YAML file describing a whole API is an ideal target for AI assistants: ask your favorite model for a schema, review it, generate. The assistant cannot hallucinate file paths, since the generator decides the layout.