From 22c0653b25ffd4503ee5b8c7dbec622dfdf66bfb Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 27 Nov 2019 09:30:28 +0100 Subject: [PATCH 1/4] Create yaml2json.yml Github Actions workflow 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. fixes #1385 - When a push to `master` (or any other branch we wish to include) is made, a Github Actions Workflow is triggered ([example](https://github.com/cebe/OpenAPI-Specification/commit/9c98e819ae876af92c2a9112dcfa6dfcb929e7dc/checks?check_suite_id=331067708)) - it will generate new JSON files from the YAML examples - if there are any changes, it will create a pull request to the branch that triggered the Workflow ([example](https://github.com/cebe/OpenAPI-Specification/pull/3)) --- .github/workflows/yaml2json.yml | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/yaml2json.yml diff --git a/.github/workflows/yaml2json.yml b/.github/workflows/yaml2json.yml new file mode 100644 index 0000000000..949b37c45f --- /dev/null +++ b/.github/workflows/yaml2json.yml @@ -0,0 +1,70 @@ +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 + - try-github-actions + +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 ..." + if [ "$file" != "api-with-examples.yaml" ] ; then + 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 + fi + done + + - name: cleanup + run: | + cd examples/v3.0 + rm -rf vendor/ composer.* + + - name: git diff + run: | + cd examples/v3.0 + git add *.json + git 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 + From 8efab5ff43882fa7acb4d7858bb1b05d08930d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Mon, 21 Oct 2019 15:49:24 +0200 Subject: [PATCH 2/4] Fix syntax errors close https://github.com/OAI/OpenAPI-Specification/pull/2036 --- examples/v3.0/api-with-examples.yaml | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/v3.0/api-with-examples.yaml b/examples/v3.0/api-with-examples.yaml index 09003b6aba..82b58141ef 100644 --- a/examples/v3.0/api-with-examples.yaml +++ b/examples/v3.0/api-with-examples.yaml @@ -13,9 +13,10 @@ paths: 200 response content: application/json: - examples: + examples: foo: - value: { + value: + { "versions": [ { "status": "CURRENT", @@ -40,15 +41,15 @@ paths: ] } ] - } + } '300': description: |- 300 response content: - application/json: - examples: + application/json: + examples: foo: - value: | + value: { "versions": [ { @@ -74,7 +75,7 @@ paths: ] } ] - } + } /v2: get: operationId: getVersionDetailsv2 @@ -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", @@ -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", @@ -164,4 +167,4 @@ paths: } ] } - } + } From d1ed6024fdbc9c56f7746fc9869351381f4eae2a Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 6 Dec 2019 14:35:22 +0100 Subject: [PATCH 3/4] re-include api-with-examples.yaml in yaml2json conversion --- .github/workflows/yaml2json.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/yaml2json.yml b/.github/workflows/yaml2json.yml index 949b37c45f..4bb470c4f0 100644 --- a/.github/workflows/yaml2json.yml +++ b/.github/workflows/yaml2json.yml @@ -35,11 +35,9 @@ jobs: for file in *.yaml ; do target=`basename -s .yaml $file`.json echo "converting $file to $target ..." - if [ "$file" != "api-with-examples.yaml" ] ; then - 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 - fi + 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 @@ -51,7 +49,7 @@ jobs: run: | cd examples/v3.0 git add *.json - git diff --staged + git --no-pager -c color.diff=always diff --staged - name: Create Pull Request uses: peter-evans/create-pull-request@v1 From 09840a426fc1de892640bba81bec86711e6501ab Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 9 Dec 2019 08:37:24 +0100 Subject: [PATCH 4/4] remove test branch from yaml2json workflow --- .github/workflows/yaml2json.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/yaml2json.yml b/.github/workflows/yaml2json.yml index 4bb470c4f0..d191626941 100644 --- a/.github/workflows/yaml2json.yml +++ b/.github/workflows/yaml2json.yml @@ -12,7 +12,6 @@ on: push: branches: - master - - try-github-actions jobs: yaml2json: