Skip to content

Commit 510c55f

Browse files
committed
[Swagger] Doc: Changing the name of a definition
1 parent ad11910 commit 510c55f

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

core/swagger.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Product // The class name will be used to name exposed resources
108108
* "swagger_context"={
109109
* "type"="string",
110110
* "enum"={"one", "two"},
111-
* "example"="one"
111+
* "example"="one"
112112
* }
113113
* }
114114
* )
@@ -179,3 +179,50 @@ Will produce the following Swagger documentation:
179179
}
180180
}
181181
```
182+
183+
### Changing the name of a definition
184+
185+
ApiPlatform generates a definition name based on the serializer `groups` defined
186+
in the (`de`)`denormalization_context`. It's possible to override the name
187+
thanks to the `swagger_definition_name` option:
188+
189+
```php
190+
/**
191+
* @ApiResource(
192+
* collectionOperations={
193+
* "post"={
194+
* "method"="POST",
195+
* "denormalization_context"={
196+
* "groups"={"user_read"},
197+
* "swagger_definition_name": "Read",
198+
* },
199+
* },
200+
* },
201+
* )
202+
*/
203+
class User
204+
{
205+
}
206+
```
207+
208+
It's also possible to re-use the `normalization_context`:
209+
210+
```php
211+
/**
212+
* @ApiResource(
213+
* collectionOperations={
214+
* "post"={
215+
* "method"="POST",
216+
* "denormalization_context"=User::API_WRITE,
217+
* },
218+
* },
219+
* )
220+
*/
221+
class User
222+
{
223+
const API_WRITE = [
224+
'groups' => ['user_read'],
225+
'swagger_definition_name' => 'Read',
226+
];
227+
}
228+
```

0 commit comments

Comments
 (0)