Skip to content

Commit

Permalink
Add include-path-params flag (#17)
Browse files Browse the repository at this point in the history
* Add --include-path-params flag for #16

* refer to original documentation in oasdiff

* Add mapping for CLI argumetns to action's inputs #17

Move format to flags for diff action

---------

Co-authored-by: Reuven <rh@tufin.com>
  • Loading branch information
Pentusha and Reuven committed Oct 16, 2023
1 parent cd0f0ab commit 74fbf19
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 28 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,51 @@ Depends on your use case:
Copy and paste the following snippet into your build .yml file:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/diff@main
with:
base: 'specs/base.yaml'
revision: 'specs/revision.yaml'
format: 'text'
fail-on-diff: false
```

This action supports additional arguments that are converted to parameters for the `oasdiff` CLI.

| CLI | Action input | Default |
|--------|--------|--------|
| --fail-on-diff | fail-on-diff | false |
| --format | format | yaml |
| --include-path-params | include-path-params | false |

### Check for breaking API changes, and fail if any are found
Copy and paste the following snippet into your build .yml file:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/breaking@main
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
fail-on-diff: true
```

#### Include optional breaking change checks
In order to ensure even stricter breaking policies, oasdiff provides with a few optional checks.
Complete list can be found [here](https://github.com/Tufin/oasdiff/blob/main/BREAKING-CHANGES.md#optional-breaking-changes-checks).
Additional arguments:

| CLI | Action input | Default |
|-----------------------|--------|--------|
| --fail-on WARN | fail-on-diff | true |
| --include-checks | include-checks | csv |
| --include-path-params | include-path-params | false |

These checks can be added by filling the `include-checks` argument in the action like the following:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/breaking@main
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
fail-on-diff: true
include-checks: "response-non-success-status-removed,api-operation-id-removed"
```

### Generate a changelog
Copy and paste the following snippet into your build .yml file:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/changelog@main
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
```

Additional arguments:

| CLI | Action input | Default |
|--------|--------|--------|
| --include-path-params | include-path-params | false |
5 changes: 5 additions & 0 deletions breaking/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
include-checks:
description: 'Include any of the defined optional breaking changes checks'
required: false
include-path-params:
description: 'Include path parameter names in endpoint matching'
required: false
default: 'false'
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -22,3 +26,4 @@ runs:
- ${{ inputs.revision }}
- ${{ inputs.fail-on-diff }}
- ${{ inputs.include-checks }}
- ${{ inputs.include-path-params }}
9 changes: 7 additions & 2 deletions breaking/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ set -e
readonly base="$1"
readonly revision="$2"
readonly fail_on_diff="$3"
readonly include_checks="$4"
echo "running oasdiff breaking base: $base, revision: $revision, fail_on_diff: $fail_on_diff, include_checks: $include_checks"
readonly include_checks="$4"
readonly include_path_params="$5"

echo "running oasdiff breaking base: $base, revision: $revision, fail_on_diff: $fail_on_diff, include_checks: $include_checks, include_path_params: $include_path_params"

# Build flags to pass in command
flags=""
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on WARN"
fi
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
fi
if [ -n "$include_checks" ]; then
flags="${flags} --include-checks $include_checks"
fi
Expand Down
5 changes: 5 additions & 0 deletions changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ inputs:
revision:
description: 'Path of revised OpenAPI spec in YAML or JSON format'
required: true
include-path-params:
description: 'Include path parameter names in endpoint matching'
required: false
default: 'false'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.base }}
- ${{ inputs.revision }}
- ${{ inputs.include-path-params }}
16 changes: 14 additions & 2 deletions changelog/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ set -e

readonly base="$1"
readonly revision="$2"
readonly include_path_params="$3"

echo "running oasdiff changelog base: $base, revision: $revision"
echo "running oasdiff changelog base: $base, revision: $revision, include_path_params: $include_path_params"

# Build flags to pass in command
flags=""
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
fi
echo "flags: $flags"

set -o pipefail

oasdiff changelog "$base" "$revision"
if [ -n "$flags" ]; then
oasdiff changelog "$base" "$revision" $flags
else
oasdiff changelog "$base" "$revision"
fi
5 changes: 5 additions & 0 deletions diff/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ inputs:
description: 'Fail with exit code 1 if a difference is found'
required: false
default: 'false'
include-path-params:
description: 'Include path parameter names in endpoint matching'
required: false
default: 'false'
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -23,3 +27,4 @@ runs:
- ${{ inputs.revision }}
- ${{ inputs.format }}
- ${{ inputs.fail-on-diff }}
- ${{ inputs.include-path-params }}
22 changes: 18 additions & 4 deletions diff/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ readonly base="$1"
readonly revision="$2"
readonly format="$3"
readonly fail_on_diff="$4"
readonly include_path_params="$5"

echo "running oasdiff diff base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff"
echo "running oasdiff diff base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff, include_path_params: $include_path_params"

# Build flags to pass in command
flags=""
if [ "$format" != "yaml" ]; then
flags="${flags} --format ${format}"
fi
if [ "$fail_on_diff" = "true" ]; then
flags="${flags} --fail-on-diff"
fi
if [ "$include_path_params" = "true" ]; then
flags="${flags} --include-path-params"
fi
echo "flags: $flags"

set -o pipefail

if [[ $fail_on_diff == "true" ]]; then
oasdiff diff "$base" "$revision" --fail-on-diff --format "$format"
if [ -n "$flags" ]; then
oasdiff diff "$base" "$revision" $flags
else
oasdiff diff "$base" "$revision" --format "$format"
oasdiff diff "$base" "$revision"
fi

0 comments on commit 74fbf19

Please sign in to comment.