Swagger API Documentation Generator
This document provides guidelines for creating API documentation using PHPDoc comments. These comments help generate API documentation automatically. Below are the formats and examples for various types of API actions.
PHPDoc Comment Structure
Required Annotations
@title
: A brief title of the API action.@description
: A detailed description of the API action.@defaultMethod
: The HTTP method used (GET, POST, etc.).@route
: The endpoint route of the API action.@responseExample
: An example of the response returned by the API action.
Optional Annotations
@parametereter
: Parameters for the API action.@header
: Headers required for the API action.
Examples
Example 1: GET Request to Get All People
Example 2: POST Request for User Login
You can use optional parameters in the @parameter
or @header
annotations to indicate whether a parameter is required or optional. For example, @parameter string $cookies The cookies of the user (optional)
specifies that the cookies parameter is optional.
Additionally, you can set a default value for a parameter using the | default:value
syntax. For instance, @parameter string $source The source of the user | default:web
means that if the source parameter is not provided, it defaults to web.
Example 3: POST Request for User Login with Token
The @tags
annotation allows you to categorize your API actions for better organization and navigation in your documentation. For instance, using @tags
Auth, User will classify an action under both the Auth and User categories. This grouping makes it easier to locate and understand different API actions within the documentation.
How to Use
Define the PHPDoc comment: Before each API action method, define the PHPDoc comment block with appropriate annotations.
Add required and optional annotations: Make sure to include all required annotations (
@title
,@description
,@defaultMethod
,@route
and@responseExample
). Add optional annotations (@parameter
,@header
) where necessary.Create Documentation: Use your document generation tool to automatically generate API documentation from these comments. If set, this deployment is also automatic.
By following these instructions, you can ensure that your API documentation is generated without any problems.
Last updated