Skip to content

Commit

Permalink
feat: support specifying APISIX path to generate json schema (#765)
Browse files Browse the repository at this point in the history
* feat: support specifying APISIX path to generate json schema

* doc: update doc about schema sync

* fix: doc

* fix: errors

* fix: error according to test

* test

* no message

* test

* fix: remove debug
  • Loading branch information
nic-chen authored Nov 10, 2020
1 parent 9d4b371 commit 63977d9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy-with-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ jobs:
run: |
docker tag dashboard:ci apisixacr.azurecr.cn/dashboard:${{ github.sha }}
docker push apisixacr.azurecr.cn/dashboard:${{ github.sha }}
5 changes: 4 additions & 1 deletion api/build-tools/schema-sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local fake_module_list = {
'pb',
'prometheus',
'protoc',
'skywalking.tracer',

'resty.cookie',
'resty.core.regex',
Expand Down Expand Up @@ -61,7 +62,8 @@ local fake_module_list = {
'apisix.plugins.skywalking.tracer',
'apisix.plugins.zipkin.codec',
'apisix.plugins.zipkin.random_sampler',
'apisix.plugins.zipkin.reporter'
'apisix.plugins.zipkin.reporter',
'apisix.timers'
}
for _, name in ipairs(fake_module_list) do
package.loaded[name] = {}
Expand All @@ -77,6 +79,7 @@ ngx.re = {}
ngx.timer = {}
ngx.location = {}
ngx.socket = {}
ngx.thread = {}
ngx.re.gmatch = empty_function
ngx.shared = {
["plugin-api-breaker"] = {}
Expand Down
30 changes: 20 additions & 10 deletions api/build-tools/schema-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,29 @@ set -ex

pwd=`pwd`

version="master"
if [[ -n $1 ]]; then
version=$1
if [[ -n $1 && -d "$1" ]]; then
path=$1
if [[ -d "${path}/apisix" ]]; then
cp -R ${path}/apisix/ ./api/build-tools/apisix/
else
cp -R ${path}/ ./api/build-tools/apisix/
fi
else
version="master"
if [[ -n $1 ]]; then
version=$1
fi
wget -O $version.zip https://github.com/apache/apisix/archive/$version.zip

unzip $version.zip
mkdir -p ./api/build-tools/apisix/
cp -R ./apisix-$version/apisix/ ./api/build-tools/
rm -rf ./apisix-$version
fi

rm -rf ./api/build-tools/apisix/
wget -O $version.zip https://github.com/apache/apisix/archive/$version.zip
cd ./api/build-tools/ && lua schema-sync.lua > ${pwd}/api/conf/schema.json && cd ../../

unzip $version.zip
mkdir -p ./api/build-tools/apisix/
mv ./apisix-$version/apisix/* ./api/build-tools/apisix/
rm -rf ./apisix-$version
cd ./api/build-tools/ && lua schema-sync.lua > ${pwd}/api/conf/schema.json
rm -rf ./api/build-tools/apisix/

echo "sync success:"
echo "${pwd}/api/conf/schema.json"
12 changes: 11 additions & 1 deletion docs/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ $ make api-stop

### Sync jsonschema

To sync jsonschema from Apache APISIX, `Lua` 5.1+ and `zip` need to be preinstalled, then execute this command: `api/build-tools/schema-sync.sh $version`.
To sync jsonschema from Apache APISIX, `Lua` 5.1+ and `zip` need to be preinstalled, then execute this command:

```sh
$ api/build-tools/schema-sync.sh $version
```

NOTE: `$version` should be `master` or Apache APISIX's version.

Expand All @@ -100,3 +104,9 @@ $ api/build-tools/schema-sync.sh master
# Using Apache APISIX's version
$ api/build-tools/schema-sync.sh 2.0
```

If you have custom plugin, please make sure your custom plugin is placed in the APISIX directory, and change the parameters of the execution script to the APISIX directory path, example:

```sh
$ api/build-tools/schema-sync.sh /usr/local/apisix
```
11 changes: 10 additions & 1 deletion docs/develop.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ $ make api-stop

### 同步 jsonschema

从 Apache APISIX 同步 jsonschema ,需要预安装 `Lua` 5.1+ 和 `zip` ,并执行命令 `api/build-tools/schema-sync.sh $version`
从 Apache APISIX 同步 jsonschema ,需要预安装 `Lua` 5.1+ 和 `zip` ,并执行命令

```sh
$ api/build-tools/schema-sync.sh $version
```

注意:`$version``master` 或者 Apache APISIX 的版本号。

Expand All @@ -103,3 +107,8 @@ $ api/build-tools/schema-sync.sh master
$ api/build-tools/schema-sync.sh 2.0
```

如果您有自定义插件,请确保您的自定义插件放在 APISIX 目录中,并将执行脚本的参数改为 APISIX 目录路径, 如:

```sh
$ api/build-tools/schema-sync.sh /usr/local/apisix
```

0 comments on commit 63977d9

Please sign in to comment.