Skip to content

Commit e44809f

Browse files
committed
Update API Refs
1 parent 0c5a211 commit e44809f

File tree

5 files changed

+120
-26
lines changed

5 files changed

+120
-26
lines changed

tools/api_refs/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ Requires [`jq`](https://stedolan.github.io/jq/download/)
66

77
## Basic usage
88

9-
`tools/php_api_ref/phpdoc.sh` is a script generating PHP API Reference, by default, under `docs/api/php_api/php_api_reference/`.
9+
`tools/api_refs/api_refs.sh` is a script generating PHP API Reference, by default, under `docs/api/php_api/php_api_reference/`.
1010

1111
- For Composer, if you do not use a global authentication to retrieve _Commerce_ edition, a path to an auth.json file can be given as first argument. For example:
1212
```
13-
tools/php_api_ref/phpdoc.sh ~/www/ibexa-dxp-commerce/auth.json
13+
tools/api_refs/api_refs.sh ~/www/ibexa-dxp-commerce/auth.json
1414
```
1515
- The second argument can be a path to an output directory to use instead of the default one. For example, using the Composer global authentication file as first argument and the path to directory (which is created if it doesn't exist yet):
1616
```
17-
tools/php_api_ref/phpdoc.sh ~/.composer/auth.json ./docs/api/php_api/php_api_reference-TMP
17+
tools/api_refs/api_refs.sh ~/.composer/auth.json ./docs/api/php_api/php_api_reference-TMP
1818
```
1919

2020
## Rebuild example
2121

2222
```bash
23-
tools/php_api_ref/phpdoc.sh
23+
tools/api_refs/api_refs.sh
2424
git add docs/api/php_api/php_api_reference/
2525
git commit -m "Rebuild PHP API Ref's HTML"
2626
git push
2727
```
2828

2929
## Maintenance
3030

31-
In `tools/php_api_ref/phpdoc.sh`:
31+
In `tools/api_refs/api_refs.sh`:
3232

3333
`PHPDOC_VERSION` should always target the last version of phpDocumentor.
3434

3535
`DXP_VERSION` should target the version of Ibexa DXP Commerce corresponding to the main doc's branch.
3636

3737
### Templates
3838

39-
Custom templates are located in `tools/php_api_ref/.phpdoc/template/` directory.
39+
Custom templates are located in `tools/api_refs/.phpdoc/template/` directory.
4040
They are overriding the default templates from a phpDocumentor version.
4141
The default templates version is not always the same as the phpDocumentor binary version.
4242
To update the default templates version, the overriding custom templates must be updated as well to obtain a better or equal result without bug.
4343
See `PHPDOC_VERSION` and `PHPDOC_TEMPLATE_VERSION`.
4444

4545
## Advanced usage
4646

47-
`tools/php_api_ref/phpdoc.sh` has a set of internal variables that might be edited for particular usages.
47+
`tools/api_refs/api_refs.sh` has a set of internal variables that might be edited for particular usages.
4848

4949
`PHPDOC_CONF` can be changed to use a different config file.
5050
For example, when working on the design, the set of parsed files can be reduced for a quicker PHP API Reference compilation.
@@ -58,16 +58,16 @@ Time is saved. The DXP's code could even be modified for test purpose.
5858
If you change some of those values, please do not commit those changes, and don't commit their output.
5959
To prevent that, you can make a local copy, and use this copy to generate in a temporary output directory:
6060
```shell
61-
cp tools/php_api_ref/phpdoc.sh tools/php_api_ref/phpdoc.dev.sh
61+
cp tools/api_refs/api_refs.sh tools/api_refs/phpdoc.dev.sh
6262
nano phpdoc.dev.sh # Edit and make your changes. For example, change PHPDOC_CONF to use phpdoc.dev.xml.
6363
nano phpdoc.dev.xml # Edit and make your changes. For example, target only your package.
64-
tools/php_api_ref/phpdoc.sh ~/.composer/auth.json ./docs/api/php_api/php_api_reference-TMP
64+
tools/api_refs/api_refs.sh ~/.composer/auth.json ./docs/api/php_api/php_api_reference-TMP
6565
```
6666

6767
### Test a branch
6868

6969
To load a package on a development branch instead of a released version,
70-
uncommented in `phpdoc.sh` the piece of code about `MY_PACKAGE` and `MY_BRANCH`,
70+
uncommented in `api_refs.sh` the piece of code about `MY_PACKAGE` and `MY_BRANCH`,
7171
and set the value of those two variables.
7272

7373
`MY_PACKAGE` is the name of the Ibexa package without the vendor.

tools/api_refs/api_refs.sh

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,40 @@
33
set +x;
44

55
AUTH_JSON=${1:-~/.composer/auth.json}; # Path to an auth.json file allowing to install the targeted edition and version
6-
OUTPUT_DIR=${2:-./docs/api/php_api/php_api_reference}; # Path to the directory where the built PHP API Reference is hosted
6+
PHP_API_OUTPUT_DIR=${2:-./docs/api/php_api/php_api_reference}; # Path to the directory where the built PHP API Reference is hosted
7+
REST_API_OUTPUT_FILE=${3:-./docs/api/rest_api/rest_api_reference/rest_api_reference.html}; # Path to the REST API Reference file
78

89
DXP_EDITION='commerce'; # Edition from and for which the Reference is built
9-
DXP_VERSION='5.0.x-dev'; # Version from and for which the Reference is built
10+
DXP_VERSION='5.0.0-rc1'; # Version from and for which the Reference is built
1011
DXP_ADD_ONS=(automated-translation rector); # Packages not included in $DXP_EDITION but added to the Reference, listed without their vendor "ibexa"
1112
DXP_EDITIONS=(oss headless experience commerce); # Available editions ordered by ascending capabilities
1213
SF_VERSION='7.2'; # Symfony version used by Ibexa DXP
1314
PHPDOC_VERSION='3.8.0'; # Version of phpDocumentor used to build the Reference
14-
PHPDOC_CONF="$(pwd)/tools/php_api_ref/phpdoc.dist.xml"; # Absolute path to phpDocumentor configuration file
15-
#PHPDOC_CONF="$(pwd)/tools/php_api_ref/phpdoc.dev.xml"; # Absolute path to phpDocumentor configuration file
15+
PHPDOC_CONF="$(pwd)/tools/api_refs/phpdoc.dist.xml"; # Absolute path to phpDocumentor configuration file
16+
#PHPDOC_CONF="$(pwd)/tools/api_refs/phpdoc.dev.xml"; # Absolute path to phpDocumentor configuration file
1617
PHPDOC_TEMPLATE_VERSION='3.8.0'; # Version of the phpDocumentor base template set
17-
PHPDOC_DIR="$(pwd)/tools/php_api_ref/.phpdoc"; # Absolute path to phpDocumentor resource directory (containing the override template set)
18+
PHPDOC_DIR="$(pwd)/tools/api_refs/.phpdoc"; # Absolute path to phpDocumentor resource directory (containing the override template set)
19+
REDOCLY_CONFIG="$(pwd)/tools/api_refs/redocly.yaml"; # Absolute path to Redocly configuration file
20+
REDOCLY_TEMPLATE="$(pwd)/tools/api_refs/redocly.hbs"; # Absolute path to Redocly wrapping template
21+
OPENAPI_FIX="$(pwd)/tools/api_refs/openapi.php"; # A script editing and fixing few things on the dumped schema (should be temporary and fixes reported to source)
1822

1923
PHP_BINARY="php -d error_reporting=`php -r 'echo E_ALL & ~E_DEPRECATED;'`"; # Avoid depreciation messages from phpDocumentor/Reflection/issues/529 when using PHP 8.2 or higher
2024
TMP_DXP_DIR=/tmp/ibexa-dxp-phpdoc; # Absolute path of the temporary directory in which Ibexa DXP will be installed and the PHP API Reference built
2125
FORCE_DXP_INSTALL=1; # If 1, empty the temporary directory, install DXP from scratch, build, remove temporary directory; if 0, potentially reuse the DXP already installed in temporary directory, keep temporary directory for future uses.
22-
BASE_DXP_BRANCH='master'; # Branch from and for which the Reference is built when using a dev branch as version
23-
VIRTUAL_DXP_VERSION='5.0.0'; # Version for which the reference is supposedly built when using dev branch as version
26+
BASE_DXP_BRANCH=''; # Branch from and for which the Reference is built when using a dev branch as version
27+
VIRTUAL_DXP_VERSION=''; # Version for which the reference is supposedly built when using dev branch as version
2428

25-
if [ ! -d $OUTPUT_DIR ]; then
26-
echo -n "Creating ${OUTPUT_DIR}";
27-
mkdir -p $OUTPUT_DIR;
29+
if [ ! -d $PHP_API_OUTPUT_DIR ]; then
30+
echo -n "Creating ${PHP_API_OUTPUT_DIR}";
31+
mkdir -p $PHP_API_OUTPUT_DIR;
2832
if [ $? -eq 0 ]; then
2933
echo 'OK';
3034
else
3135
exit 1;
3236
fi;
3337
fi;
34-
OUTPUT_DIR=$(realpath $OUTPUT_DIR); # Transform to absolute path before changing the working directory
38+
PHP_API_OUTPUT_DIR=$(realpath $PHP_API_OUTPUT_DIR); # Transform into absolute path before changing the working directory
39+
REST_API_OUTPUT_FILE=$(realpath $REST_API_OUTPUT_FILE); # Transform into absolute path before changing the working directory
3540

3641
if [ 1 -eq $FORCE_DXP_INSTALL ]; then
3742
echo 'Remove temporary directory…';
@@ -59,6 +64,13 @@ if [ 0 -eq $DXP_ALREADY_EXISTS ]; then
5964
fi;
6065
composer config repositories.ibexa composer https://updates.ibexa.co;
6166
composer require ibexa/$DXP_EDITION:$DXP_VERSION --no-interaction --update-with-all-dependencies --no-install --ignore-platform-reqs --no-scripts;
67+
elif [[ "$DXP_VERSION" == *"-rc"* ]]; then
68+
composer create-project ibexa/website-skeleton:$DXP_VERSION . --no-interaction --ignore-platform-reqs --no-scripts --stability=rc;
69+
if [ -n "$AUTH_JSON" ]; then
70+
cp $AUTH_JSON ./;
71+
fi;
72+
composer config repositories.ibexa composer https://updates.ibexa.co;
73+
composer require ibexa/$DXP_EDITION:$DXP_VERSION --no-interaction --update-with-all-dependencies --no-install --ignore-platform-reqs --no-scripts;
6274
else
6375
composer create-project ibexa/$DXP_EDITION-skeleton:$DXP_VERSION . --no-interaction --no-install --ignore-platform-reqs --no-scripts;
6476
if [ -n "$AUTH_JSON" ]; then
@@ -179,21 +191,36 @@ if [ $? -eq 0 ]; then
179191
./php_api_reference/js/searchIndex.js \
180192
> ./php_api_reference/js/searchIndex.new.js;
181193
mv -f ./php_api_reference/js/searchIndex.new.js ./php_api_reference/js/searchIndex.js;
182-
echo -n "Copy phpDocumentor output to ${OUTPUT_DIR}";
183-
cp -rf ./php_api_reference/* $OUTPUT_DIR;
194+
echo -n "Copy phpDocumentor output to ${PHP_API_OUTPUT_DIR}";
195+
cp -rf ./php_api_reference/* $PHP_API_OUTPUT_DIR;
184196
echo -n 'Remove surplus… ';
185197
while IFS= read -r line; do
186198
file="$(echo $line | sed -r 's/Only in (.*): (.*)/\1\/\2/')";
187-
if [[ $file = $OUTPUT_DIR/* ]]; then
199+
if [[ $file = $PHP_API_OUTPUT_DIR/* ]]; then
188200
rm -rf $file;
189201
fi;
190-
done <<< "$(diff -qr ./php_api_reference $OUTPUT_DIR | grep 'Only in ')";
202+
done <<< "$(diff -qr ./php_api_reference $PHP_API_OUTPUT_DIR | grep 'Only in ')";
191203
echo 'OK.';
192204
else
193-
echo 'A phpDocumentor error prevents reference update.';
205+
echo 'A phpDocumentor error prevents PHP Reference update.';
194206
exit 3;
195207
fi;
196208

209+
if [ 0 -eq $DXP_ALREADY_EXISTS ]; then
210+
echo 'Set up DXP recipes…';
211+
git init && git add . && git commit -m "Installed Ibexa Commerce" > /dev/null;
212+
composer recipes:install ibexa/$DXP_EDITION --force --reset --no-interaction;
213+
fi;
214+
215+
echo 'Dump REST OpenAPI schema… ';
216+
$PHP_BINARY bin/console ibexa:openapi --yaml \
217+
| sed "s@info:@info:\n x-logo:\n url: 'https://doc.ibexa.co/en/latest/images/ibexa-dxp-logo.png'@" \
218+
> openapi.yaml;
219+
echo 'Fix REST OpenAPI schema… ';
220+
$PHP_BINARY $OPENAPI_FIX;
221+
echo 'Build REST Reference… ';
222+
redocly build-docs openapi.yaml --output $REST_API_OUTPUT_FILE --config $REDOCLY_CONFIG --template $REDOCLY_TEMPLATE;
223+
197224
if [ 1 -eq $FORCE_DXP_INSTALL ]; then
198225
echo 'Remove temporary directory…';
199226
rm -rf $TMP_DXP_DIR;

tools/api_refs/openapi.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$openApi = yaml_parse_file('openapi.yaml');
4+
5+
foreach ($openApi['paths'] as $path => &$pathMethods) {
6+
foreach ($pathMethods as $method => &$methodDefinition) {
7+
if (array_key_exists('requestBody', $methodDefinition) && array_key_exists('content', $methodDefinition['requestBody'])) {
8+
//foreach ($methodDefinition['requestBody']['content'] as $contentType => &$contentDefinition) {}
9+
ksort($methodDefinition['requestBody']['content']);
10+
}/* */elseif (array_key_exists('requestBody', $methodDefinition)) {
11+
echo "$method $path\n";
12+
}/**/
13+
foreach ($methodDefinition['responses'] as $responseCode => &$responseDefinition) {
14+
if (array_key_exists('content', $responseDefinition)) {
15+
//foreach ($responseDefinition['content'] as $contentType => &$contentDefinition) {}
16+
ksort($responseDefinition['content']);
17+
}/* * /else {
18+
echo "$method $path: $responseCode\n";
19+
}/**/
20+
}
21+
}
22+
}
23+
24+
yaml_emit_file('openapi.yaml', $openApi);

tools/api_refs/redocly.hbs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf8" />
6+
<title>{{title}}</title>
7+
<!-- needed for adaptive design -->
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="icon" href="https://doc.ibexa.co/en/latest/images/favicon.png" />
10+
<style>
11+
body {
12+
padding: 0;
13+
margin: 0;
14+
}
15+
</style>
16+
{{{redocHead}}}
17+
{{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
18+
</head>
19+
20+
<body>
21+
{{{redocHTML}}}
22+
<script>
23+
window.addEventListener('load', () => {
24+
window.setTimeout(() => {
25+
let logo = document.querySelector('img[src$="ibexa-dxp-logo.png"]');
26+
logo.onclick = () => {
27+
let pathParts = document.location.pathname.split('/').slice(0, 3);
28+
document.location = pathParts.join('/') + '/api/rest_api/rest_api_usage/rest_api_usage/';
29+
};
30+
logo.setAttribute('style', 'cursor: pointer; margin: 13px;');
31+
}, 500);
32+
});
33+
</script>
34+
</body>
35+
36+
</html>

tools/api_refs/redocly.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
theme:
2+
openapi:
3+
hideHostname: true
4+
theme:
5+
logo:
6+
maxWidth: '76px!important'
7+
maxHeight: '26px'

0 commit comments

Comments
 (0)