Download the PHP package wwwision/types-openapi without Composer
On this page you can find all versions of the php package wwwision/types-openapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wwwision/types-openapi
More information about wwwision/types-openapi
Files in wwwision/types-openapi
Package types-openapi
Short Description Generator for OpenAPI schema files, see https://www.openapis.org/
License MIT
Informations about the package types-openapi
The easiest way to generate type-safe APIs with PHP...
...possibly... ;)
Integration for the wwwision/types package that allows for generation of OpenAPI schemas and APIs from PHP code
Usage
This package can be installed via composer:
Simple Example
This is all that is required to generate an OpenAPI schema for a simple HTTP endpoint:
Serve HTTP Requests
This package comes with a RequestHandler
that allows for serving HTTP requests using the generated OpenAPI schema.
The RequestHandler
is PSR-7 compatible such that it can easily be integrated with a corresponding psr/http-factory
/psr/http-message
provider, e.g. guzzlehttp/psr7
:
Parameters
Arguments of the endpoint methods are automatically mapped to OpenAPI parameters.
All OpenAPI parameter types are supported (query
, path
, header
, cookie
).
Query parameters
By default, the parameter type is query
:
will accept requests like
and
and will map the values to the corresponding method arguments.
Path parameters
Operations can also make use of Path Templating in order to map method arguments from the query path:
Path params cannot be optional and must be defined in the path template.
Header parameters
To define a header parameter, the #[Parameter]
attribute can be used:
Cookie parameters
Likewise, to define a cookie parameter, the #[Parameter]
attribute can be used:
Complex types
Complex parameter types are supported as well as long as they follow the wwwision/types best practices:
This will validate and map the parameter and fail if it does not satisfy the constraints:
Example
The following example makes use of all parameter types:
This will lead to an OpenAPI definition like this:
And an HTTP request like:
...will result in the following response:
Security
To implement custom authentication schemes, you can implement the AuthenticationContextProvider
interface and return an instance of your custom AuthenticationContext
class:
The AuthenticationContext
is passed to the endpoint method as an additional argument, if the security
option of the Operation
attribute is set.
The RequestHandler
will automatically call the getAuthenticationContext()
method of your provider and pass the result to the endpoint method.
Security schemes can be defined using the #[OpenApi]
attribute:
More Examples
More complex example
Contribution
Contributions in the form of issues or pull requests are highly appreciated
License
See LICENSE
All versions of types-openapi with dependencies
wwwision/types Version ^1.4
webmozart/assert Version ^1.11
wwwision/types-jsonschema Version ^2
psr/http-server-handler Version ^1
psr/http-server-middleware Version ^1
psr/http-factory Version ^1