Skip to content

Commit 9a85ce1

Browse files
authored
Merge pull request #1290 from alanpoulain/merge-2.6
Merge 2.6
2 parents b719db6 + 192fe7b commit 9a85ce1

Some content is hidden

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

75 files changed

+1647
-1168
lines changed

.github/workflows/cd.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy Website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '*.*'
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- name: Checkout the website
15+
uses: actions/checkout@v2
16+
with:
17+
repository: api-platform/website
18+
ref: main
19+
20+
- name: Get yarn cache directory path
21+
id: yarn-cache-dir-path
22+
run: echo "::set-output name=dir::$(yarn cache dir)"
23+
24+
- uses: actions/cache@v2
25+
id: yarn-cache
26+
with:
27+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
28+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-yarn-
31+
32+
- name: Install deps
33+
run: yarn install
34+
35+
- name: Retrieve docs
36+
run: bin/retrieve-documentation
37+
38+
- name: Build website
39+
env:
40+
GITHUB_KEY: ${{ secrets.CONTRIBUTORS_GITHUB_TOKEN }}
41+
run: yarn gatsby build
42+
43+
- name: Deploy
44+
uses: peaceiris/actions-gh-pages@v3
45+
with:
46+
github_token: ${{ secrets.GITHUB_TOKEN }}
47+
publish_dir: ./public
48+
cname: api-platform.com

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lint
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
name: Lint
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Lint
19+
uses: github/super-linter@v3
20+
env:
21+
VALIDATE_ALL_CODEBASE: false
22+
VALIDATE_EDITORCONFIG: false
23+
VALIDATE_JSCPD: false
24+
DEFAULT_BRANCH: 2.6
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- uses: actions/cache@v2
28+
with:
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
34+
- name: Install Proselint
35+
run: pip install --quiet --user proselint
36+
37+
- name: Run Proselint
38+
run: find . -name '*.md' -exec proselint {} \;

.markdownlint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MD013:
2+
line_length: 400
3+
no-inline-html:
4+
allowed_elements: [a, p, img, br]

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

admin/components.md

Lines changed: 71 additions & 53 deletions
Large diffs are not rendered by default.

admin/customizing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,4 @@ For instance, using an autocomplete input is straightforward, [checkout the dedi
185185
API Platform is built on top of [React Admin](https://marmelab.com/react-admin/).
186186
You can use all the features provided by the underlying library with API Platform Admin, including support for [file upload](https://marmelab.com/react-admin/DataProviders.html#decorating-your-data-provider-example-of-file-upload), [authentication](https://marmelab.com/react-admin/Authentication.html), [authorization](https://marmelab.com/react-admin/Authorization.html) and deeper customization.
187187

188-
To learn more about these capabilities, refer to [the React Admin documentation](https://marmelab.com/react-admin/).
188+
To learn more about these capabilities, refer to [the React Admin documentation](https://marmelab.com/react-admin/).

admin/file-upload.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
HydraAdmin,
1414
ResourceGuesser,
1515
CreateGuesser,
16-
InputGuesser
1716
} from "@api-platform/admin";
1817
import { FileField, FileInput } from "react-admin";
1918

admin/getting-started.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ Otherwise, all you need to install API Platform Admin is a JavaScript package ma
88

99
If you don't have an existing React Application, create one using [Create React App](https://create-react-app.dev/):
1010

11-
$ yarn create react-app my-admin
11+
```console
12+
yarn create react-app my-admin
13+
```
1214

1315
Go to the directory of your project:
1416

15-
$ cd my-admin
17+
```console
18+
cd my-admin
19+
```
1620

1721
Finally, install the `@api-platform/admin` library:
1822

19-
$ yarn add @api-platform/admin
23+
```console
24+
yarn add @api-platform/admin
25+
```
2026

2127
## Creating the Admin
2228

@@ -59,7 +65,10 @@ nelmio_cors:
5965
6066
Clear the cache to apply this change:
6167
62-
$ docker-compose exec php bin/console cache:clear --env=prod
68+
```console
69+
docker-compose exec php \
70+
bin/console cache:clear --env=prod
71+
```
6372

6473
Your new administration interface is ready! Type `yarn start` to try it!
6574

admin/images/required-field.png

2.08 KB
Loading
5.74 KB
Loading

admin/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ API Platform Admin is a tool to automatically create a beautiful and fully featu
66
for any API supporting [the Hydra Core Vocabulary](http://www.hydra-cg.com/) or other API specification formats supported by [`@api-platform/api-doc-parser`](https://github.com/api-platform/api-doc-parser) (experimental support for [OpenAPI](https://www.openapis.org/) is also available).
77

88
API Platform Admin is the perfect companion of APIs created
9-
using [the API Platform framework](https://api-platform.com), but also supports APIs written with any other programming language or framework as long as they expose a standard Hydra API documentation.
9+
using [the API Platform framework](https://api-platform.com), but also supports APIs written with any other programming language or framework as long as they expose a standard Hydra API documentation.
1010

1111
API Platform Admin is a 100% standalone Single-Page-Application with no coupling to the server part,
1212
according to the API-first paradigm.
1313

1414
API Platform Admin parses the API documentation then uses the awesome [React Admin](https://marmelab.com/react-admin/)
1515
library to expose a nice, responsive, management interface (Create-Retrieve-Update-Delete) for all documented resource types.
1616

17-
You can **customize everything** by using provided React Admin and [Material UI](https://material-ui.com/) components, or by writing your custom [React](https://reactjs.org/) components.
17+
You can **customize everything** by using provided React Admin and [Material UI](https://material-ui.com/) components, or by writing your custom [React](https://reactjs.org/) components.
1818

1919
## Features
2020

2121
* Automatically generates an admin interface for all the resources of the API thanks to hypermedia features of Hydra
2222
* Generates 'list', 'create', 'show', and 'edit' screens, as well as a delete button
2323
* Generates suitable inputs and fields according to the API doc (e.g. number HTML input for numbers, checkbox for booleans, selectbox for relationships...)
24-
* Generates suitable inputs and fields according to Schema.org types if available (e.g. email field for http://schema.org/email)
24+
* Generates suitable inputs and fields according to Schema.org types if available (e.g. email field for `http://schema.org/email`)
2525
* Handles relationships
2626
* Supports pagination
2727
* Supports filters and ordering

admin/validation.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Validation
2+
3+
API Platform Admin manages automatically two types of validation: client-side validation and server-side (or submission) validation.
4+
5+
## Client-side Validation
6+
7+
If the API documentation indicates that a field is mandatory,
8+
API Platform Admin will automatically add a [required client-side validation](https://marmelab.com/react-admin/CreateEdit.html#per-input-validation-built-in-field-validators).
9+
10+
For instance, with API Platform Core as backend, if you write the following:
11+
12+
```php
13+
<?php
14+
// api/src/Entity/Book.php
15+
16+
use ApiPlatform\Core\Annotation\ApiResource;
17+
use Symfony\Component\Validator\Constraints as Assert;
18+
19+
/**
20+
* @ApiResource
21+
*/
22+
class Book
23+
{
24+
/**
25+
* @Assert\NotBlank
26+
*/
27+
public ?string $title = null;
28+
}
29+
```
30+
31+
If you create a new book and touch the "Title" field without typing, you will see:
32+
33+
![Required title field](images/required-field.png)
34+
35+
## Server-side Validation
36+
37+
When the form is submitted and if submission errors are received,
38+
API Platform Admin will automatically show the errors for the corresponding fields.
39+
40+
To do so, it uses the [submission validation](https://marmelab.com/react-admin/CreateEdit.html#submission-validation) feature of React Admin,
41+
and the mapping between the response and the fields is done by the [schema analyzer](components.md#schemaanalyzer) with its method `getSubmissionErrors`.
42+
43+
API Platform Core is supported by default, but if you use another backend, you will need to override the `getSubmissionErrors` method.
44+
45+
For example if you have this code:
46+
47+
```php
48+
<?php
49+
// api/src/Entity/Book.php
50+
51+
use ApiPlatform\Core\Annotation\ApiResource;
52+
use Symfony\Component\Validator\Constraints as Assert;
53+
54+
/**
55+
* @ApiResource
56+
*/
57+
class Book
58+
{
59+
/**
60+
* @Assert\Isbn
61+
*/
62+
public ?string $isbn = null;
63+
}
64+
```
65+
66+
If you submit the form with an invalid ISBN, you will see:
67+
68+
![Submission error field](images/submission-error-field.png)

client-generator/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Client Generator is the fastest way to scaffold fully featured webapps and nativ
44

55
![Screencast](images/client-generator-demo.gif)
66

7-
*Generated React and React Native apps, updated in real time*
7+
## Generated React and React Native Apps, Updated in Real Time
88

99
It is able to generate apps using the following frontend stacks:
1010

client-generator/nextjs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Create a [Next.js application with express server](https://github.com/zeit/next.
1818

1919
Enable TypeScript in your next project
2020

21-
$ yarn add --dev typescript @types/react @types/node
21+
yarn add --dev typescript @types/react @types/node
2222

2323
Install required dependencies:
2424

25-
$ yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch
25+
yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch formik
2626

2727
## Generating Routes
2828

@@ -35,7 +35,7 @@ Install required dependencies:
3535

3636
You can launch the server with
3737

38-
$ yarn dev
38+
yarn dev
3939

4040
Go to `http://localhost:3000/books/` to start using your app.
4141

client-generator/nuxtjs.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ The Nuxt.js Client Generator generates components for Server Side Rendered appli
88

99
Create a [Nuxt.js application](https://nuxtjs.org/guides/get-started/installation#using-create-nuxt-app). The easiest way is to execute:
1010

11-
$ npx create-nuxt-app your-app-name
12-
# or
13-
$ yarn create nuxt-app your-app-name
11+
```console
12+
npx create-nuxt-app your-app-name
13+
```
1414

15-
It will ask you some questions you can use these answers :
15+
or:
1616

17+
```console
18+
yarn create nuxt-app your-app-name
1719
```
20+
21+
It will ask you some questions you can use these answers :
22+
23+
```console
1824
Project name: your-app-name
1925
Programming language: JavaScript
2026
Package manager: Yarn
@@ -30,8 +36,10 @@ Deployment target: Static (Static/JAMStack hosting)
3036

3137
Install required dependencies:
3238

33-
$ yarn add moment lodash vue-i18n vuelidate vuex-map-fields nuxt-i18n
34-
# yarn add --dev @nuxtjs/vuetify @nuxtjs/fontawesome
39+
```console
40+
yarn add moment lodash vue-i18n vuelidate vuex-map-fields nuxt-i18n
41+
yarn add --dev @nuxtjs/vuetify @nuxtjs/fontawesome
42+
```
3543

3644
## Updating nuxtjs config
3745

@@ -48,19 +56,22 @@ Update your `nuxt.config.js` with following:
4856
// to avoid name conflicts in generators
4957
components: false,
5058
```
59+
5160
## Generating Routes
5261

53-
$ npx @api-platform/client-generator https://demo.api-platform.com . --generator nuxt
54-
# Replace the URL by the entrypoint of your Hydra-enabled API
62+
```console
63+
npx @api-platform/client-generator https://demo.api-platform.com . --generator nuxt
64+
```
5565

56-
> Note: Omit the resource flag to generate files for all resource types exposed by the API.
66+
Replace the URL by the entrypoint of your Hydra-enabled API
5767

58-
## Updating default layout
68+
**Note:** Omit the resource flag to generate files for all resource types exposed by the API.
5969

70+
## Updating default layout
6071

6172
Update your `layouts/default.vue` with following:
6273

63-
```javascript
74+
```vue
6475
<template>
6576
<v-app>
6677
<alert />
@@ -132,9 +143,11 @@ export default {
132143

133144
## Starting the Project
134145

135-
You can launch the server with
146+
You can launch the server with:
136147

137-
$ yarn dev
148+
```console
149+
yarn dev
150+
````
138151

139152
Go to `https://localhost:3000/books/` to start using your app.
140153

0 commit comments

Comments
 (0)