Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Python library for eLabFTW REST API.

# Description

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/).
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/).

Alternatively, it supports using [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) as an optional code generation tool.

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

Expand Down Expand Up @@ -62,15 +64,29 @@ From TU Graz, Shared RDM Project:

## Using the helper script

~~~bash
# generate the library
### Generate the library using Code Generators

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.

```bash
# Option 1: Generate using Swagger Codegen
./helper.sh generate
# generate from local file: openapi.yaml must be in current dir

# Option 2: Generate using OpenAPI Generator
GENERATOR_TOOL=openapi ./helper.sh generate
```

### Or Generate from a local OpenAPI Specification
Ensure the `openapi.yaml` file is located in the current working directory, then run:
~~~bash
./helper.sh generate-from-local
# build packages
./helper.sh build
~~~

### Build packages
```bash
./helper.sh build
```

## Installing the library for dev

~~~bash
Expand Down
27 changes: 19 additions & 8 deletions helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
# Edit docker systemd service file and add "--default-ulimit nofile=65536:65536" on the ExecStart line
# then systemctl daemon-reload and systemctl restart docker

# default generator
generator_tool="${GENERATOR_TOOL:-swagger}"

# generator can be 'swagger' or 'openapi'
# the docker image used to generate the client code
# pinning version to avoid unexpected bugs
# releases: https://github.com/OpenAPITools/openapi-generator/releases
generator_version="v7.13.0"
docker_image="openapitools/openapi-generator-cli:$generator_version"
if [ "$generator_tool" = "swagger" ]; then
generator_lineage="v3"
generator_version="3.0.68"
docker_image="swaggerapi/swagger-codegen-cli-$generator_lineage:$generator_version"
generator_flag="-l"
else
# releases: https://github.com/OpenAPITools/openapi-generator/releases
generator_version="v7.13.0"
docker_image="openapitools/openapi-generator-cli:$generator_version"
generator_flag="-g"
fi

# where to grab the definition file
openapi_yaml_url="https://raw.githubusercontent.com/elabftw/elabftw/master/apidoc/v2/openapi.yaml"
# folder with the generated python code
Expand All @@ -24,25 +35,25 @@ function cleanup {
# generate the lib from remote spec
function generate {
cleanup
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
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
}

function generate-html {
cleanup
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
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
}

# don't use user/group ids in GH actions
function generate-ci {
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
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
# fix permissions
sudo chown -R "$(id -u)":"$(id -gn)" "$lib"
}

# generate the lib from a local file in current directory
function generate-from-local {
cleanup
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
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
}

function venv {
Expand Down