Skip to content

Commit 8c55202

Browse files
committed
feat: shift to another tool supporting OAS 3.1
1 parent 02b332b commit 8c55202

File tree

4 files changed

+170
-41
lines changed

4 files changed

+170
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Once you sign up or login, you can create a new API under your account and impor
3030
If you find something missing or incorrect please [open an issue](https://github.com/XeroAPI/Xero-OpenAPI/issues/new) or send us a pull request.
3131

3232
## API Diff Checking
33-
This repository includes automated API diff checking using [oasdiff](https://github.com/oasdiff/oasdiff) to detect breaking changes and modifications to the OpenAPI specifications.
33+
This repository includes automated API diff checking using [openapi-diff](https://github.com/OpenAPITools/openapi-diff) to detect breaking changes and modifications to the OpenAPI specifications.
3434

3535
### Quick Start
3636
```bash

scripts/api-diff/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API Diff Scripts
22

3-
This directory contains scripts for detecting and reporting API changes using [oasdiff](https://github.com/oasdiff/oasdiff).
3+
This directory contains scripts for detecting and reporting API changes using [openapi-diff](https://github.com/OpenAPITools/openapi-diff).
44

55
## Files
66

@@ -23,7 +23,7 @@ Main script that compares OpenAPI specifications against the master branch.
2323
```
2424

2525
**Environment Variables:**
26-
- `OASDIFF_DOCKER_IMAGE` - Docker image to use (default: `tufin/oasdiff:latest`)
26+
- `OPENAPI_DIFF_DOCKER_IMAGE` - Docker image to use (default: `openapitools/openapi-diff:latest`)
2727
- `BASE_BRANCH` - Branch to compare against (default: `origin/master`)
2828

2929
### `api-diff.test.sh`
@@ -58,12 +58,3 @@ The GitHub Actions workflow automatically adjusts its behavior based on branch n
5858
- Build will fail if breaking changes are detected
5959

6060
This allows developers to explicitly signal when they're working on breaking changes by including `breaking` in their branch name.
61-
62-
## Known Limitations
63-
64-
The oasdiff tool has some non-deterministic behavior due to unordered map iteration in Go:
65-
- **Error counts** (breaking changes) are consistent and reliable
66-
- **Warning counts** may vary by ~2-3% between runs on identical inputs
67-
- This is acceptable for CI purposes as breaking change detection remains accurate
68-
69-
For more details, see the [oasdiff documentation](https://github.com/oasdiff/oasdiff).

scripts/api-diff/api-diff.sh

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Script to check API diffs using oasdiff
3+
# Script to check API diffs using openapi-diff
44
# Usage: ./scripts/api-diff/api-diff.sh [--fail-on-breaking] [filename.yaml]
55
# Assumes you have Docker installed and the repo is checked out with master branch available
66

@@ -11,7 +11,7 @@ set -o pipefail # Catch errors in pipes
1111
cd "$(dirname "$0")/../.."
1212

1313
# Configuration
14-
DOCKER_IMAGE="${OASDIFF_DOCKER_IMAGE:-tufin/oasdiff:latest}"
14+
DOCKER_IMAGE="${OPENAPI_DIFF_DOCKER_IMAGE:-openapitools/openapi-diff:latest}"
1515
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
1616

1717
FAIL_ON_BREAKING=false
@@ -112,39 +112,19 @@ for file in $files; do
112112
continue
113113
fi
114114

115-
# Note: oasdiff has some non-deterministic behavior in change counts due to
116-
# unordered map iteration in Go. Error counts are consistent, but warning
117-
# counts may vary by ~2-3% between runs. This is a known limitation.
118-
119-
# Run oasdiff changelog
120-
echo "--- Changelog ---"
121-
set +e
122-
CHANGELOG_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" changelog --include-path-params /base/"$file" /current/"$file" 2>&1)
123-
CHANGELOG_EXIT=$?
124-
set -e
125-
126-
echo "$CHANGELOG_OUTPUT"
127-
128-
if [ $CHANGELOG_EXIT -eq 0 ]; then
129-
echo "✓ Changelog generated successfully"
130-
else
131-
echo "⚠ Could not generate changelog (exit code: $CHANGELOG_EXIT)"
132-
fi
133-
134-
# Run breaking changes check
135-
echo ""
136-
echo "--- Breaking changes check ---"
115+
# Run openapi-diff to check for changes and breaking changes
116+
echo "--- API Diff ---"
137117
set +e
138-
BREAKING_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" breaking --fail-on ERR --include-path-params /base/"$file" /current/"$file" 2>&1)
139-
BREAKING_EXIT=$?
118+
DIFF_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" /base/"$file" /current/"$file" --fail-on-incompatible 2>&1)
119+
DIFF_EXIT=$?
140120
set -e
141121

142-
echo "$BREAKING_OUTPUT"
122+
echo "$DIFF_OUTPUT"
143123

144-
if [ $BREAKING_EXIT -eq 0 ]; then
124+
if [ $DIFF_EXIT -eq 0 ]; then
145125
echo "✓ No breaking changes detected"
146126
else
147-
echo "⚠ Breaking changes detected (exit code: $BREAKING_EXIT)"
127+
echo "⚠ Breaking changes detected (exit code: $DIFF_EXIT)"
148128
BREAKING_CHANGES_FOUND=true
149129
FILES_WITH_BREAKING_CHANGES+=("$file")
150130
fi

scripts/api-diff/test-api-diff.sh

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
3+
# Script to check API diffs using openapi-diff
4+
# Usage: ./scripts/api-diff/test-api-diff.sh [--fail-on-breaking] [filename.yaml]
5+
# Assumes you have Docker installed and the repo is checked out with master branch available
6+
7+
set -e # Exit on error
8+
set -o pipefail # Catch errors in pipes
9+
10+
# Change to repo root
11+
cd "$(dirname "$0")/../.."
12+
13+
# Configuration
14+
DOCKER_IMAGE="${OPENAPI_DIFF_DOCKER_IMAGE:-openapitools/openapi-diff:latest}"
15+
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
16+
17+
FAIL_ON_BREAKING=false
18+
TARGET_FILE=""
19+
20+
# Parse arguments
21+
for arg in "$@"; do
22+
if [ "$arg" = "--fail-on-breaking" ]; then
23+
FAIL_ON_BREAKING=true
24+
elif [[ "$arg" == *.yaml ]]; then
25+
TARGET_FILE="$arg"
26+
fi
27+
done
28+
29+
echo "Starting API diff check..."
30+
31+
# Ensure we're in the repo root
32+
if [ ! -f "xero_accounting.yaml" ]; then
33+
echo "Error: Not in repo root or xero_accounting.yaml not found"
34+
exit 1
35+
fi
36+
37+
# Fetch master if not already done
38+
git fetch "${BASE_BRANCH%%/*}" "${BASE_BRANCH##*/}" 2>/dev/null || echo "Warning: Could not fetch ${BASE_BRANCH}"
39+
40+
# Create temp directory for master branch files (outside repo to avoid overlap with /current mount)
41+
TEMP_DIR=$(mktemp -d)
42+
trap "rm -rf $TEMP_DIR" EXIT
43+
44+
# Get list of xero*.yaml files (excluding any master_*.yaml files)
45+
if [ -n "$TARGET_FILE" ]; then
46+
# Single file specified
47+
if [ ! -f "$TARGET_FILE" ]; then
48+
echo "Error: File '$TARGET_FILE' not found"
49+
exit 1
50+
fi
51+
files="$TARGET_FILE"
52+
echo "Running diff for single file: $TARGET_FILE"
53+
else
54+
# All xero*.yaml files
55+
files=$(ls xero*.yaml 2>/dev/null | grep -v "^master_")
56+
if [ -z "$files" ]; then
57+
echo "No xero*.yaml files found"
58+
exit 1
59+
fi
60+
fi
61+
62+
BREAKING_CHANGES_FOUND=false
63+
FILES_WITH_BREAKING_CHANGES=()
64+
TOTAL_FILES=0
65+
PROCESSED_FILES=0
66+
67+
echo "========================================"
68+
echo "API Diff Summary"
69+
echo "Using Docker image: $DOCKER_IMAGE"
70+
echo "Base branch: $BASE_BRANCH"
71+
echo "========================================"
72+
73+
for file in $files; do
74+
TOTAL_FILES=$((TOTAL_FILES + 1))
75+
echo ""
76+
echo "========== $file =========="
77+
78+
# Get the file from master branch
79+
if ! git show "$BASE_BRANCH:$file" > "$TEMP_DIR/$file" 2>/dev/null; then
80+
echo "ℹ️ New file (does not exist in master branch)"
81+
continue
82+
fi
83+
84+
# Verify the temp file was created
85+
if [ ! -f "$TEMP_DIR/$file" ]; then
86+
echo "❌ Failed to create temp file"
87+
continue
88+
fi
89+
90+
# Note: openapi-diff provides deterministic results for change detection.
91+
# Both error and warning counts are consistent between runs.
92+
93+
# Run openapi-diff changelog
94+
echo "--- Changelog ---"
95+
set +e
96+
CHANGELOG_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" changelog --include-path-params /base/"$file" /current/"$file" 2>&1)
97+
CHANGELOG_EXIT=$?
98+
set -e
99+
100+
echo "$CHANGELOG_OUTPUT"
101+
102+
if [ $CHANGELOG_EXIT -eq 0 ]; then
103+
echo "✓ Changelog generated successfully"
104+
else
105+
echo "⚠ Could not generate changelog (exit code: $CHANGELOG_EXIT)"
106+
fi
107+
108+
# Run breaking changes check
109+
echo ""
110+
echo "--- Breaking changes check ---"
111+
set +e
112+
BREAKING_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" breaking --fail-on ERR --include-path-params /base/"$file" /current/"$file" 2>&1)
113+
BREAKING_EXIT=$?
114+
set -e
115+
116+
echo "$BREAKING_OUTPUT"
117+
118+
if [ $BREAKING_EXIT -eq 0 ]; then
119+
echo "✓ No breaking changes detected"
120+
else
121+
echo "⚠ Breaking changes detected (exit code: $BREAKING_EXIT)"
122+
BREAKING_CHANGES_FOUND=true
123+
FILES_WITH_BREAKING_CHANGES+=("$file")
124+
fi
125+
126+
PROCESSED_FILES=$((PROCESSED_FILES + 1))
127+
done
128+
129+
echo ""
130+
echo "========================================"
131+
echo "API Diff check completed"
132+
echo "Processed: $PROCESSED_FILES/$TOTAL_FILES files"
133+
echo "========================================"
134+
135+
# Summary
136+
if [ "$BREAKING_CHANGES_FOUND" = true ]; then
137+
echo ""
138+
echo "❌ Breaking changes detected in the following files:"
139+
for file in "${FILES_WITH_BREAKING_CHANGES[@]}"; do
140+
echo " - $file"
141+
# Output GitHub Actions annotation
142+
if [ -n "$GITHUB_ACTIONS" ]; then
143+
echo "::warning file=${file}::Breaking changes detected in this API spec file"
144+
fi
145+
done
146+
147+
if [ "$FAIL_ON_BREAKING" = true ]; then
148+
echo ""
149+
echo "Exiting with error due to breaking changes"
150+
exit 1
151+
else
152+
echo ""
153+
echo "Note: Not failing build (use --fail-on-breaking to fail on breaking changes)"
154+
fi
155+
else
156+
echo ""
157+
echo "✓ No breaking changes detected across all files"
158+
fi

0 commit comments

Comments
 (0)