Skip to content

Commit 284cb89

Browse files
authored
Merge branch 'api-platform:3.1' into 3.1
2 parents 9776f6e + c184606 commit 284cb89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+545
-479
lines changed

.github/workflows/cd.yml

+36-18
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,18 @@ jobs:
2828
restore-keys: |
2929
${{ runner.os }}-yarn-
3030
31-
- name: Install deps
32-
run: yarn install
3331
34-
- name: Retrieve docs
35-
run: bin/retrieve-documentation
36-
37-
- name: Build website
38-
env:
39-
GITHUB_KEY: ${{ secrets.CONTRIBUTORS_GITHUB_TOKEN }}
40-
NODE_OPTIONS: --openssl-legacy-provider
41-
run: yarn gatsby build
32+
- name: Setup Hugo
33+
uses: peaceiris/actions-hugo@v2
34+
with:
35+
hugo-version: '0.119.0'
36+
extended: true
4237

43-
- name: Deploy
44-
uses: peaceiris/actions-gh-pages@v3
38+
- name: Install php
39+
uses: shivammathur/setup-php@v2
4540
with:
46-
github_token: ${{ secrets.GITHUB_TOKEN }}
47-
publish_dir: ./public
48-
cname: api-platform.com
41+
php-version: '8.2'
42+
tools: phive
4943

5044
- name: Auth gcloud
5145
uses: google-github-actions/auth@v1
@@ -54,6 +48,30 @@ jobs:
5448

5549
- name: 'Set up Cloud SDK'
5650
uses: 'google-github-actions/setup-gcloud@v1'
57-
58-
- name: Deploy on bucket
59-
run: gsutil -m rsync -d -r ./public gs://api-platform-website-v3/
51+
52+
- name: Compute documentation
53+
run: |
54+
git clone https://github.com/api-platform/docs-website
55+
cd docs-website
56+
npm install
57+
# fetches api-platform/docs
58+
bash tools/get-docs.sh
59+
# fetches api-platform/core for reference and guides
60+
bash tools/get-core-docs.sh
61+
# builds the config/_default/menu.toml according to the outline.yaml from api-platform/docs
62+
node tools/menu.mjs
63+
# build our tailwind theme
64+
hugo --minify
65+
gsutil -q -m rsync -d -r ./public gs://api-platform-website-v3/
66+
# This need to move to website
67+
# env:
68+
# GITHUB_KEY: ${{ secrets.CONTRIBUTORS_GITHUB_TOKEN }}
69+
# NODE_OPTIONS: --openssl-legacy-provider
70+
71+
# - name: Deploy
72+
# uses: peaceiris/actions-gh-pages@v3
73+
# with:
74+
# github_token: ${{ secrets.GITHUB_TOKEN }}
75+
# publish_dir: ./public
76+
# cname: api-platform.com
77+

admin/authentication-support.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ const Admin = () => {
7979
</Head>
8080

8181
<HydraAdmin dataProvider={dataProvider(setRedirectToLogin)} authProvider={authProvider} entrypoint={window.origin}>
82-
<CustomRoutes>
83-
{redirectToLogin ? <Route path="/" element={<RedirectToLogin />} /> : null}
84-
</CustomRoutes>
82+
{redirectToLogin ? (
83+
<CustomRoutes>
84+
<Route path="/" element={<RedirectToLogin />} />
85+
<Route path="/:any" element={<RedirectToLogin />} />
86+
</CustomRoutes>
87+
) : (
88+
<>
89+
<Resource name=".." list="..">
90+
<Resource name=".." list="..">
91+
</>
92+
)}
8593
</HydraAdmin>
8694
</>
8795
);

admin/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![Screencast](images/admin-demo.gif)
44

55
API Platform Admin is a tool to automatically create a beautiful (Material Design) and fully-featured administration interface
6-
for any API supporting [the Hydra Core Vocabulary](http://www.hydra-cg.com/), exposing an [OpenAPI documentation](https://www.openapis.org/)
6+
for any API supporting [the Hydra Core Vocabulary](https://www.hydra-cg.com/), exposing an [OpenAPI documentation](https://www.openapis.org/)
77
or other API specification formats supported by [`@api-platform/api-doc-parser`](https://github.com/api-platform/api-doc-parser).
88

99
API Platform Admin is the perfect companion of APIs created

core/angularjs-integration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Warning: for a new project, you should consider using [the API Platform's Progre
55

66
## Restangular
77

8-
API Platform works fine with [AngularJS v1](http://angularjs.org). The popular [Restangular](https://github.com/mgonto/restangular)
8+
API Platform works fine with [AngularJS v1](https://angularjs.org/). The popular [Restangular](https://github.com/mgonto/restangular)
99
REST client library for Angular can easily be configured to handle the API format.
1010

1111
Here is a working Restangular config:

core/bootstrap.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use ApiPlatform\JsonLd\Serializer\ObjectNormalizer as JsonLdObjectNormalizer;
5757
use ApiPlatform\JsonLd\ContextBuilder as JsonLdContextBuilder;
5858
use ApiPlatform\JsonSchema\SchemaFactory;
5959
use ApiPlatform\JsonSchema\TypeFactory;
60+
use ApiPlatform\Metadata\ApiResource;
6061
use ApiPlatform\Metadata\CollectionOperationInterface;
6162
use ApiPlatform\Metadata\HttpOperation;
6263
use ApiPlatform\Metadata\Operation;
@@ -257,7 +258,7 @@ $providerCollection = new class implements ContainerInterface {
257258
}
258259

259260
public function has($id): bool {
260-
return isset($this->providers['id']);
261+
return isset($this->providers[$id]);
261262
}
262263
};
263264
$stateProviders = new CallableProvider($providerCollection);
@@ -289,6 +290,12 @@ class Validator implements ValidatorInterface {
289290
$validator = new Validator(Validation::createValidator());
290291
$validateListener = new ValidateListener($validator, $resourceMetadataFactory);
291292

293+
#[ApiResource(provider: \BookProvider::class)]
294+
class Book
295+
{
296+
public int $id;
297+
}
298+
292299
class BookProvider implements ProviderInterface
293300
{
294301
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null

core/content-negotiation.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Format | Format name |
2222
----------------------------------------------------------------|--------------|-------------------------------|----------------------------------------
2323
[JSON-LD](https://json-ld.org) | `jsonld` | `application/ld+json` | yes
2424
[GraphQL](graphql.md) | n/a | n/a | yes
25-
[JSON:API](http://jsonapi.org/) | `jsonapi` | `application/vnd.api+json` | yes
25+
[JSON:API](https://jsonapi.org/) | `jsonapi` | `application/vnd.api+json` | yes
2626
[HAL](https://stateless.group/hal_specification.html) | `jsonhal` | `application/hal+json` | yes
27-
[YAML](http://yaml.org/) | `yaml` | `application/x-yaml` | no
27+
[YAML](https://yaml.org/) | `yaml` | `application/x-yaml` | no
2828
[CSV](https://tools.ietf.org/html/rfc4180) | `csv` | `text/csv` | no
2929
[HTML](https://whatwg.org/) (API docs) | `html` | `text/html` | no
3030
[XML](https://www.w3.org/XML/) | `xml` | `application/xml`, `text/xml` | no
@@ -119,9 +119,9 @@ Additionally the `csv` format is added with the MIME type `text/csv`.
119119
It is also important to notice that the usage of this attribute will override the formats defined in the configuration, therefore
120120
this configuration might disable the `json` or the `html` on this resource for example.
121121

122-
You can specify different accepted formats at operation level too, it's especially convenient for to configure formats available for the `PATCH` method:
122+
You can specify different accepted formats at operation level too, it's especially convenient to configure formats available for the `PATCH` method:
123123

124-
[codeSelector]
124+
<code-selector>
125125

126126
```php
127127
<?php
@@ -178,12 +178,12 @@ resources:
178178
</resources>
179179
```
180180

181-
[/codeSelector]
181+
</code-selector>
182182

183183
## Supporting Custom Formats
184184

185185
The API Platform content negotiation system is extendable.
186-
You can add support for formats not available by default by creating custom normalizer and encoders.
186+
You can add support for formats not available by default by creating custom normalizers and encoders.
187187
Refer to the Symfony documentation to learn [how to create and register such classes](https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders).
188188

189189
Then, register the new format in the configuration:

core/controllers.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Note: using custom controllers with API Platform is **discouraged**. Also, Graph
44
[For most use cases, better extension points, working both with REST and GraphQL, are available](design.md).
55

66
API Platform can leverage the Symfony routing system to register custom operations related to custom controllers. Such custom
7-
controllers can be any valid [Symfony controller](http://symfony.com/doc/current/book/controller.html), including standard
7+
controllers can be any valid [Symfony controller](https://symfony.com/doc/current/controller.html), including standard
88
Symfony controllers extending the [`Symfony\Bundle\FrameworkBundle\Controller\AbstractController`](http://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.html)
99
helper class.
1010

@@ -15,7 +15,7 @@ implements the [Action-Domain-Responder](https://github.com/pmjones/adr) pattern
1515
The distribution of API Platform also eases the implementation of the ADR pattern: it automatically registers action classes
1616
stored in `api/src/Controller` as autowired services.
1717

18-
Thanks to the [autowiring](http://symfony.com/doc/current/components/dependency_injection/autowiring.html) feature of the
18+
Thanks to the [autowiring](https://symfony.com/doc/current/service_container/autowiring.html) feature of the
1919
Symfony Dependency Injection container, services required by an action can be type-hinted in its constructor, it will be
2020
automatically instantiated and injected, without having to declare it explicitly.
2121

@@ -85,7 +85,7 @@ the client.
8585

8686
The routing has not been configured yet because we will add it at the resource configuration level:
8787

88-
[codeSelector]
88+
<code-selector>
8989

9090
```php
9191
<?php
@@ -143,7 +143,7 @@ resources:
143143
</resources>
144144
```
145145

146-
[/codeSelector]
146+
</code-selector>
147147

148148
It is mandatory to set the `method`, `uriTemplate` and `controller` attributes. They allow API Platform to configure the routing path and
149149
the associated controller respectively.
@@ -158,7 +158,7 @@ To avoid that, API Platform provides the `ApiPlatform\Action\PlaceholderAction`
158158

159159
You just need to set the `controller` attribute with this class. Here, the previous example updated:
160160

161-
[codeSelector]
161+
<code-selector>
162162

163163
```php
164164
// api/src/Entity/Book.php
@@ -215,13 +215,13 @@ resources:
215215
</resources>
216216
```
217217

218-
[/codeSelector]
218+
</code-selector>
219219

220220
## Using Serialization Groups
221221

222222
You may want different serialization groups for your custom operations. Just configure the proper `normalizationContext` and/or `denormalizationContext` in your operation:
223223

224-
[codeSelector]
224+
<code-selector>
225225

226226
```php
227227
<?php
@@ -240,7 +240,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
240240
name: 'publication',
241241
uriTemplate: '/books/{id}/publication',
242242
controller: CreateBookPublication::class,
243-
normalizationContext: ['groups' => 'publication']
243+
normalizationContext: ['groups' => ['publication']],
244244
)
245245
])]
246246
class Book
@@ -292,14 +292,14 @@ resources:
292292
</resources>
293293
```
294294

295-
[/codeSelector]
295+
</code-selector>
296296

297297
## Retrieving the Entity
298298

299299
If you want to bypass the automatic retrieval of the entity in your custom operation, you can set `read: false` in the
300300
operation attribute:
301301

302-
[codeSelector]
302+
<code-selector>
303303

304304
```php
305305
<?php
@@ -357,7 +357,7 @@ resources:
357357
</resources>
358358
```
359359

360-
[/codeSelector]
360+
</code-selector>
361361

362362
This way, it will skip the `ReadListener`. You can do the same for some other built-in listeners. See [Built-in Event Listeners](events.md#built-in-event-listeners)
363363
for more information.
@@ -377,7 +377,7 @@ for `book_post_discontinuation` when neither `method` nor `routeName` attributes
377377

378378
First, let's create your resource configuration:
379379

380-
[codeSelector]
380+
<code-selector>
381381

382382
```php
383383
<?php
@@ -430,10 +430,10 @@ resources:
430430
</resources>
431431
```
432432

433-
[/codeSelector]
433+
</code-selector>
434434

435435
API Platform will automatically map this `post_publication` operation to the route `book_post_publication`. Let's create a custom action
436-
and its related route using annotations:
436+
and its related route using attributes:
437437

438438
```php
439439
<?php

core/default-order.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ API Platform provides an easy way to override the default order of items in your
55
By default, items in the collection are ordered in ascending (ASC) order by their resource identifier(s). If you want to
66
customize this order, you must add an `order` attribute on your ApiResource annotation:
77

8-
[codeSelector]
8+
<code-selector>
99

1010
```php
1111
<?php
@@ -35,12 +35,12 @@ App\Entity\Book:
3535
foo: ASC
3636
```
3737
38-
[/codeSelector]
38+
</code-selector>
3939
4040
This `order` attribute is used as an array: the key defines the order field, the values defines the direction.
4141
If you only specify the key, `ASC` direction will be used as default. For example, to order by `foo` & `bar`:
4242

43-
[codeSelector]
43+
<code-selector>
4444

4545
```php
4646
<?php
@@ -74,11 +74,11 @@ App\Entity\Book:
7474
order: ['foo', 'bar']
7575
```
7676

77-
[/codeSelector]
77+
</code-selector>
7878

7979
It's also possible to configure the default order on an association property:
8080

81-
[codeSelector]
81+
<code-selector>
8282

8383
```php
8484
<?php
@@ -107,11 +107,11 @@ App\Entity\Book:
107107
order: ['author.username']
108108
```
109109

110-
[/codeSelector]
110+
</code-selector>
111111

112112
Another possibility is to apply the default order for a specific collection operation, which will override the global default order configuration.
113113

114-
[codeSelector]
114+
<code-selector>
115115

116116
```php
117117
<?php
@@ -155,4 +155,4 @@ App\Entity\Book:
155155
name: ASC
156156
```
157157

158-
[/codeSelector]
158+
</code-selector>

core/deprecations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It's a tedious task that should be avoided as much as possible.
99
On the other hand, the evolution strategy (also known as versionless APIs) consists of deprecating the fields, resources
1010
types or operations that will be removed at some point.
1111

12-
Most modern API formats including [JSON-LD / Hydra](content-negotiation.md), [GraphQL](graphql.md) and [OpenAPI](swagger.md)
12+
Most modern API formats including [JSON-LD / Hydra](content-negotiation.md), [GraphQL](graphql.md) and [OpenAPI](openapi.md)
1313
allow you to mark resources types, operations or fields as deprecated.
1414

1515
## Deprecating Resource Classes, Operations and Properties
@@ -67,7 +67,7 @@ class Parchment
6767

6868
It's also possible to deprecate a single property:
6969

70-
[codeSelector]
70+
<code-selector>
7171

7272
```php
7373
<?php
@@ -99,7 +99,7 @@ properties:
9999
deprecationReason: 'Use the rating property instead'
100100
```
101101
102-
[/codeSelector]
102+
</code-selector>
103103
104104
* With JSON-lD / Hydra, [an `owl:deprecated` annotation property](https://www.w3.org/TR/owl2-syntax/#Annotation_Properties) will be added to the appropriate data structure
105105
* With Swagger / OpenAPI, [a `deprecated` property](https://swagger.io/docs/specification/2-0/paths-and-operations/) will be added

core/design.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To do so, you have to write a plain old PHP object (POPO) representing the input
88
that is [marked with the `#[ApiResource]` attribute](../distribution/index.md).
99
This class **doesn't have** to be mapped with Doctrine ORM, or any other persistence system. It must be simple (it's usually
1010
just a data structure with no or minimal behaviors) and will be automatically converted to [Hydra](extending-jsonld-context.md),
11-
[OpenAPI](swagger.md) and [GraphQL](graphql.md) documentations or schemas by API Platform (there is a 1-1 mapping
11+
[OpenAPI](openapi.md) and [GraphQL](graphql.md) documentations or schemas by API Platform (there is a 1-1 mapping
1212
between this class and those docs).
1313

1414
Then, it's up to the developer to feed API Platform with an hydrated instance of this API resource object by implementing

0 commit comments

Comments
 (0)