Below is an example of a GitHub Action workflow that converts an OpenAPI JSON documentation into a PHP API client using the OpenAPI Generator tool. The generated PHP client code is then committed back to the repository.
name: Generate PHP API Client
on:
push:
branches:
- main
jobs:
generate-php-client:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Java and OpenAPI Generator
run: |
sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.3.0/openapi-generator-cli-5.3.0.jar -O openapi-generator-cli.jar
- name: Generate PHP Client
run: |
java -jar openapi-generator-cli.jar generate \
-i path/to/openapi.json \
-g php \
-o generated-php-client
- name: Commit Generated PHP Client
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add generated-php-client
git commit -m "Generated PHP client from OpenAPI JSON documentation" || echo "No changes to commit"
To use this workflow, make sure to replace the following placeholders:
path/to/openapi.json: Replace this with the actual path to your OpenAPI JSON documentation file within the repository.generated-php-client: Replace this with the desired output directory name for the generated PHP client.
To set up this workflow in your repository:
- Create a new file named
.github/workflows/generate-php-client.ymlin the root of your repository. - Copy and paste the above YAML content into the
generate-php-client.ymlfile. - Commit and push the changes to your repository.
Whenever there is a push to the main branch, this GitHub Action workflow will execute, generating a PHP client based on the provided OpenAPI JSON documentation and committing the generated code back to the repository under the specified directory.

Laisser un commentaire
Vous devez vous connecter pour publier un commentaire.