diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-14 14:14:14 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-14 14:14:14 +0100 |
commit | 7b62b1d5f012ace46c8651b98efeb5be9f35455e (patch) | |
tree | 58729dae12b53c0f368212ce334826b8093c6f4a | |
parent | 68ca61941e3a7ca4c018566d2c496afd27dbd76d (diff) | |
parent | 002df3813d13c5accd36d7943af2b17376a6d1ac (diff) | |
download | PeerTube-7b62b1d5f012ace46c8651b98efeb5be9f35455e.tar.gz PeerTube-7b62b1d5f012ace46c8651b98efeb5be9f35455e.tar.zst PeerTube-7b62b1d5f012ace46c8651b98efeb5be9f35455e.zip |
OpenAPI clients generation
See merge request framasoft/peertube/PeerTube!28, which continued https://github.com/Chocobozzz/PeerTube/pull/2060
-rw-r--r-- | .gitlab-ci.yml | 16 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | scripts/openapi-clients.sh | 81 | ||||
-rwxr-xr-x | scripts/openapi-peertube-version.sh | 5 | ||||
-rw-r--r-- | support/doc/api/openapi.yaml | 3 | ||||
-rw-r--r-- | support/openapi/go.yaml | 3 | ||||
-rw-r--r-- | support/openapi/kotlin.yaml | 6 | ||||
-rw-r--r-- | support/openapi/python.yaml | 5 | ||||
-rw-r--r-- | yarn.lock | 5 |
9 files changed, 126 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9c1898f3..0b7332e0b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml | |||
@@ -4,6 +4,7 @@ stages: | |||
4 | - build-and-lint | 4 | - build-and-lint |
5 | - test | 5 | - test |
6 | - docker-nightly | 6 | - docker-nightly |
7 | - clients | ||
7 | 8 | ||
8 | #before_script: | 9 | #before_script: |
9 | # - 'sed -i -z "s/database:\n hostname: ''localhost''/database:\n hostname: ''postgres''/" config/test.yaml' | 10 | # - 'sed -i -z "s/database:\n hostname: ''localhost''/database:\n hostname: ''postgres''/" config/test.yaml' |
@@ -84,6 +85,21 @@ cache: | |||
84 | # script: | 85 | # script: |
85 | # - NODE_PENDING_JOB_WAIT=1000 npm run ci -- api-$CI_NODE_INDEX | 86 | # - NODE_PENDING_JOB_WAIT=1000 npm run ci -- api-$CI_NODE_INDEX |
86 | 87 | ||
88 | build-openapi-clients: | ||
89 | stage: clients | ||
90 | only: | ||
91 | refs: | ||
92 | - master | ||
93 | - schedules | ||
94 | changes: | ||
95 | - support/doc/api/openapi.yaml | ||
96 | script: | ||
97 | - apt-get update -qq | ||
98 | - apt-get -yqqq install openjdk-8-jre | ||
99 | - yarn install --pure-lockfile | ||
100 | - scripts/openapi-peertube-version.sh | ||
101 | - scripts/openapi-clients.sh | ||
102 | |||
87 | build-nightly: | 103 | build-nightly: |
88 | stage: docker-nightly | 104 | stage: docker-nightly |
89 | only: | 105 | only: |
diff --git a/package.json b/package.json index da8ee7897..3311f7add 100644 --- a/package.json +++ b/package.json | |||
@@ -73,6 +73,7 @@ | |||
73 | "release": "scripty", | 73 | "release": "scripty", |
74 | "release-embed-api": "scripty", | 74 | "release-embed-api": "scripty", |
75 | "nightly": "scripty", | 75 | "nightly": "scripty", |
76 | "openapi-clients": "scripty", | ||
76 | "client-report": "scripty", | 77 | "client-report": "scripty", |
77 | "swagger-cli": "swagger-cli", | 78 | "swagger-cli": "swagger-cli", |
78 | "sass-lint": "sass-lint" | 79 | "sass-lint": "sass-lint" |
@@ -142,6 +143,7 @@ | |||
142 | "youtube-dl": "^3.0.2" | 143 | "youtube-dl": "^3.0.2" |
143 | }, | 144 | }, |
144 | "devDependencies": { | 145 | "devDependencies": { |
146 | "@openapitools/openapi-generator-cli": "^1.0.10-4.2.3", | ||
145 | "@types/apicache": "^1.2.0", | 147 | "@types/apicache": "^1.2.0", |
146 | "@types/async": "^3.0.0", | 148 | "@types/async": "^3.0.0", |
147 | "@types/async-lock": "^1.1.0", | 149 | "@types/async-lock": "^1.1.0", |
diff --git a/scripts/openapi-clients.sh b/scripts/openapi-clients.sh new file mode 100755 index 000000000..b031ceac1 --- /dev/null +++ b/scripts/openapi-clients.sh | |||
@@ -0,0 +1,81 @@ | |||
1 | #!/bin/bash | ||
2 | # Required environment vars | ||
3 | # ========================= | ||
4 | # API_LANGS | ||
5 | # A ':' delimited list of the client lib languages to be generated | ||
6 | # API_GIT_USER | ||
7 | # The user that will be used to push/pull from the APIs repos | ||
8 | # API_GIT_EMAIL | ||
9 | # The git email | ||
10 | # GIT_TOKEN | ||
11 | # A personal access token for github or gilab for pushing to repos | ||
12 | # !!!This is a secret and shouldn't be logged publicly!!! | ||
13 | |||
14 | # (Optional environment vars) | ||
15 | # =========================== | ||
16 | # API_COMMIT_MSG | ||
17 | # A message to use when committing to the lib repo | ||
18 | # API_PATH_PREFIX | ||
19 | # Will be used for building the URL to the repo and path to checkout. | ||
20 | # !!! End with a slash "/", otherwise the prefix will be tacked onto the language | ||
21 | # API_URL_USERNAME | ||
22 | # The username to use building the URL to the git repo. | ||
23 | # Default: API_GIT_USER | ||
24 | # API_REPO_HOST | ||
25 | # Whoever's hosting the repo e.g gitlab.com, github.com, etc. | ||
26 | # Default: framagit.org | ||
27 | |||
28 | # Unofficial bash strict mode | ||
29 | # https://web.archive.org/web/20190115051613/https://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
30 | set -euo pipefail | ||
31 | IFS=$'\n\t ' | ||
32 | |||
33 | # Set default values | ||
34 | API_URL_USERNAME="${API_URL_USERNAME:-$API_GIT_USER}" | ||
35 | API_PATH_PREFIX="${API_PATH_PREFIX:-}" | ||
36 | API_REPO_HOST=${API_REPO_HOST:-framagit.org} | ||
37 | |||
38 | echo "API_GIT_USER='${API_GIT_USER}'" | ||
39 | echo "API_URL_USERNAME='${API_URL_USERNAME}'" | ||
40 | echo "API_LANGS='${API_LANGS}'" | ||
41 | |||
42 | git config --global user.email "${API_GIT_EMAIL}" | ||
43 | git config --global user.name "${API_GIT_USER}" | ||
44 | |||
45 | for lang in ${API_LANGS//:/ } ; do | ||
46 | ( | ||
47 | echo "Generating client API libs for $lang" | ||
48 | |||
49 | out_dir_prefix="dist/api/${API_PATH_PREFIX}" | ||
50 | out_dir="${out_dir_prefix}/${lang}" | ||
51 | git_repo_id="${API_PATH_PREFIX}${lang}" | ||
52 | host_path="${API_REPO_HOST}/${API_URL_USERNAME}/${git_repo_id}.git" | ||
53 | git_remote="https://${API_GIT_USER}:${GIT_TOKEN}@${host_path}" | ||
54 | if ! [ -e "$out_dir" ] ; then | ||
55 | # Make sure the prefix exists before cloning the repo | ||
56 | mkdir -p "${out_dir_prefix}" | ||
57 | git clone "https://${host_path}" "$out_dir" | ||
58 | fi | ||
59 | |||
60 | npx openapi-generator generate \ | ||
61 | -i support/doc/api/openapi.yaml \ | ||
62 | -c "support/openapi/${lang}.yaml" \ | ||
63 | -g "$lang" \ | ||
64 | --git-host "${API_REPO_HOST}" \ | ||
65 | --git-user-id "${API_URL_USERNAME}" \ | ||
66 | --git-repo-id "${git_repo_id}" \ | ||
67 | -o "${out_dir}" | ||
68 | |||
69 | # Commit and push changes to the remote | ||
70 | cd "$out_dir" | ||
71 | git remote set-url origin "$git_remote" | ||
72 | # Make sure something has changed | ||
73 | if [[ $(git status -s | wc -l) = 0 ]] ; then | ||
74 | echo "No changes from previous version" | ||
75 | continue | ||
76 | fi | ||
77 | git add . | ||
78 | git commit -m "${API_COMMIT_MSG:-"Minor update $lang"}" | ||
79 | git push | ||
80 | ) | ||
81 | done | ||
diff --git a/scripts/openapi-peertube-version.sh b/scripts/openapi-peertube-version.sh index 4eb481e64..49154a5f3 100755 --- a/scripts/openapi-peertube-version.sh +++ b/scripts/openapi-peertube-version.sh | |||
@@ -4,3 +4,8 @@ | |||
4 | PACKAGE_VERSION=$(node -p "require('./package.json').version") | 4 | PACKAGE_VERSION=$(node -p "require('./package.json').version") |
5 | 5 | ||
6 | sed -i "s/\(^\s*\)version: .*/\1version: $PACKAGE_VERSION/" ./support/doc/api/openapi.yaml | 6 | sed -i "s/\(^\s*\)version: .*/\1version: $PACKAGE_VERSION/" ./support/doc/api/openapi.yaml |
7 | |||
8 | # Sets the package version for libs | ||
9 | echo "packageVersion: $PACKAGE_VERSION" >> ./support/openapi/go.yaml | ||
10 | echo "artifactVersion: $PACKAGE_VERSION" >> ./support/openapi/kotlin.yaml | ||
11 | echo "packageVersion: $PACKAGE_VERSION" >> ./support/openapi/python.yaml | ||
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index b1e5f90f8..180f65bcf 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml | |||
@@ -13,6 +13,7 @@ info: | |||
13 | altText: PeerTube Project Homepage | 13 | altText: PeerTube Project Homepage |
14 | description: | | 14 | description: | |
15 | # Introduction | 15 | # Introduction |
16 | |||
16 | The PeerTube API is built on HTTP(S). Our API is RESTful. It has predictable | 17 | The PeerTube API is built on HTTP(S). Our API is RESTful. It has predictable |
17 | resource URLs. It returns HTTP response codes to indicate errors. It also | 18 | resource URLs. It returns HTTP response codes to indicate errors. It also |
18 | accepts and returns JSON in the HTTP body. You can use your favorite | 19 | accepts and returns JSON in the HTTP body. You can use your favorite |
@@ -22,11 +23,13 @@ info: | |||
22 | which generates a client SDK in the language of your choice. | 23 | which generates a client SDK in the language of your choice. |
23 | 24 | ||
24 | # Authentication | 25 | # Authentication |
26 | |||
25 | When you sign up for an account, you are given the possibility to generate | 27 | When you sign up for an account, you are given the possibility to generate |
26 | sessions, and authenticate using this session token. One session token can | 28 | sessions, and authenticate using this session token. One session token can |
27 | currently be used at a time. | 29 | currently be used at a time. |
28 | 30 | ||
29 | # Errors | 31 | # Errors |
32 | |||
30 | The API uses standard HTTP status codes to indicate the success or failure | 33 | The API uses standard HTTP status codes to indicate the success or failure |
31 | of the API call. The body of the response will be JSON in the following | 34 | of the API call. The body of the response will be JSON in the following |
32 | format. | 35 | format. |
diff --git a/support/openapi/go.yaml b/support/openapi/go.yaml new file mode 100644 index 000000000..7136da912 --- /dev/null +++ b/support/openapi/go.yaml | |||
@@ -0,0 +1,3 @@ | |||
1 | # https://openapi-generator.tech/docs/generators/go | ||
2 | |||
3 | packageName: peertube | ||
diff --git a/support/openapi/kotlin.yaml b/support/openapi/kotlin.yaml new file mode 100644 index 000000000..7a01ae6e5 --- /dev/null +++ b/support/openapi/kotlin.yaml | |||
@@ -0,0 +1,6 @@ | |||
1 | # https://openapi-generator.tech/docs/generators/kotlin | ||
2 | |||
3 | artifactId: peertube-api | ||
4 | groupId: org.peertube | ||
5 | packageName: org.peertube.client | ||
6 | |||
diff --git a/support/openapi/python.yaml b/support/openapi/python.yaml new file mode 100644 index 000000000..819a466eb --- /dev/null +++ b/support/openapi/python.yaml | |||
@@ -0,0 +1,5 @@ | |||
1 | # https://openapi-generator.tech/docs/generators/python | ||
2 | |||
3 | packageName: peertube | ||
4 | projectName: peertube | ||
5 | |||
@@ -18,6 +18,11 @@ | |||
18 | esutils "^2.0.2" | 18 | esutils "^2.0.2" |
19 | js-tokens "^4.0.0" | 19 | js-tokens "^4.0.0" |
20 | 20 | ||
21 | "@openapitools/openapi-generator-cli@^1.0.10-4.2.3": | ||
22 | version "1.0.10-4.2.3" | ||
23 | resolved "https://registry.yarnpkg.com/@openapitools/openapi-generator-cli/-/openapi-generator-cli-1.0.10-4.2.3.tgz#4b934362efb9262fc236d4fb81b381e29bdb8245" | ||
24 | integrity sha512-Xo4rbz3aPiObpVS8oBUR0pHWYU5WBG/bmsJg16yCG7/vpGE8o1YsROTWMFfaMepWfxESrLP5XOqlBkZqbre7dw== | ||
25 | |||
21 | "@types/apicache@^1.2.0": | 26 | "@types/apicache@^1.2.0": |
22 | version "1.2.2" | 27 | version "1.2.2" |
23 | resolved "https://registry.yarnpkg.com/@types/apicache/-/apicache-1.2.2.tgz#b820659b1d95e66ec0e71dcd0317e9d30f0c154b" | 28 | resolved "https://registry.yarnpkg.com/@types/apicache/-/apicache-1.2.2.tgz#b820659b1d95e66ec0e71dcd0317e9d30f0c154b" |