Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GitHub Actions workflow for automatically updating the example JSON files #2068

Closed
wants to merge 4 commits into from
Closed
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
67 changes: 67 additions & 0 deletions .github/workflows/yaml2json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: YAML2JSON

#
# This workflow updates the *.json files in the examples/v3.0 directory,
# when the corresponding *.yaml files change.
# JSON example files are automatically generated from the YAML example files.
# Only the YAML files should be adjusted manually.
#

# run this on push to master
on:
push:
branches:
- master

jobs:
yaml2json:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1 # checkout repo content

- name: Install dependencies
run: |
cd examples/v3.0
echo '{}' > composer.json
# fix versions to ensure reproduceable runs
composer require cebe/php-openapi:1.3.1 symfony/yaml:4.2.12 cebe/indent:1.1.0

- name: convert YAML examples to JSON
run: |
cd examples/v3.0
for file in *.yaml ; do
target=`basename -s .yaml $file`.json
echo "converting $file to $target ..."
vendor/bin/php-openapi convert --read-yaml $file --write-json $target
vendor/bin/indent --tabs --tabstop=4 $target
vendor/bin/indent --spaces --tabstop=2 $target
done

- name: cleanup
run: |
cd examples/v3.0
rm -rf vendor/ composer.*

- name: git diff
run: |
cd examples/v3.0
git add *.json
git --no-pager -c color.diff=always diff --staged

- name: Create Pull Request
uses: peter-evans/create-pull-request@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch-suffix: none
branch: update-json-examples
title: Update JSON example files
commit-message: Update JSON example files
body: |
This pull request is automatically triggered by github actions [create-pull-request][1].

It seems the OpenAPI example YAML files have changed, so the JSON files are automatically being adjusted.

[1]: https://github.com/peter-evans/create-pull-request

29 changes: 16 additions & 13 deletions examples/v3.0/api-with-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ paths:
200 response
content:
application/json:
examples:
examples:
foo:
value: {
value:
{
"versions": [
{
"status": "CURRENT",
Expand All @@ -40,15 +41,15 @@ paths:
]
}
]
}
}
'300':
description: |-
300 response
content:
application/json:
examples:
application/json:
examples:
foo:
value: |
value:
{
"versions": [
{
Expand All @@ -74,7 +75,7 @@ paths:
]
}
]
}
}
/v2:
get:
operationId: getVersionDetailsv2
Expand All @@ -84,10 +85,11 @@ paths:
description: |-
200 response
content:
application/json:
application/json:
examples:
foo:
value: {
value:
{
"version": {
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
Expand Down Expand Up @@ -124,15 +126,16 @@ paths:
}
]
}
}
}
'203':
description: |-
203 response
content:
application/json:
application/json:
examples:
foo:
value: {
value:
{
"version": {
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
Expand Down Expand Up @@ -164,4 +167,4 @@ paths:
}
]
}
}
}