Skip to content
Draft
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
12 changes: 12 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
__pycache__/
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 16 additions & 1 deletion entrypoint.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down