Skip to content

Commit 0c2bd2f

Browse files
authored
use openapi-generator-cli instead of swagger-codegen (#30)
see: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/qna.md
1 parent d0e5247 commit 0c2bd2f

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ Python library for eLabFTW REST API.
77

88
# Description
99

10-
This repository allows generating a python library to interact with [eLabFTW](https://github.com/elabftw/elabftw) REST API v2. It uses [Swagger Codegen](https://github.com/swagger-api/swagger-codegen/tree/3.0.0) to generate it based on the OpenApi specification of [eLabFTW REST API v2](https://doc.elabftw.net/api/v2/).
10+
This repository allows generating a python library to interact with [eLabFTW](https://github.com/elabftw/elabftw) REST API v2. It uses [Openapi Generator](https://github.com/OpenAPITools/openapi-generator) to generate it based on the OpenApi specification of [eLabFTW REST API v2](https://doc.elabftw.net/api/v2/).
1111

1212
As such, it doesn't contain the generated code, but only instructions on how to generate it for local development.
1313

14-
Users should install the library with `pip`, as described below.
14+
Users should install the library with `pip` or any other python dependency management tool, as described below.
1515

1616
# Installation
1717

1818
~~~bash
1919
# create a virtual environment
20-
python -m venv elab
20+
python -m venv venv
2121
# activate it
22-
source elab/bin/activate
22+
source venv/bin/activate
2323
# on Windows
24-
# C:\> elab\Scripts\activate.bat
24+
# C:\> venv\Scripts\activate.bat
2525
# install the library
2626
pip install elabapi-python
2727
~~~

helper.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
# the docker image used to generate the client code
99
# pinning version to avoid unexpected bugs
10-
# see https://github.com/swagger-api/swagger-codegen/releases for updating version below
11-
docker_image="swaggerapi/swagger-codegen-cli-v3:3.0.68"
10+
# releases: https://github.com/OpenAPITools/openapi-generator/releases
11+
generator_version="v7.13.0"
12+
docker_image="openapitools/openapi-generator-cli:$generator_version"
1213
# where to grab the definition file
1314
openapi_yaml_url="https://raw.githubusercontent.com/elabftw/elabftw/master/apidoc/v2/openapi.yaml"
1415
# folder with the generated python code
@@ -23,52 +24,54 @@ function cleanup {
2324
# generate the lib from remote spec
2425
function generate {
2526
cleanup
26-
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
27+
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -g python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
2728
}
2829

2930
function generate-html {
3031
cleanup
31-
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l html2 -o /local/"$html" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
32+
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -g html2 -o /local/"$html" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
3233
}
3334

3435
# don't use user/group ids in GH actions
3536
function generate-ci {
36-
docker run --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
37+
docker run --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -g python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
3738
# fix permissions
3839
sudo chown -R "$(id -u)":"$(id -gn)" "$lib"
3940
}
4041

4142
# generate the lib from a local file in current directory
4243
function generate-from-local {
4344
cleanup
44-
docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}":/local "$docker_image" generate -i /local/openapi.yaml -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
45+
docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}":/local "$docker_image" generate -i /local/openapi.yaml -g python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
46+
}
47+
48+
function venv {
49+
rm -rf venv
50+
python -m venv venv
51+
source venv/bin/activate
4552
}
4653

4754
function build {
4855
cd "$lib" || exit 1
49-
python setup.py sdist bdist_egg bdist_wheel
50-
cd ..
56+
pip install uv
57+
uv build
5158
}
5259

5360
function publish {
5461
generate
5562
build
5663
cd "$lib" || exit 1
5764
twine upload dist/*
58-
cd ..
5965
}
6066

6167
function install-dev {
62-
cd "$lib" || exit 1
68+
venv
6369
pip install -e generated
64-
cd ..
6570
}
6671

67-
6872
function build-ci {
6973
generate-ci
70-
cd "$lib" || exit 1
71-
python -m build --sdist --wheel --outdir ../dist
74+
build
7275
}
7376

7477
"$1"

0 commit comments

Comments
 (0)