Skip to content

Reference

accord:generate

Terminal window
php artisan accord:generate [options]

Options

OptionDefaultDescription
--versionv1URI version filter — only include routes matching /v{N}/
--titleAPISets info.title in the generated spec
--outputresources/openapi/{version}.yamlOutput file path
--forceOverwrite an existing file without prompting

Examples

Terminal window
# Generate spec for v1 routes (default)
php artisan accord:generate
# Generate spec for v2 routes
php artisan accord:generate --version=v2
# Custom title and output path
php artisan accord:generate --title="Acme API" --output=docs/openapi.yaml
# Overwrite existing spec
php artisan accord:generate --force

Schema inference

forge reads your FormRequest rules() method and maps Laravel validation rules to JSON Schema properties.

Validation ruleJSON Schema effect
integer, int, numerictype: integer
boolean, booltype: boolean
arraytype: array
string (default)type: string
emailformat: email
urlformat: uri
dateformat: date
uuidformat: uuid
nullablenullable: true
min:NminLength / minimum (type-dependent)
max:NmaxLength / maximum (type-dependent)
in:a,b,cenum: [a, b, c]
requiredField added to required array

Fields not matched by any type rule default to type: string.


Example output

Given a route POST /v1/users with a StoreUserRequest containing:

public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email'],
'age' => ['nullable', 'integer', 'min:0'],
];
}

forge generates:

openapi: 3.0.3
info:
title: API
version: 1.0.0
paths:
/v1/users:
post:
summary: Store User
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- name
- email
properties:
name:
type: string
maxLength: 255
email:
type: string
format: email
age:
type: integer
minimum: 0
nullable: true
responses:
'200':
description: OK

Response schemas are scaffolded as stubs. Fill them in manually after generation.


FormRequest inspector

forge discovers FormRequest classes by inspecting the route’s controller method signature. It resolves the FormRequest class and calls rules() to extract validation rules.

Routes without a FormRequest (or using Request directly) will have no request body schema in the generated spec — they are included in the spec with an empty request body.