diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 96e2809..cf2029c 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -97,3 +97,15 @@ jobs: openapi-file: test_data/openapi.json command-args: --model-name-prefix=BLAH - run: test -f rust-client/src/models/blah_a_model.rs + test-env-vars: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + - name: Generate with environment variables + env: + _JAVA_OPTIONS: "-DmaxYamlCodePoints=99999999" + uses: openapi-generators/openapitools-generator-action@v1 + with: + generator: rust + openapi-file: test_data/openapi.json + - run: cd rust-client diff --git a/.gitignore b/.gitignore index 9f11b75..2483976 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +__pycache__/ diff --git a/README.md b/README.md index 37dde13..82b8bc9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,45 @@ See user-defined [templates](https://openapi-generator.tech/docs/templating#modi Additional arguments to pass through to the [generate](https://openapi-generator.tech/docs/usage#generate) command. +## Environment Variables + +The action automatically passes through certain environment variables to the OpenAPI Generator container. You can set these using GitHub Actions' built-in `env:` feature. + +### Supported Environment Variables + +The following environment variables are automatically passed through when set: +- `_JAVA_OPTIONS` - Java runtime options (useful for handling large YAML files) +- `JAVA_OPTS` - Additional Java options +- `NODE_ENV` - Node.js environment setting +- `DEBUG` - Debug mode flag +- `OPENAPI_GENERATOR_VERSION` - Override generator version + +### Usage Examples + +For handling large YAML files: +```yaml +- name: Generate Client + env: + _JAVA_OPTIONS: "-DmaxYamlCodePoints=99999999" + uses: openapi-generators/openapitools-generator-action@v1 + with: + generator: powershell + openapi-file: large-redfish-spec.yaml +``` + +Multiple environment variables: +```yaml +- name: Generate Client + env: + _JAVA_OPTIONS: "-DmaxYamlCodePoints=99999999" + NODE_ENV: "production" + DEBUG: "true" + uses: openapi-generators/openapitools-generator-action@v1 + with: + generator: typescript-angular + openapi-file: spec.yaml +``` + ## Outputs No outputs are returned. The generated client is placed in the current directory. The name of the package (unless configured differently) will be `generator-name-client` where "generator-name" is (unsurprisingly) the name of the generator used to generate the client. diff --git a/entrypoint.py b/entrypoint.py index 11fa6ee..f6fe0bb 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,10 +1,25 @@ from subprocess import call from sys import argv -from os import getenv, getuid +from os import getenv, getuid, environ (_, generator, docker_repository, docker_image, generator_tag, openapi_file, openapi_url, config_file, template_dir, *args) = argv cmd = f"docker run -u {getuid()}:1001 --rm --workdir /github/workspace -v {getenv('GITHUB_WORKSPACE')}:/github/workspace" + +# Pass through environment variables that are commonly needed for OpenAPI generation +# This allows users to set these via GitHub Actions env: instead of custom input +env_vars_to_pass = [ + '_JAVA_OPTIONS', + 'JAVA_OPTS', + 'NODE_ENV', + 'DEBUG', + 'OPENAPI_GENERATOR_VERSION' +] + +for env_var in env_vars_to_pass: + if env_var in environ: + cmd = f"{cmd} -e {env_var}='{environ[env_var]}'" + cmd = f"{cmd} {docker_repository}/{docker_image}:{generator_tag} generate" cmd = f"{cmd} -g {generator} -o /github/workspace/{generator}-client"