Skip to content

Commit 8105302

Browse files
committed
Fix Open Api Definitions models
1 parent 05bff41 commit 8105302

File tree

4 files changed

+66
-16
lines changed

4 files changed

+66
-16
lines changed

UPGRADE-4.x.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@ UPGRADE FROM 4.x to 4.x
1616

1717
Controllers for NelmioApiDocBundle v2 were moved under `Sonata\UserBundle\Controller\Api\Legacy\` namespace and controllers for NelmioApiDocBundle v3 were added as replacement. If you extend them, you must ensure they are using the corresponding inheritance.
1818

19-
### Fix REST API routing paths
19+
### Fix REST API
2020

21-
In version 4.6.0 some extra REST API routes were added by mistake, creating new duplicated paths pointing to existing actions (by instance `/groups/{id}.{_format}` was duplicated as `/group/{id}.{_format}`, `/users/{id}.{_format}` was duplicated as `/user/{id}.{_format}`, etc).
22-
You MUST avoid importing these routes in order to keep your API routing clean and consistent with previous versions. To do so, make sure to import some of these routing files, depending on your needs:
21+
- Routing paths
2322

24-
sonata_api_user:
25-
prefix: /api/user
26-
resource: "@SonataUserBundle/Resources/config/routing/standard_api.xml"
27-
# or for NelmioApiDocBundle v3
28-
#resource: "@SonataUserBundle/Resources/config/routing/standard_api_nelmio_v3.xml"
23+
In version 4.6.0 some extra REST API routes were added by mistake, creating new duplicated paths pointing to existing actions (by instance `/groups/{id}.{_format}` was duplicated as `/group/{id}.{_format}`, `/users/{id}.{_format}` was duplicated as `/user/{id}.{_format}`, etc).
24+
You MUST avoid importing these routes in order to keep your API routing clean and consistent with previous versions. To do so, make sure to import some of these routing files, depending on your needs:
25+
26+
sonata_api_user:
27+
prefix: /api/user
28+
resource: "@SonataUserBundle/Resources/config/routing/standard_api.xml"
29+
# or for NelmioApiDocBundle v3
30+
#resource: "@SonataUserBundle/Resources/config/routing/standard_api_nelmio_v3.xml"
31+
32+
- Open Api Definitions
33+
34+
If you want use NelmioApiDocBudle v3 you MUST add extra config for it:
35+
36+
nelmio_api_doc:
37+
models:
38+
names:
39+
- { alias: SonataUserGroup, type: '%sonata.user.admin.group.entity%', groups: [sonata_api_read] }
40+
- { alias: SonataUserUser, type: '%sonata.user.admin.user.entity%', groups: [sonata_api_read] }
41+
# or these alias for ODM
42+
#- { alias: SonataUserGroup, type: '%sonata.user.admin.group.document%', groups: [sonata_api_read] }
43+
#- { alias: SonataUserUser, type: '%sonata.user.admin.user.document%', groups: [sonata_api_read] }
2944

3045
UPGRADE FROM 4.6 to 4.7
3146
========================

docs/reference/api.rst

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ Here's the configuration we used, you may adapt it to your needs:
3535
router: { annotations: true }
3636
request: { converters: true }
3737
38+
nelmio_api_doc:
39+
models:
40+
names:
41+
- { alias: SonataUserGroup, type: '%sonata.user.admin.group.entity%', groups: [sonata_api_read] }
42+
- { alias: SonataUserUser, type: '%sonata.user.admin.user.entity%', groups: [sonata_api_read] }
43+
# or these alias for ODM
44+
#- { alias: SonataUserGroup, type: '%sonata.user.admin.group.document%', groups: [sonata_api_read] }
45+
#- { alias: SonataUserUser, type: '%sonata.user.admin.user.document%', groups: [sonata_api_read] }
46+
3847
twig:
3948
exception_controller: null
4049
@@ -60,3 +69,29 @@ The taxonomy is as follows:
6069
* ``sonata_api_write`` is the group used for input entities (when used instead of forms)
6170

6271
If you wish to customize the outputted data, feel free to set up your own serialization options by configuring `JMSSerializer` with those groups.
72+
73+
Documentation
74+
-------------
75+
76+
In order to activate the API’s documentation, you’ll also need to add this to your routing:
77+
78+
.. code-block:: yaml
79+
80+
## Requires the Asset component and the Twig bundle
81+
## $ composer require twig asset
82+
app.swagger_ui:
83+
path: /api/doc
84+
methods: GET
85+
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
86+
87+
Open Api Definition
88+
-------------------
89+
90+
You can generate your Open Api Definitions after add this to your routing:
91+
92+
.. code-block:: yaml
93+
94+
app.swagger:
95+
path: /api/doc.json
96+
methods: GET
97+
defaults: { _controller: nelmio_api_doc.controller.swagger }

src/Controller/Api/GroupController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getGroupsAction(ParamFetcherInterface $paramFetcher)
137137
* @SWG\Response(
138138
* response="200",
139139
* description="Returned when successful",
140-
* @SWG\Schema(ref=@Model(type="FOS\UserBundle\Model\GroupInterface"))
140+
* @SWG\Schema(ref="#/definitions/SonataUserGroup")
141141
* ),
142142
* @SWG\Response(
143143
* response="404",
@@ -165,7 +165,7 @@ public function getGroupAction($id)
165165
* @SWG\Response(
166166
* response="200",
167167
* description="Returned when successful",
168-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\Group"))
168+
* @SWG\Schema(ref="#/definitions/SonataUserGroup")
169169
* ),
170170
* @SWG\Response(
171171
* response="400",
@@ -193,7 +193,7 @@ public function postGroupAction(Request $request)
193193
* @SWG\Response(
194194
* response="200",
195195
* description="Returned when successful",
196-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\Group"))
196+
* @SWG\Schema(ref="#/definitions/SonataUserGroup")
197197
* ),
198198
* @SWG\Response(
199199
* response="400",

src/Controller/Api/UserController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function getUsersAction(ParamFetcherInterface $paramFetcher)
141141
* @SWG\Response(
142142
* response="200",
143143
* description="Returned when successful",
144-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\UserInterface"))
144+
* @SWG\Schema(ref="#/definitions/SonataUserUser")
145145
* ),
146146
* @SWG\Response(
147147
* response="404",
@@ -169,7 +169,7 @@ public function getUserAction($id)
169169
* @SWG\Response(
170170
* response="200",
171171
* description="Returned when successful",
172-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\Group"))
172+
* @SWG\Schema(ref="#/definitions/SonataUserGroup")
173173
* ),
174174
* @SWG\Response(
175175
* response="400",
@@ -197,7 +197,7 @@ public function postUserAction(Request $request)
197197
* @SWG\Response(
198198
* response="200",
199199
* description="Returned when successful",
200-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\User"))
200+
* @SWG\Schema(ref="#/definitions/SonataUserUser")
201201
* ),
202202
* @SWG\Response(
203203
* response="400",
@@ -265,7 +265,7 @@ public function deleteUserAction($id)
265265
* @SWG\Response(
266266
* response="200",
267267
* description="Returned when successful",
268-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\User"))
268+
* @SWG\Schema(ref="#/definitions/SonataUserUser")
269269
* ),
270270
* @SWG\Response(
271271
* response="400",
@@ -311,7 +311,7 @@ public function postUserGroupAction($userId, $groupId)
311311
* @SWG\Response(
312312
* response="200",
313313
* description="Returned when successful",
314-
* @SWG\Schema(ref=@Model(type="Sonata\UserBundle\Model\User"))
314+
* @SWG\Schema(ref="#/definitions/SonataUserUser")
315315
* ),
316316
* @SWG\Response(
317317
* response="400",

0 commit comments

Comments
 (0)