Skip to content

Commit 1bd36b0

Browse files
author
aman
committed
Add api client generation
1 parent 62737aa commit 1bd36b0

8 files changed

Lines changed: 10526 additions & 0 deletions

File tree

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ htmlcov/
3939
# OS
4040
.DS_Store
4141
Thumbs.db
42+
43+
## API generator
44+
.ruff_cache/
45+
openapi.json
46+
openapi.codegen.json

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ The release / publish workflow is defined as:
5050
- Create a new GitHub release based on that tag, baptize the release identical to the tag and add release notes.
5151
- Triggered by the release creation the GitHub Action `publish.yml` will build the package and publish it to PyPi.
5252

53+
Update the API client
54+
55+
The API generator <https://pypi.org/project/openapi-python-client/> is used.
56+
57+
```bash
58+
./generate_api_client.sh <ip_or_hostname_of_my_bodyloop_instance>
59+
```
60+
5361
## License
5462

5563
See [LICENSE](LICENSE)

generate-api-client.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
HOSTNAME=${1:-bodyloop-control-pc}
4+
5+
curl -kO https://${HOSTNAME}/api/v2/openapi.json
6+
7+
# Optionally beautify the JSON file with jq
8+
mv openapi.json openapi_tmp.json && jq . openapi_tmp.json > openapi.json && rm openapi_tmp.json
9+
10+
# Generate the API client code
11+
mkdir -p src/bodyloop_sdk/api
12+
13+
# Normalize OpenAPI for openapi-python-client compatibility
14+
uv run python scripts/prepare_openapi_for_codegen.py --input openapi.json --output openapi.codegen.json
15+
16+
uv run --with openapi-python-client python -m openapi_python_client generate --overwrite --config generate-api-client.yml --path openapi.codegen.json --output-path src/bodyloop_sdk
17+
18+
mv src/bodyloop_sdk/README.md src/bodyloop_sdk/client/
19+
20+
rm src/bodyloop_sdk/.gitignore
21+
rm src/bodyloop_sdk/pyproject.toml
22+
rm -rf src/bodyloop_sdk/client/.ruff_cache/

generate-api-client.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project_name_override: client
2+
package_name_override: client
3+
class_overrides:
4+
_PrivateInternalLongName:
5+
class_name: ShortName
6+
module_name: short_name
7+
docstrings_on_attributes: true
8+
literal_enums: true
9+
generate_all_tags: true

0 commit comments

Comments
 (0)