To avoid polluting PHP files with maybe thousands of lines of OpenAPI attributes, we opted for storing them in separate files, called
OpenAPI.php, one for each module.
We already covered all the endpoints available in Dotkernel API, you can consult the existing documentation in each module's own OpenAPI.php file.
After you add more functionalities to your API, you will have to document the new endpoints.
This is easier than it sounds because in most cases you will do the same: add a request by method, describe the request payload (if any), add request parameters (if any) and describe the possible responses.
To do this, you will use the following request objects:
OA\Delete: delete an API resource identified by its unique idOA\Get: fetch API single or collections of API resourcesOA\Post: create a new API resource (unless if it already exists)OA\Patch: update an existing API resourceOA\Put: create a new API resource (if it already exists, it is overwritten)
Also, the following components describe PHP objects:
OA\Schema: describe an object sent in a request or received as a response - read moreOA\Parameter: describe aquery/pathparameter - read moreOA\RequestBody: describe the body of a request - read more
There are a lot more, but these are the most often used ones.
If you need help, take a look at the existing definitions found in Dotkernel API.
Defines a DELETE HTTP request. It should specify at least the following parameters:
path: the route to the resource (example:/resource/{id}- whereidis a path parameter defined below)description: verbose description of the endpoint's purposesummary: short description of the endpoint's purposesecurity: an array of security scheme(s) to be used—omit if the endpoint is not protectedtags: an array of tags to help group related requests (example: user-related requests could have aUsertag)parameters: an array ofquery/pathparameters - each parameter is specified as a newOA\Parameterobjectresponses: an array ofOA\Responseobjects, each describing a combination of HTTP status codes and their respective response bodies
Defines a GET HTTP request. It should specify at least the following parameters:
path: the route to a single or collection of resources (example:/resource/{id}for a single resource or/resourcefor a collection of resources)description: verbose description of the endpoint's purposesummary: short description of the endpoint's purposesecurity: an array of security scheme(s) to be used—omit if the endpoint is not protectedtags: an array of tags to help group related requests (example: user-related requests could have aUsertag)parameters: an array ofquery/pathparameters - each parameter is specified as a newOA\Parameterobjectresponses: an array ofOA\Responseobjects, each describing a combination of HTTP status codes and their respective response bodies
Defines a PATCH HTTP request. It should specify at least the following parameters:
path: the route to the resource (example:/resource/{id}- whereidis a path parameter defined below)description: verbose description of the endpoint's purposesummary: short description of the endpoint's purposesecurity: an array of security scheme(s) to be used—omit if the endpoint is not protectedrequestBody: aOA\RequestBodyobject describing the data being sent in the requesttags: an array of tags to help group related requests (example: user-related requests could have aUsertag)parameters: an array ofquery/pathparameters - each parameter is specified as a newOA\Parameterobjectresponses: an array ofOA\Responseobjects, each describing a combination of HTTP status codes and their respective response bodies
Defines a POST HTTP request. It should specify at least the following parameters:
path: the route to the resource (example:/resource/{id}- whereidis a path parameter defined below)description: verbose description of the endpoint's purposesummary: short description of the endpoint's purposesecurity: an array of security scheme(s) to be used—omit if the endpoint is not protectedrequestBody: aOA\RequestBodyobject describing the data being sent in the requesttags: an array of tags to help group related requests (example: user-related requests could have aUsertag)parameters: an array ofquery/pathparameters - each parameter is specified as a newOA\Parameterobjectresponses: an array ofOA\Responseobjects, each describing a combination of HTTP status codes and their respective response bodies
Defines a PUT HTTP request. It should specify at least the following parameters:
path: the route to the resource (example:/resource/{id}- whereidis a path parameter defined below)description: verbose description of the endpoint's purposesummary: short description of the endpoint's purposesecurity: an array of security scheme(s) to be used—omit if the endpoint is not protectedrequestBody: aOA\RequestBodyobject describing the data being sent in the requesttags: an array of tags to help group related requests (example: user-related requests could have aUsertag)parameters: an array ofquery/pathparameters - each parameter is specified as a newOA\Parameterobjectresponses: an array ofOA\Responseobjects, each describing a combination of HTTP status codes and their respective response bodies
To summarize, the typical scenario on working on your own instance of Dotkernel API would follow these steps:
- create new module (example:
Book) - add functionality to your new module (routes, entities, repositories, handlers, services, tests etc)
- create file
OpenAPI.phpin the new module and describe each new endpoint - generate the latest version of a documentation file as described in this tutorial