Download the PHP package tobion/openapi-symfony-routing without Composer
On this page you can find all versions of the php package tobion/openapi-symfony-routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobion/openapi-symfony-routing
More information about tobion/openapi-symfony-routing
Files in tobion/openapi-symfony-routing
Package openapi-symfony-routing
Short Description Loads routes in Symfony based on OpenAPI/Swagger annotations
License MIT
Homepage https://github.com/Tobion/OpenAPI-Symfony-Routing
Informations about the package openapi-symfony-routing
OpenAPI-Symfony-Routing
Loads routes in Symfony based on OpenAPI/Swagger annotations.
Installation
$ composer require tobion/openapi-symfony-routing
Version >= 1.2 requires zircote/swagger-php 3.x which is compatible with the OpenAPI Specification version 3. Version < 1.2 requires zircote/swagger-php 2.x which works with the OpenAPI Specification version 2 (fka Swagger). So tobion/openapi-symfony-routing can be used with both OpenAPI v2 and v3 and composer will select the compatible one for your dependencies. Route loading stays the same between those versions. You just need to update the annotations when migrating from OpenAPI v2 to v3.
Basic Usage
This library allows to (re-)use your OpenAPI documentation to configure the routing of your Symfony-based API. All the relevant routing information like the HTTP method, path and parameters are already part of the OpenAPI spec. This way you do not have to duplicate any routing information in Symfony. Consider having the controllers annotated with zircote/swagger-php like the following example:
This library provides an OpenApiRouteLoader
that you need to define as service and configure where to look for annotations like so:
Then you need to tell Symfony to load routes using it:
Advanced Features
Scanning annotations in different directories
Naming routes
By default routes are auto-named based on the controller class and method. If you want to give routes
an explicit name, you can do so using the OpenAPI operationId
property:
Add format suffix automatically
If your API supports different formats it is often common to optionally allow specifying the requested format as a suffix
to the endpoint instead of having to always change headers for content negotiation.
The routing loader allows to add a .{_format}
placeholder automatically to the routes. This is disabled by default
and can be enabled using a format-suffix
OpenAPI vendor extension:
The above example will create a route /foobar.{_format}
where the format is optional and can be json or xml.
You can also enable the format-suffix globally by configuring it on the root OpenApi annotation and disable it for
certain routes again, see test fixtures.
Order routes with priority
Since Symfony 5.1, the order of routes defined using annotations can be influenced using a priority.
This can be used to make sure templated routes do not match before concrete routes without parameters for the same URL.
The priority can also be set on OpenAPI annotations using a priority
vendor extension:
Contributing
To run tests:
$ composer install
$ vendor/bin/simple-phpunit
All versions of openapi-symfony-routing with dependencies
symfony/finder Version ^4.4|^5.0
symfony/framework-bundle Version ^4.4|^5.0
symfony/routing Version ^4.4|^5.0
zircote/swagger-php Version ^3.0.3