Skip to content

Commit de4ec84

Browse files
refactor: clean up docker cmds and improve code blocks (#2041)
1 parent 1a856de commit de4ec84

19 files changed

+137
-130
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ By contributing to this project, you agree to abide by our [Code of Conduct](htt
2424
1. Fork this repository by clicking the "Fork" button at the top right of the `api-platform/docs` repository page.
2525

2626
2. Clone the forked repository to your local machine:
27-
```bash
27+
```console
2828
git clone https://github.com/your-username/repository-name.git
2929
```
3030
3. Create a new branch for your contribution:
31-
```bash
31+
```console
3232
git switch -c docs-your-branch-name
3333
```
3434
4. Commit and push your changes

admin/getting-started.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ nelmio_cors:
5858
Clear the cache to apply this change:
5959
6060
```console
61-
docker compose exec php \
62-
bin/console cache:clear --env=prod
61+
bin/console cache:clear --env=prod
6362
```
6463

6564
Your new administration interface is ready! Type `npm start` to try it!

core/file-upload.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ api_platform:
2525
Install the bundle with the help of Composer:
2626
2727
```console
28-
docker compose exec php \
29-
composer require vich/uploader-bundle
28+
composer require vich/uploader-bundle
3029
```
3130

3231
This will create a new configuration file that you will need to slightly change

core/graphql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Once enabled, you have nothing to do: your schema describing your API is automat
1313
To enable GraphQL and its IDE (GraphiQL and GraphQL Playground) in your API, simply require the `api-platform/graphql` package using Composer:
1414

1515
```console
16-
composer require api-platform/graphql
16+
composer require api-platform/graphql
1717
```
1818

1919
You can now use GraphQL at the endpoint: `https://localhost:8443/graphql`.

core/json-schema.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ The generated schema can be used with libraries such as [react-json-schema-form]
1010
To export the schema corresponding to an API Resource, run the following command:
1111

1212
```console
13-
docker compose exec php \
14-
bin/console api:json-schema:generate 'App\Entity\Book'
13+
bin/console api:json-schema:generate 'App\Entity\Book'
1514
```
1615

1716
To see all options available, try:
1817

1918
```console
20-
docker compose exec php \
21-
bin/console help api:json-schema:generate
19+
bin/console help api:json-schema:generate
2220
```
2321

2422
## Overriding the JSON Schema Specification

core/jwt.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# JWT Authentication
22

3-
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
4-
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
3+
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert
4+
> some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and
5+
> provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
6+
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens
7+
> are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
58
>
69
> [Wikipedia](https://en.wikipedia.org/wiki/JSON_Web_Token)
710
@@ -14,11 +17,17 @@ API Platform allows to easily add a JWT-based authentication to your API using [
1417
We begin by installing the bundle:
1518

1619
```console
17-
docker compose exec php \
18-
composer require lexik/jwt-authentication-bundle
20+
composer require lexik/jwt-authentication-bundle
1921
```
22+
Then we need to generate the public and private keys used for signing JWT tokens.
2023

21-
Then we need to generate the public and private keys used for signing JWT tokens. If you're using the [API Platform distribution](../symfony/index.md), you may run this from the project's root directory:
24+
You can generate them by using this command:
25+
26+
```console
27+
php bin/console lexik:jwt:generate-keypair
28+
```
29+
30+
Or if you're using the [API Platform distribution with Symfony](../symfony/index.md), you may run this from the project's root directory:
2231

2332
```console
2433
docker compose exec php sh -c '
@@ -30,13 +39,18 @@ docker compose exec php sh -c '
3039
'
3140
```
3241

33-
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
42+
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform
43+
docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
3444

35-
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the correct permissions on the keys allowing the web server to read them.
45+
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the
46+
correct permissions on the keys allowing the web server to read them.
3647

37-
Since these keys are created by the `root` user from a container, your host user will not be able to read them during the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are skipped from the result image.
48+
If you want the keys to be auto generated in `dev` environment, see an example in the
49+
[docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/a03ce4fb1f0e072c126e8104e42a938bb840bffc/api/docker/php/docker-entrypoint.sh#L16-L17).
3850

39-
If you want the keys to be auto generated in `dev` environment, see an example in the [docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/master/api/docker/php/docker-entrypoint.sh).
51+
Since these keys are created by the `root` user from a container, your host user will not be able to read them during
52+
the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are
53+
skipped from the result image.
4054

4155
The keys should not be checked in to the repository (i.e. it's in `api/.gitignore`). However, note that a JWT token could
4256
only pass signature validation against the same pair of keys it was signed with. This is especially relevant in a production

core/messenger.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Many transports are supported to dispatch messages to async consumers, including
1212
To enable the support of Messenger, install the library:
1313

1414
```console
15-
docker compose exec php \
16-
composer require messenger
15+
composer require symfony/messenger
1716
```
1817

1918
## Dispatching a Resource through the Message Bus

core/mongodb.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the legacy [mongo](https://secure.php.net/manual/en/book.mongo.php) extension.
1818

1919
If the `mongodb` PHP extension is not installed yet, [install it beforehand](https://secure.php.net/manual/en/mongodb.installation.pecl.php).
2020

21-
If you are using the [API Platform Distribution](../symfony/index.md), modify the `Dockerfile` to add the extension:
21+
Or if you are using the [API Platform Distribution with Symfony](../symfony/index.md), modify the `Dockerfile` to add the extension:
2222

2323
```diff
2424
# api/Dockerfile
@@ -64,12 +64,11 @@ services:
6464
# ...
6565
```
6666

67-
Once the extension is installed, to enable the MongoDB support, require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
67+
In all cases, enable the MongoDB support by requiring the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
6868
package using Composer:
6969

7070
```console
71-
docker compose exec php \
72-
composer require doctrine/mongodb-odm-bundle
71+
composer require doctrine/mongodb-odm-bundle
7372
```
7473

7574
Execute the contrib recipe to have it already configured.

core/openapi.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,31 @@ You can also dump an OpenAPI specification for your API.
2020
OpenAPI, JSON format:
2121

2222
```console
23-
docker compose exec php \
24-
bin/console api:openapi:export
23+
bin/console api:openapi:export
2524
```
2625

2726
OpenAPI, YAML format:
2827

2928
```console
30-
docker compose exec php \
31-
bin/console api:openapi:export --yaml
29+
bin/console api:openapi:export --yaml
3230
```
3331

3432
Create a file containing the specification:
3533

3634
```console
37-
docker compose exec php \
38-
bin/console api:openapi:export --output=swagger_docs.json
35+
bin/console api:openapi:export --output=swagger_docs.json
3936
```
4037

4138
If you want to use the old OpenAPI v2 (Swagger) JSON format, use:
4239

4340
```console
44-
docker compose exec php \
45-
bin/console api:swagger:export
41+
bin/console api:swagger:export
4642
```
4743

4844
It is also possible to use OpenAPI v3.0.0 format:
4945

5046
```console
51-
docker compose exec php \
52-
bin/console api:openapi:export --spec-version=3.0.0
47+
bin/console api:openapi:export --spec-version=3.0.0
5348
```
5449

5550
## Overriding the OpenAPI Specification

core/testing.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Reuse them to run, for instance, SQL queries or requests to external APIs direct
1717
Install the `symfony/http-client` and `symfony/browser-kit` packages to enabled the API Platform test client:
1818

1919
```console
20-
docker compose exec php \
21-
composer require symfony/browser-kit symfony/http-client
20+
composer require symfony/browser-kit symfony/http-client
2221
```
2322

2423
To use the testing client, your test class must extend the `ApiTestCase` class:

0 commit comments

Comments
 (0)