Skip to content

Commit 814de96

Browse files
docs: explain openapi boolean option (#1590)
1 parent a967c21 commit 814de96

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

core/controllers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ In the following examples, the built-in `GET` operation is registered as well as
2323

2424
By default, API Platform uses the first `Get` operation defined to generate the IRI of an item and the first `GetCollection` operation to generate the IRI of a collection.
2525

26+
If your resource does not have any `Get` operation, API Platform automatically adds an operation to help generating this IRI.
27+
If your resource has any identifier, this operation will look like `/books/{id}`. But if your resource doesn't have any identifier, API Platform will use the Skolem format `/.well-known/genid/{id}`.
28+
Those routes are not exposed from any documentation (for instance OpenAPI), but are anyway declared on the Symfony routing and always return a HTTP 404.
29+
2630
If you create a custom operation, you will probably want to properly document it.
2731
See the [OpenAPI](openapi.md) part of the documentation to do so.
2832

core/openapi.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,61 @@ This will produce the following Swagger documentation:
253253

254254
To pass a context to the OpenAPI **v2** generator, use the `swaggerContext` attribute (notice the prefix: `swagger` instead of `openapi`).
255255

256+
## Disabling an Operation From OpenAPI Documentation
257+
258+
Sometimes you may want to disable an operation from the OpenAPI documentation, for example to not exposing it.
259+
Using the `openapi` boolean option disables this operation from the OpenAPI documentation:
260+
261+
[codeSelector]
262+
263+
```php
264+
<?php
265+
// api/src/Entity/Product.php
266+
namespace App\Entity;
267+
268+
use ApiPlatform\Metadata\ApiResource;
269+
use ApiPlatform\Metadata\GetCollection;
270+
271+
#[ApiResource(
272+
operations: [
273+
new GetCollection(openapi: false)
274+
]
275+
)]
276+
class Product
277+
{
278+
// ...
279+
}
280+
```
281+
282+
```yaml
283+
# api/config/api_platform/resources.yaml
284+
resources:
285+
App\Entity\Product:
286+
operations:
287+
ApiPlatform\Metadata\GetCollection:
288+
openapi: false
289+
```
290+
291+
```xml
292+
<?xml version="1.0" encoding="UTF-8" ?>
293+
<!-- api/config/api_platform/resources.xml -->
294+
295+
<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
296+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
297+
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
298+
https://api-platform.com/schema/metadata/resources-3.0.xsd">
299+
<resource class="App\Entity\Product">
300+
<operations>
301+
<operation class="ApiPlatform\Metadata\GetCollection" openapi="false" />
302+
</operations>
303+
</resource>
304+
</resources>
305+
```
306+
307+
[/codeSelector]
308+
309+
Note: as your route is not exposed, you may want to return a HTTP 404 if it's called. Prefer using the `NotExposedAction` controller instead.
310+
256311
## Changing the Name of a Definition
257312

258313
API Platform generates a definition name based on the serializer `groups` defined

0 commit comments

Comments
 (0)