Core concepts

Requests

By default, PHP autodoc does not understand request body type as it can be specified in many different ways depending on the application/framework.

For Laravel projects, PHP autodoc-laravel supports inferring request body types using using Laravel request validation rules, Laravel FormRequest classes and URL parameters.

For other frameworks, it’s recommended to use custom PHP autodoc extensions to define the logic for detecting request body types specific to your application. Alternatively, you can use the following annotations to manually describe request data:

  • @request / @request-body   –   Describe the request body type for a route
  • @request-cookie   –   Describe a cookie
  • @request-header   –   Describe a header
  • @request-query   –   Describe a query parameter
  • @request-url-param   –   Describe a URL parameter

PHPDoc request annotation example

/**
 * @request-query filter {type: string[]}
 * 
 * @request-header Authorization {
 *     required: true,
 *     description: 'Authorization header'
 * }
 * 
 * @request-header X-HEADER-1
 * @request-header X-NUMERIC-HEADER {type: numeric-string}
 *
 *
 * @request-cookie COOKIE-NAME {
 *     description: 'Description of the cookie',
 *     deprecated: true
 * }
 *
 * @request-body object{
 *     data: array<array{
 *         id: int,
 *         name: string,
 *     }>
 * }
 */

PHPDoc request annotation details

  • @request / @request-body
    You can specify only the type, similar to how you'd use a @return.
    Example: @request-body SomeRequestClass
  • @request-cookie / @request-header / @request-query / @request-url-param
    These annotations require a parameter name and may include optional options within curly braces:

{

  • required: true/false,   –   (bool) Whether the parameter is required (default: false)
  • description: 'Text',   –   (string) Description of the parameter
  • type: int|string|SomeClass|...,   –   (type) Type of the parameter (default: string)
  • deprecated: true/false,   –   (bool) Whether the parameter is deprecated (default: false)
}