@@ -8,6 +8,11 @@ Loads routes in Symfony based on [OpenAPI/Swagger annotations](https://github.co
88
99 $ composer require tobion/openapi-symfony-routing
1010
11+ Version >= 1.2 requires zircote/swagger-php 3.x which is compatible with the OpenAPI Specification version 3.
12+ Version < 1.2 requires zircote/swagger-php 2.x which works with the OpenAPI Specification version 2 (fka Swagger).
13+ So tobion/openapi-symfony-routing can be used with both OpenAPI v2 and v3 and composer will select the compatible one for your dependencies.
14+ Route loading stays the same between version. You just need to update the annotations when migrating from OpenAPI v2 to v3.
15+
1116## Basic Usage
1217
1318This library allows to (re-)use your OpenAPI documentation to configure the routing of your Symfony-based API.
@@ -16,19 +21,19 @@ This way you do not have to duplicate any routing information in Symfony. Consid
1621[ zircote/swagger-php] ( https://github.com/zircote/swagger-php ) like the following example:
1722
1823``` php
19- use Swagger \Annotations as SWG ;
24+ use OpenApi \Annotations as OA ;
2025
2126/**
22- * @SWG\Swagger (
23- * @SWG \Info(title="My API", version="1.0")
27+ * @OA\OpenApi (
28+ * @OA \Info(title="My API", version="1.0")
2429 * )
2530 */
2631class MyController
2732{
2833 /**
29- * @SWG \Get(
34+ * @OA \Get(
3035 * path="/foobar",
31- * @SWG \Response(response="200", description="Success")
36+ * @OA \Response(response="200", description="Success")
3237 * )
3338 */
3439 public function __invoke()
@@ -77,15 +82,15 @@ By default routes are auto-named based on the controller class and method. If yo
7782an explicit name, you can do so using the OpenAPI ` operationId` property:
7883
7984` ` ` php
80- use Swagger \A nnotations as SWG ;
85+ use OpenApi \A nnotations as OA ;
8186
8287class MyController
8388{
8489 /**
85- * @SWG \G et(
90+ * @OA \G et(
8691 * path="/foobar",
8792 * operationId="my-name",
88- * @SWG \R esponse(response="200", description="Success")
93+ * @OA \R esponse(response="200", description="Success")
8994 * )
9095 */
9196 public function __invoke()
@@ -102,18 +107,18 @@ The routing loader allows to add a `.{_format}` placeholder automatically to the
102107and can be enabled using a `format-suffix` OpenAPI vendor extension :
103108
104109` ` ` php
105- use Swagger \A nnotations as SWG ;
110+ use OpenApi \A nnotations as OA ;
106111
107112class MyController
108113{
109114 /**
110- * @SWG \G et(
115+ * @OA \G et(
111116 * path="/foobar",
112117 * x={"format-suffix": {
113118 * "enabled": true,
114119 * "pattern": "json|xml"
115120 * }},
116- * @SWG \R esponse(response="200", description="Success")
121+ * @OA \R esponse(response="200", description="Success")
117122 * )
118123 */
119124 public function __invoke()
@@ -123,7 +128,7 @@ class MyController
123128` ` `
124129
125130The above example will create a route `/foobar.{_format}` where the format is optional and can be json or xml.
126- You can also enable the format-suffix globally by configuring it on the root Swagger annotation and disable it for
131+ You can also enable the format-suffix globally by configuring it on the root OpenApi annotation and disable it for
127132certain routes again, see [test fixtures](./tests/Fixtures/FormatSuffix/Controller.php).
128133
129134# ## Order routes with priority
@@ -133,15 +138,15 @@ This can be used to make sure templated routes do not match before concrete rout
133138The priority can also be set on OpenAPI annotations using a `priority` vendor extension :
134139
135140` ` ` php
136- use Swagger \A nnotations as SWG ;
141+ use OpenApi \A nnotations as OA ;
137142
138143class MyController
139144{
140145 /**
141- * @SWG \G et(
146+ * @OA \G et(
142147 * path="/foobar",
143148 * x={"priority": 10},
144- * @SWG \R esponse(response="200", description="Success")
149+ * @OA \R esponse(response="200", description="Success")
145150 * )
146151 */
147152 public function __invoke()
0 commit comments