Annotations reference
While Scramble automatically document everything it can, you can always override it or add more information (like descriptions or examples) using attributes and annotations.
Attributes
| ExcludeRouteFromDocs | ExcludeAllRoutesFromDocs | QueryParameter |
| HeaderParameter | CookieParameter | PathParameter |
| BodyParameter | Header | Response |
| SchemaName | Group |
ExcludeRouteFromDocs
Excludes a route from docs.
1use Dedoc\Scramble\Attributes\ExcludeRouteFromDocs;2
3class UserController extends Controller4{5 #[ExcludeRouteFromDocs]6 public function internalMethod()7 {8 // This route will not appear in the documentation9 }10}ExcludeAllRoutesFromDocs
Excludes all controller’s routes from docs.
1use Dedoc\Scramble\Attributes\ExcludeAllRoutesFromDocs;2
3#[ExcludeAllRoutesFromDocs]4class UserController extends Controller5{6 public function store()7 {8 // This route will not appear in the documentation9 }10
11 public function update()12 {13 // This route will not appear in the documentation14 }15}QueryParameter
Manually documents query parameters. Allows you to add descriptions, types, default values, and examples for query string parameters.
1use Dedoc\Scramble\Attributes\QueryParameter;2
3class TodoItemsController4{5 #[QueryParameter('per_page', description: 'Number of items per page.', type: 'int', default: 10, example: 20)]6 public function index()7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the parameter. |
$description | string | The description of the parameter. |
$required | bool | Whether the parameter is required. |
$deprecated | bool | Whether the parameter is deprecated. |
$type | string | The type of the parameter. |
$format | string | The format of the parameter (e.g., "uuid", "email"). |
$infer | bool | Whether to merge information inferred from validation rules. When set to false, type information from validation rules will be ignored. Default: true |
$default | mixed | The default value for the parameter. |
$example | mixed | A single example value for the parameter. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
HeaderParameter
Manually documents header parameters in requests. Allows you to add descriptions, types, default values, and examples for request headers.
1use Dedoc\Scramble\Attributes\HeaderParameter;2
3class ApiController extends Controller4{5 #[HeaderParameter('X-API-Key', description: 'API key for authentication.', type: 'string', required: true)]6 public function index()7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the parameter. |
$description | string | The description of the parameter. |
$required | bool | Whether the parameter is required. |
$deprecated | bool | Whether the parameter is deprecated. |
$type | string | The type of the parameter. |
$format | string | The format of the parameter (e.g., "uuid", "email"). |
$infer | bool | Whether to merge information inferred from validation rules. When set to false, type information from validation rules will be ignored. Default: true |
$default | mixed | The default value for the parameter. |
$example | mixed | A single example value for the parameter. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
CookieParameter
Manually documents cookie parameters. Allows you to add descriptions, types, default values, and examples for cookie parameters.
1use Dedoc\Scramble\Attributes\CookieParameter;2
3class ApiController extends Controller4{5 #[CookieParameter('session_id', description: 'Session identifier.', type: 'string')]6 public function index()7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the parameter. |
$description | string | The description of the parameter. |
$required | bool | Whether the parameter is required. |
$deprecated | bool | Whether the parameter is deprecated. |
$type | string | The type of the parameter. |
$format | string | The format of the parameter (e.g., "uuid", "email"). |
$infer | bool | Whether to merge information inferred from validation rules. When set to false, type information from validation rules will be ignored. Default: true |
$default | mixed | The default value for the parameter. |
$example | mixed | A single example value for the parameter. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
PathParameter
Manually documents path parameters. Allows you to add descriptions, types, formats, and examples for route path parameters.
1use Dedoc\Scramble\Attributes\PathParameter;2
3class TodoItemsController4{5 #[PathParameter('todoItem', description: 'Todo item being updated', type: 'string', format: 'uuid', example: '550e8400-e29b-41d4-a716-446655440000')]6 public function update(Request $request, TodoItem $todoItem)7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the parameter. |
$description | string | The description of the parameter. |
$required | bool | Whether the parameter is required. |
$deprecated | bool | Whether the parameter is deprecated. |
$type | string | The type of the parameter. |
$format | string | The format of the parameter (e.g., "uuid", "email"). |
$infer | bool | Whether to merge information inferred from validation rules. When set to false, type information from validation rules will be ignored. Default: true |
$default | mixed | The default value for the parameter. |
$example | mixed | A single example value for the parameter. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
BodyParameter
Manually documents request body parameters. Allows you to add descriptions, types, default values, and examples for request body fields.
1use Dedoc\Scramble\Attributes\BodyParameter;2
3class TodoItemsController4{5 #[BodyParameter('title', description: 'The title of the todo item.', type: 'string', required: true)]6 public function store(Request $request)7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the parameter. |
$description | string | The description of the parameter. |
$required | bool | Whether the parameter is required. |
$deprecated | bool | Whether the parameter is deprecated. |
$type | string | The type of the parameter. |
$format | string | The format of the parameter (e.g., "uuid", "email"). |
$infer | bool | Whether to merge information inferred from validation rules. When set to false, type information from validation rules will be ignored. Default: true |
$default | mixed | The default value for the parameter. |
$example | mixed | A single example value for the parameter. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
Header
Manually documents response headers. Allows you to add descriptions and types for headers that appear in responses.
1use Dedoc\Scramble\Attributes\Header;2
3class SampleController4{5 #[Header('X-RateLimit-Limit', 'The amount of requests allowed per minute', type: 'int')]6 public function __invoke(Request $request)7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the header. |
$description | string | The description of the header. |
$type | string | The type of the header's value. |
$format | string | The format of the header's value (e.g., "uuid", "email"). |
$required | bool | Whether the header is required (meaning that the header must be present in the response). |
$default | mixed | The default value for the header. |
$example | mixed | A single example value for the header. |
$examples | array<string, Example> | The key is a distinct name and the value is an example object. |
$deprecated | bool | Whether the header is deprecated. |
$explode | bool | Whether arrays and objects should generate separate parameters for each array item or object property. |
$status | int|string | The HTTP status code for the response this header applies to. Default: 200 |
Response
Manually documents responses. Allows you to add response descriptions, status codes, and types. Unless you specify status code and media type, the documentation will be attached to the response with status code 200 and media type application/json.
1use Dedoc\Scramble\Attributes\Response;2
3class SampleController4{5 #[Response('The sample created before')]6 public function __invoke(Request $request)7 {8 // ...9 }10}You can also specify status code and response type:
1use Dedoc\Scramble\Attributes\Response;2
3class SampleController4{5 #[Response(201, 'Created item ID', type: 'array{id: int}')]6 public function __invoke(Request $request)7 {8 // ...9 }10}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$status | int|string | The HTTP status code for the response. Default: 200 |
$description | string | The description of the response. |
$mediaType | string | The media type of the response. Default: 'application/json' |
$type | string | The type of the response body schema. |
$format | string | The format of the response body schema. |
$examples | mixed | Examples for the response. |
Example object
The Example object is used to provide detailed examples. It allows you to specify not just the value, but also a summary, description, and external value reference.
It is used for manual documentation of parameters and headers.
1use Dedoc\Scramble\Attributes\QueryParameter;2use Dedoc\Scramble\Attributes\Example;3
4class TodoItemsController5{6 #[QueryParameter(7 'status',8 description: 'Filter todos by status.',9 examples: [10 'active' => new Example('active', summary: 'Active todos', description: 'Returns only active todo items'),11 'completed' => new Example('completed', summary: 'Completed todos', description: 'Returns only completed todo items'),12 ]13 )]14 public function index()15 {16 // ...17 }18}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$value | mixed | The example value. |
$summary | string | A short summary describing the example. |
$description | string | A longer description of the example. |
$externalValue | string | A URL that points to the literal example. This provides the capability to reference examples that cannot easily be included in JSON or YAML documents. |
SchemaName
Explicitly names schemas for Eloquent models, JSON API resources, and enums. By default, Scramble uses the class name as the schema name. This is particularly useful when you have classes with the same names but in different namespaces.
1use Dedoc\Scramble\Attributes\SchemaName;2
3#[SchemaName('User')]4class UserResource extends JsonResource5{6 // ...7}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | Required The name of the schema. |
$input | string | Some classes can be used both as input and output schemas (like Laravel Data objects). This property is used to explicitly name the schema when it is in the input context. |
Group
Groups and sorts endpoints. By default, endpoints are grouped by controller name. You can use this attribute to name the endpoint group yourself and control the sorting order.
1use Dedoc\Scramble\Attributes\Group;2
3#[Group('Todo Items API')]4class TodoItemsController5{6 // ...7}You can also use the weight parameter to control the sorting order:
1use Dedoc\Scramble\Attributes\Group;2
3#[Group('Todo Items API', weight: 1)]4class TodoItemsController5{6 // ...7}8
9#[Group('Todos', weight: 0)]10class TodosController11{12 // ...13}Available constructor parameters
| Name | Type | Description |
|---|---|---|
$name | string | The name of the group. |
$description | string | The description of the group. |
$weight | int | Determines the ordering of the groups. Groups with the same weight are sorted by the name (with `SORT_LOCALE_STRING` sorting flag). |
Annotations
Annotations are PHPDoc annotations that should be added to whatever is stated in “Applies to” column.
| @deprecated | @notDeprecated | @var |
| @example | @format | @default |
| @query | @ignoreParam | @response |
| @status | @body | @operationId |
| @requestMediaType | @tags |
@deprecated
Applies to: Classes, methods, request fields, array items, properties in data objects
Marks a route as deprecated. When used on a class, all routes in the class will be marked as deprecated.
1class OldController extends Controller2{3 /**4 * @deprecated5 */6 public function store(Request $request)7 {8 // This route will be marked as deprecated9 }10}You can also mark any object’s schema property as deprecated:
1use Illuminate\Http\Resources\Json\JsonResource;2
3class UserResource extends JsonResource4{5 public function toArray($request)6 {7 return [8 /** @deprecated */9 'name' => $this->name,10 ];11 }12}If needed, you can add an additional message for deprecation by providing a string after the @deprecated annotation. This message will be added to the operation (or schema, if the annotation is used on a field) description:
1class UsersController extends Controller2{3 /**4 * @deprecated Deprecated since version 1.0.0.5 */6 public function store(Request $request) {}7}@notDeprecated
Applies to: Methods
Old alias: @not-deprecated
Marks a route of a deprecated controller as not deprecated.
1/**2 * @deprecated3 */4class OldController extends Controller5{6 /**7 * @notDeprecated8 */9 public function stillActiveMethod()10 {11 // This route will not be marked as deprecated even though the controller is12 }13}@var
Applies to: request fields, array items, properties in data objects
Re-defines a type of schema.
1use Illuminate\Http\Resources\Json\JsonResource;2
3class UserResource extends JsonResource4{5 public function toArray($request)6 {7 return [8 /** @var string[] */9 'tags' => $this->tags,10 ];11 }12}Or when used in data objects:
1use Spatie\LaravelData\Data;2
3class UserData extends Data4{5 public function __construct(6 /**7 * @var string[] $tags8 */9 public array $tags,10 ) {}11}@example
Applies to: request fields, array items, properties in data objects
Allows adding examples to schema.
1use Illuminate\Http\Resources\Json\JsonResource;2
3class UserResource extends JsonResource4{5 public function toArray($request)6 {7 return [8 /**9 * @example "user@bestapi.dev"10 */11 'email' => $this->email,12 ];13 }14}Or when used in data objects:
1use Spatie\LaravelData\Data;2
3class UserData extends Data4{5 public function __construct(6 /**7 * @example "user@bestapi.dev"8 */9 public string $email,10 ) {}11}@format
Applies to: request fields, array items, properties in data objects
Specifies the format for the schema.
1use Illuminate\Http\Resources\Json\JsonResource;2
3class UserResource extends JsonResource4{5 public function toArray($request)6 {7 return [8 /** @format email */9 'email' => $this->email,10 ];11 }12}Or when used in data objects:
1use Spatie\LaravelData\Data;2
3class UserData extends Data4{5 public function __construct(6 /**7 * @format email8 */9 public string $email,10 ) {}11}@default
Applies to: request fields, array items, properties in data objects
Specifies the default value for the schema.
1use Illuminate\Http\Resources\Json\JsonResource;2
3class UserResource extends JsonResource4{5 public function toArray($request)6 {7 return [8 /** @default "active" */9 'status' => $this->status,10 ];11 }12}Or when used in data objects:
1use Spatie\LaravelData\Data;2
3class UserData extends Data4{5 public function __construct(6 /**7 * @default "active"8 */9 public string $status,10 ) {}11}@query
Applies to: request fields
Marks a parameter as part of the query string for non-GET requests.
1public function store(Request $request)2{3 $request->validate([4 /** @query */5 'per_page' => ['integer'],6 ]);7 // ...8}@ignoreParam
Applies to: request fields
Excludes a parameter from being documented in the API documentation.
1public function store(Request $request)2{3 $request->validate([4 /** @ignoreParam */5 'foo' => ['string'],6 ]);7}@response
Applies to: Methods
Documents arbitrary response types. This annotation has the highest priority when determining the response type.
1use App\Models\TodoItem;2use App\Http\Resources\TodoItemResource;3
4class TodoItemsController5{6 /**7 * @response TodoItemResource8 */9 public function update(Request $request, TodoItem $item)10 {11 return new TodoItemResource($item);12 }13}@status
Applies to: Return statements of route actions (closures, controllers’ methods)
Specifies the response status code. Used together with @body to document responses manually.
1public function create(Request $request)2{3 /**4 * A user resource.5 *6 * @status 2017 * @body User8 */9 return User::create($request->only(['email']));10}@body
Applies to: Return statements of route actions (closures, controllers’ methods)
Specifies the response body type. Used together with @status to document responses manually.
1public function create(Request $request)2{3 /**4 * A user resource.5 *6 * @status 2017 * @body User8 */9 return User::create($request->only(['email']));10}@operationId
Applies to: Methods
Overrides the automatically generated operation ID for an endpoint.
1class DownloadMediaController2{3 /**4 * @operationId getMediaItem5 */6 public function show(Media $mediaItem)7 {8 return $mediaItem;9 }10}@requestMediaType
Applies to: Methods
Overrides the request media type (Content-Type header). By default, Scramble uses application/json, or multipart/form-data when file uploads are detected.
1class UploadMediaController2{3 /**4 * @requestMediaType multipart/form-data5 */6 public function store(Request $request)7 {8 // ...9 }10}@tags
Applies to: Classes
Adds multiple tags to controller’s endpoints in the OpenAPI specification. Provide a comma-separated list of tags.
1/**2 * @tags Todos, Items, API3 */4class TodoItemsController5{6 // All endpoints in this controller will have these tags7}