Skip to content

Commit

Permalink
Merge branch '4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Oct 2, 2024
2 parents 9506e8e + 72a22d6 commit cb93b34
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion core/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ vich_uploader:
media_object:
uri_prefix: /media
upload_destination: '%kernel.project_dir%/public/media'
# Will rename uploaded files using a uniqueid as a prefix.
# Will rename uploaded files using a uniqueid as a suffix.
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
```
Expand Down
17 changes: 10 additions & 7 deletions core/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A parameter can alter the current Operation context, to do so use a `ApiPlatform

```php
class GroupsParameterProvider implements ParameterProviderInterface {
public function provider(Parameter $parameter, array $uriVariables = [], array $context = []): HttpOperation
public function provide(Parameter $parameter, array $uriVariables = [], array $context = []): HttpOperation
{
$request = $context['request'];
return $context['operation']->withNormalizationContext(['groups' => $request->query->all('groups')]);
Expand Down Expand Up @@ -1534,6 +1534,7 @@ use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\PropertyInfo\Type;
use ApiPlatform\OpenApi\Model\Parameter;
final class RegexpFilter extends AbstractFilter
{
Expand Down Expand Up @@ -1567,12 +1568,14 @@ final class RegexpFilter extends AbstractFilter
'type' => Type::BUILTIN_TYPE_STRING,
'required' => false,
'description' => 'Filter using a regex. This will appear in the OpenApi documentation!',
'openapi' => [
'example' => 'Custom example that will be in the documentation and be the default value of the sandbox',
'allowReserved' => false,// if true, query parameters will be not percent-encoded
'allowEmptyValue' => true,
'explode' => false, // to be true, the type must be Type::BUILTIN_TYPE_ARRAY, ?product=blue,green will be ?product=blue&product=green
],
'openapi' => new Parameter(
name: $property,
in: 'query',
allowEmptyValue: true,
explode: false, // to be true, the type must be Type::BUILTIN_TYPE_ARRAY, ?product=blue,green will be ?product=blue&product=green
allowReserved: false, // if true, query parameters will be not percent-encoded
example: 'Custom example that will be in the documentation and be the default value of the sandbox',
),
];
}
Expand Down
13 changes: 6 additions & 7 deletions core/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
You can choose your preferred stack between Symfony, Laravel, or bootstrapping the API Platform core library manually.

> [!CAUTION]
>
> If you are migrating from an older version of API Platform, make sure you read the [Upgrade Guide](upgrade-guide.md).
### Symfony
Expand Down Expand Up @@ -263,11 +262,11 @@ Open the generated migration class (`database/migrations/<timestamp>_create_prod
Schema::create('products', function (Blueprint $table) {
$table->id();
+ $table->string('name');
+ $table->decimal('price', 8, 2);
+ $table->text('description');
+ $table->boolean('is_active')->default(true);
+ $table->date('created_date')->nullable();
+ $table->string('name');
+ $table->decimal('price', 8, 2);
+ $table->text('description');
+ $table->boolean('is_active')->default(true);
+ $table->date('created_date')->nullable();
$table->timestamps();
});
Expand All @@ -277,7 +276,7 @@ Open the generated migration class (`database/migrations/<timestamp>_create_prod
Finally, execute the migration:

```console
php artisan
php artisan migrate
```

And after that, just adding the `#[ApiResource]` attribute as follows onto your model:
Expand Down
30 changes: 22 additions & 8 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ an implementation point of view, an operation is a link between a resource, a ro
<p align="center" class="symfonycasts"><a href="https://symfonycasts.com/screencast/api-platform/operations?cid=apip"><img src="../symfony/images/symfonycasts-player.png" alt="Operations screencast"><br>Watch the Operations screencast</a></p>

API Platform automatically registers typical [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations
and describes them in the exposed documentation (Hydra and Swagger). It also creates and registers routes corresponding
to these operations in the Symfony routing system (if it is available).
and describes them in the exposed documentation (Hydra and Swagger). It also creates and registers routes
for these operations in the Symfony routing system, if available, or in the Laravel routing system,
should that be the case.

The behavior of built-in operations is briefly presented in the [Getting started](getting-started.md#mapping-the-entities)
guide.
Expand Down Expand Up @@ -42,13 +43,20 @@ Method | Mandatory | Description | Registered b
`PATCH` | no | Apply a partial modification to an element | yes
`DELETE` | no | Delete an element | yes

Note: the `PATCH` method must be enabled explicitly in the configuration, refer to the [Content Negotiation](content-negotiation.md) section for more information.
> [!NOTE]
> The `PATCH` method must be enabled explicitly in the configuration, refer to the [Content Negotiation](content-negotiation.md) section for more information.
Note: with JSON Merge Patch, the [null values will be skipped](https://symfony.com/doc/current/components/serializer.html#skipping-null-values) in the response.
---

Note: Current `PUT` implementation behaves more or less like the `PATCH` method.
Existing properties not included in the payload are **not** removed, their current values are preserved.
To remove an existing property, its value must be explicitly set to `null`.
> [!NOTE]
> With JSON Merge Patch, the [null values will be skipped](https://symfony.com/doc/current/components/serializer.html#skipping-null-values) in the response.
---

> [!NOTE]
> Current `PUT` implementation behaves more or less like the `PATCH` method.
> Existing properties not included in the payload are **not** removed, their current values are preserved.
> To remove an existing property, its value must be explicitly set to `null`.
## Enabling and Disabling Operations

Expand All @@ -64,7 +72,13 @@ for the `GET` method for both `collection` and `item` to create a readonly endpo
If the operation's name matches a supported HTTP method (`GET`, `POST`, `PUT`, `PATCH` or `DELETE`), the corresponding `method` property
will be automatically added.

Note: The `#[GetCollection]` attribute is an alias for `#[Get(collection: true)]`
> [!TIP]
> The `#[GetCollection]` attribute is an alias for `#[Get(collection: true)]`
---

> [!NOTE]
> In Symfony we use the term “entities”, while the following documentation is mostly for Laravel “models”.
<code-selector>

Expand Down
10 changes: 5 additions & 5 deletions laravel/filters.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Parameters and Filters

API Platform is great for Rapid Application Development and provides lots of functionalities out of the box such as collection filtering with Eloquent. Most of the filtering is done using query parameters, which are automatically documented and validated. If needed you can use [state providers](core/state-providers) or a [Links Handler] to provide data.
API Platform is great for Rapid Application Development and provides lots of functionalities out of the box such as collection filtering with Eloquent. Most of the filtering is done using query parameters, which are automatically documented and validated. If needed you can use [state providers](../core/state-providers.md) or a [Links Handler] to provide data.

## Parameters

Expand Down Expand Up @@ -84,13 +84,13 @@ class Book extends Model
}
```

The documentation will output a query parameter per property that applies the `PartialSearchFilter` and also gives the ability to sort by name and id using: `/books?name=search&order[id]=asc&order[name]=desc`.
The documentation will output a query parameter per property that applies the `PartialSearchFilter` and also gives the ability to sort by name and ID using: `/books?name=search&order[id]=asc&order[name]=desc`.

## Filters

### Text

As shown above the following search filters are available:
As shown above the following search filters are available:

- `ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter` queries `LIKE %term%`
- `ApiPlatform\Laravel\Eloquent\Filter\EqualsFilter` queries `= term`
Expand All @@ -99,7 +99,7 @@ As shown above the following search filters are available:

### Date

The `DateFilter` allows to filter dates with an operator (`eq`, `lt`, `gt`, `lte`, `gte`):
The `DateFilter` allows to filter dates with an operator (`eq`, `lt`, `gt`, `lte`, `gte`):

```php
// app/Models/Book.php
Expand All @@ -119,7 +119,7 @@ class Book extends Model
}
```

Our default strategy is to exclude null values, just remove the `filterContext` if you want to exclude nulls.
Our default strategy is to exclude null values, just remove the `filterContext` if you want to exclude nulls.

### Or

Expand Down

0 comments on commit cb93b34

Please sign in to comment.