Skip to content

Commit 98b564e

Browse files
use swagger-codegen as default generator tool (#34)
default generator is swagger-codegen. Allow using openapi-generator if needed
1 parent c871baf commit 98b564e

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ 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 [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/).
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/).
11+
12+
Alternatively, it supports using [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) as an optional code generation tool.
1113

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

@@ -62,15 +64,29 @@ From TU Graz, Shared RDM Project:
6264

6365
## Using the helper script
6466

65-
~~~bash
66-
# generate the library
67+
### Generate the library using Code Generators
68+
69+
The primary tool for generating the library is swagger-codegen. However, you can also use OpenAPI Generator as an alternative, if it better suits your requirements or you encounter issues with the default.
70+
71+
```bash
72+
# Option 1: Generate using Swagger Codegen
6773
./helper.sh generate
68-
# generate from local file: openapi.yaml must be in current dir
74+
75+
# Option 2: Generate using OpenAPI Generator
76+
GENERATOR_TOOL=openapi ./helper.sh generate
77+
```
78+
79+
### Or Generate from a local OpenAPI Specification
80+
Ensure the `openapi.yaml` file is located in the current working directory, then run:
81+
~~~bash
6982
./helper.sh generate-from-local
70-
# build packages
71-
./helper.sh build
7283
~~~
7384

85+
### Build packages
86+
```bash
87+
./helper.sh build
88+
```
89+
7490
## Installing the library for dev
7591

7692
~~~bash

helper.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
# Edit docker systemd service file and add "--default-ulimit nofile=65536:65536" on the ExecStart line
55
# then systemctl daemon-reload and systemctl restart docker
66

7+
# default generator
8+
generator_tool="${GENERATOR_TOOL:-swagger}"
79

10+
# generator can be 'swagger' or 'openapi'
811
# the docker image used to generate the client code
9-
# pinning version to avoid unexpected bugs
10-
# releases: https://github.com/OpenAPITools/openapi-generator/releases
11-
generator_version="v7.13.0"
12-
docker_image="openapitools/openapi-generator-cli:$generator_version"
12+
if [ "$generator_tool" = "swagger" ]; then
13+
generator_lineage="v3"
14+
generator_version="3.0.68"
15+
docker_image="swaggerapi/swagger-codegen-cli-$generator_lineage:$generator_version"
16+
generator_flag="-l"
17+
else
18+
# releases: https://github.com/OpenAPITools/openapi-generator/releases
19+
generator_version="v7.13.0"
20+
docker_image="openapitools/openapi-generator-cli:$generator_version"
21+
generator_flag="-g"
22+
fi
23+
1324
# where to grab the definition file
1425
openapi_yaml_url="https://raw.githubusercontent.com/elabftw/elabftw/master/apidoc/v2/openapi.yaml"
1526
# folder with the generated python code
@@ -24,25 +35,25 @@ function cleanup {
2435
# generate the lib from remote spec
2536
function generate {
2637
cleanup
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
38+
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" "$generator_flag" python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
2839
}
2940

3041
function generate-html {
3142
cleanup
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
43+
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" "$generator_flag" html2 -o /local/"$html" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
3344
}
3445

3546
# don't use user/group ids in GH actions
3647
function generate-ci {
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
48+
docker run --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" "$generator_flag" python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
3849
# fix permissions
3950
sudo chown -R "$(id -u)":"$(id -gn)" "$lib"
4051
}
4152

4253
# generate the lib from a local file in current directory
4354
function generate-from-local {
4455
cleanup
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
56+
docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}":/local "$docker_image" generate -i /local/openapi.yaml "$generator_flag" python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
4657
}
4758

4859
function venv {

0 commit comments

Comments
 (0)