In order 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 describing PHP objects:
OA\Schema
: describe an object sent in a request or received as a response -
read moreOA\Parameter
: describe a query
/path
parameter -
read moreOA\RequestBody
: describe the body of a request -
read moreThere are 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/{uuid}
- where uuid
is 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 grouping related requests (example: user-related requests could have a User
tag)parameters
: an array of query
/path
parameters - each parameter is specified as a new OA\Parameter
objectresponses
: an array of OA\Response
objects, each describing a combination of HTTP status codes and their
respective response bodiesDefines a GET
HTTP request. It should specify at least the following parameters:
path
: the route to a single or collection of resources (example: /resource/{uuid}
for a single resource or
/resource
for 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 grouping related requests (example: user-related requests could have a User
tag)parameters
: an array of query
/path
parameters - each parameter is specified as a new OA\Parameter
objectresponses
: an array of OA\Response
objects, each describing a combination of HTTP status codes and their
respective response bodiesDefines a PATCH
HTTP request. It should specify at least the following parameters:
path
: the route to the resource (example: /resource/{uuid}
- where uuid
is 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
: a OA\RequestBody
object describing the data being sent in the requesttags
: an array of tags to help grouping related requests (example: user-related requests could have a User
tag)parameters
: an array of query
/path
parameters - each parameter is specified as a new OA\Parameter
objectresponses
: an array of OA\Response
objects, each describing a combination of HTTP status codes and their
respective response bodiesDefines a POST
HTTP request. It should specify at least the following parameters:
path
: the route to the resource (example: /resource/{uuid}
- where uuid
is 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
: a OA\RequestBody
object describing the data being sent in the requesttags
: an array of tags to help grouping related requests (example: user-related requests could have a User
tag)parameters
: an array of query
/path
parameters - each parameter is specified as a new OA\Parameter
objectresponses
: an array of OA\Response
objects, each describing a combination of HTTP status codes and their
respective response bodiesDefines a PUT
HTTP request. It should specify at least the following parameters:
path
: the route to the resource (example: /resource/{uuid}
- where uuid
is 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
: a OA\RequestBody
object describing the data being sent in the requesttags
: an array of tags to help grouping related requests (example: user-related requests could have a User
tag)parameters
: an array of query
/path
parameters - each parameter is specified as a new OA\Parameter
objectresponses
: an array of OA\Response
objects, each describing a combination of HTTP status codes and their
respective response bodiesTo summarize, the typical scenario on working on your own instance of Dotkernel API would follow these steps:
Book
)OpenAPI.php
in the new module and describe each new endpoint