Skip to content

Commit

Permalink
Use openapi-generator-cli batch
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Oct 8, 2024
1 parent 8446724 commit a0021ea
Show file tree
Hide file tree
Showing 650 changed files with 2,720 additions and 1,484 deletions.
64 changes: 38 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO ADD PIXI
name: Release

on:
Expand All @@ -8,8 +7,8 @@ on:
- 'version.txt'

jobs:
build:
name: Build
build-python:
name: Build Python packages
runs-on: ubuntu-24.04
strategy:
fail-fast: true
Expand All @@ -20,6 +19,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: ${{ matrix.name }}
- name: Install build
run: pip install --break-system-packages build
- name: Build dist
Expand All @@ -29,10 +30,10 @@ jobs:
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}/dist/
publish:
name: Publish
publish-python:
name: Publish Python packages
runs-on: ubuntu-24.04
needs: build
needs: build-python
steps:
- name: Download distributions packages
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -61,18 +62,15 @@ jobs:
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# TODO change to prod PyPI
repository-url: https://test.pypi.org/legacy/
password: '${{ secrets.TEST_PYPI_TOKEN }}'
# password: '${{ secrets.PYPI_API_TOKEN }}'
password: '${{ secrets.PYPI_API_TOKEN }}'
outputs:
pep508_chris_oag: ${{ steps.requirements.outputs.chris_oag }}
pep508_aiochris_oag: ${{ steps.requirements.outputs.aiochris_oag }}

oci-image:
name: Push OCI Image
oci-image-python:
name: Build and push Python OCI images
runs-on: ubuntu-24.04
needs: build
needs: build-python
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -138,14 +136,28 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


# rust-crate:
# name: Build and publish Rust crate
# runs-on: ubuntu-24.04
# env:
# CARGO_TERM_COLOR: always
# steps:
# - name: Git checkout
# uses: actions/checkout@v4
# with:
# sparse-checkout: rust
# - name: cargo publish
# run: cargo publish --manifest-path rust/Cargo.toml
# env:
# CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

gh-release:
name: Create GitHub Release
runs-on: ubuntu-24.04
needs:
- oci-image
- publish
- oci-image-python
- publish-python
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -166,36 +178,36 @@ jobs:
```shell
# using uv - https://docs.astral.sh/uv/
uv pip install ${{ needs.publish.outputs.pep508_aiochris_oag }}
uv pip install ${{ needs.publish-python.outputs.pep508_aiochris_oag }}
# using rye - https://rye.astral.sh/
rye add ${{ needs.publish.outputs.pep508_aiochris_oag }}
rye add ${{ needs.publish-python.outputs.pep508_aiochris_oag }}
# using pip
pip install ${{ needs.publish.outputs.pep508_aiochris_oag }}
pip install ${{ needs.publish-python.outputs.pep508_aiochris_oag }}
# using Docker
docker pull ${{ needs.oci-image.outputs.python-async-image }}:${{ needs.oci-image.outputs.python-async-version }}
docker pull ${{ needs.oci-image-python.outputs.python-async-image }}:${{ needs.oci-image-python.outputs.python-async-version }}
# using Podman
podman pull ${{ needs.oci-image.outputs.python-async-image }}:${{ needs.oci-image.outputs.python-async-version }}
podman pull ${{ needs.oci-image-python.outputs.python-async-image }}:${{ needs.oci-image-python.outputs.python-async-version }}
```
## Python urllib3 Client
```shell
# using uv - https://docs.astral.sh/uv/
uv pip install ${{ needs.publish.outputs.pep508_chris_oag }}
uv pip install ${{ needs.publish-python.outputs.pep508_chris_oag }}
# using rye - https://rye.astral.sh/
rye add ${{ needs.publish.outputs.pep508_chris_oag }}
rye add ${{ needs.publish-python.outputs.pep508_chris_oag }}
# using pip
pip install ${{ needs.publish.outputs.pep508_chris_oag }}
pip install ${{ needs.publish-python.outputs.pep508_chris_oag }}
# using Docker
docker pull ${{ needs.oci-image.outputs.python-image }}:${{ needs.oci-image.outputs.python-version }}
docker pull ${{ needs.oci-image-python.outputs.python-image }}:${{ needs.oci-image-python.outputs.python-version }}
# using Podman
podman pull ${{ needs.oci-image.outputs.python-image }}:${{ needs.oci-image.outputs.python-version }}
podman pull ${{ needs.oci-image-python.outputs.python-image }}:${{ needs.oci-image-python.outputs.python-version }}
```
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/schema*.yaml

/.venv

dist
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ git add -A
git commit -m "Version $(< version.txt)"
git push origin main
```

## Adding A Generator

Many other generators are available. See the list here: https://openapi-generator.tech/docs/generators

To add a generator, create a YAML configuration file for it in `configs`.

3 changes: 3 additions & 0 deletions configs/broken/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `typescript` generator straight up crashes.
- `typescript-fetch` generator produces invalid code for `oneOf` where variants are primitive types.
See https://github.com/OpenAPITools/openapi-generator/issues/14763
14 changes: 14 additions & 0 deletions configs/broken/typescript-browser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'!include': 'common.yaml'

generatorName: typescript
outputDir: typescript-browser

# https://openapi-generator.tech/docs/generators/typescript/#config-options
additionalProperties:
npmName: '@fnndsc/chris-oag-browser'
framework: framework
platform: browser
nullSafeAdditionalProps: true
paramNaming: camelCase
'!include': version_npm.yaml

14 changes: 14 additions & 0 deletions configs/broken/typescript-deno.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'!include': 'common.yaml'

generatorName: typescript
outputDir: typescript-deno

# https://openapi-generator.tech/docs/generators/typescript/#config-options
additionalProperties:
npmName: '@fnndsc/chris-oag-deno'
framework: framework
platform: deno
nullSafeAdditionalProps: true
paramNaming: camelCase
'!include': version_npm.yaml

14 changes: 14 additions & 0 deletions configs/broken/typescript-fetch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'!include': 'common.yaml'

generatorName: typescript-fetch
outputDir: typescript-fetch

# https://openapi-generator.tech/docs/generators/typescript-fetch/#config-options
additionalProperties:
npmName: '@fnndsc/chris-oag'
withInterfaces: true
nullSafeAdditionalProps: true
paramNaming: camelCase
# stringEnums: true
'!include': version_npm.yaml

14 changes: 14 additions & 0 deletions configs/broken/typescript-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'!include': 'common.yaml'

generatorName: typescript
outputDir: typescript-node

# https://openapi-generator.tech/docs/generators/typescript/#config-options
additionalProperties:
npmName: '@fnndsc/chris-oag-node'
framework: framework
platform: node
nullSafeAdditionalProps: true
paramNaming: camelCase
'!include': version_npm.yaml

12 changes: 12 additions & 0 deletions configs/python-async.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'!include': 'common.yaml'

generatorName: python
outputDir: python-async

# https://openapi-generator.tech/docs/generators/python/#config-options
additionalProperties:
packageName: aiochris_oag
projectName: aiochris-oag
library: asyncio
'!include': 'version_pep440.yaml'

12 changes: 12 additions & 0 deletions configs/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'!include': 'common.yaml'

generatorName: python
outputDir: python

# https://openapi-generator.tech/docs/generators/python/#config-options
additionalProperties:
packageName: chris_oag
projectName: chris-oag
library: urllib3
'!include': 'version_pep440.yaml'

12 changes: 12 additions & 0 deletions configs/todo/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'!include': 'common.yaml'

generatorName: rust
outputDir: rust

# https://openapi-generator.tech/docs/generators/rust/#config-options
additionalProperties:
library: reqwest
preferUnsignedInt: true
supportAsync: true
supportMiddleware: true
'!include': version.yaml
15 changes: 15 additions & 0 deletions configs/todo/typescript-axios.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'!include': 'common.yaml'

generatorName: typescript-axios
outputDir: typescript-axios

# https://openapi-generator.tech/docs/generators/typescript-axios/#config-options
additionalProperties:
npmName: '@fnndsc/chris-oag'
withInterfaces: true
nullSafeAdditionalProps: true
paramNaming: camelCase
stringEnums: true
# what is withSeparateModelsAndApi?
'!include': version_npm.yaml

1 change: 1 addition & 0 deletions includes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version*.yaml
5 changes: 5 additions & 0 deletions includes/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inputSpec: https://github.com/FNNDSC/ChRIS_ultron_backEnd/releases/download/v6.3.0-beta.4/schema_split.yaml
gitHost: github.com
gitUserId: FNNDSC
gitRepoId: openapi-clients

33 changes: 13 additions & 20 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
file := "schema_split.yaml"
releases_url := "https://github.com/FNNDSC/ChRIS_ultron_backEnd/releases"
generate-batch: sync-versions
podman run --rm --userns=keep-id:uid=100100,gid=100100 -u 100100:100100 \
-v "$(pwd):/share" -w /share \
docker.io/openapitools/openapi-generator-cli:v7.9.0 \
batch --clean --fail-fast --root-dir /share --includes-base-dir /share/includes \
configs/*.yaml

generate-all:
@just generate python -g python -p packageName=chris_oag,projectName=chris-oag -p library=urllib3,packageVersion=$(just get-version-pep440)
@just generate python-async -g python -p packageName=aiochris_oag,projectName=aiochris-oag -p library=asyncio,packageVersion=$(just get-version-pep440)
# @just generate typescript-fetch -g typescript-fetch -p npmName=@fnndsc/chris-openapi-generated -p withInterfaces=true
# @just generate rust -g rust -p packageName=chris-openapi-generated -p library=reqwest,preferUnsignedInt=true,supportMiddleware=true
sync-versions:
just write-version-file version.yaml packageVersion $(just get-version)
just write-version-file version_npm.yaml npmVersion $(just get-version)
just write-version-file version_pep440.yaml packageVersion $(just get-version-pep440)

# generate an OpenAPI client
generate output +options:
@if ! [ -e "{{file}}" ]; then \
error="$(tput setaf 1)error$(tput sgr0): {{file}} not found."; \
suggestion="Please download the OpenAPI specification YAML from {{releases_url}} and save it as $(pwd)/{{file}}"; \
echo "$error $suggestion"; \
exit 1; \
fi
if ! [ -d {{output}} ]; then mkdir -v {{output}}; fi
podman run --rm --userns=keep-id:uid=100100,gid=100100 -u 100100:100100 \
-v "$(pwd)/{{output}}:/out:rw" -v "$(pwd)/{{file}}:/{{file}}:ro" \
docker.io/openapitools/openapi-generator-cli:v7.8.0 \
generate {{options}} -i "/{{file}}" -o "/out"
write-version-file file key value:
@echo '# This file was automatically generated by `just`. Do not edit it manually.' > includes/{{file}}
@echo "{{key}}: '{{value}}'" >> includes/{{file}}

get-version-pep440:
@./semver2pep440.sh < version.txt
Expand Down
17 changes: 5 additions & 12 deletions python-async/.github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Test with pytest
run: |
pytest
pytest --cov={{packageName}}
6 changes: 3 additions & 3 deletions python-async/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ stages:
- pip install -r test-requirements.txt
- pytest --cov=aiochris_oag

pytest-3.7:
extends: .pytest
image: python:3.7-alpine
pytest-3.8:
extends: .pytest
image: python:3.8-alpine
Expand All @@ -29,3 +26,6 @@ pytest-3.10:
pytest-3.11:
extends: .pytest
image: python:3.11-alpine
pytest-3.12:
extends: .pytest
image: python:3.12-alpine
Loading

0 comments on commit a0021ea

Please sign in to comment.