Skip to content

Commit 7002877

Browse files
authored
fix: make ignoreLastPathSegment option of the path-segment-plural rule work for any number of segments (#2079)
1 parent 8b9036a commit 7002877

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

.changeset/cyan-points-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
---
4+
5+
Fixed an issue where the `ignoreLastPathSegment` option of the `path-segment-plural` rule had no effect if the path contained only one segment, resulting in an error.

.github/workflows/smoke.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
- name: Clear Yarn Cache
9393
run: yarn cache clean
9494
- run: |
95-
for i in {1..3}; do
96-
bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn" && break || sleep 5
95+
for i in {1..2}; do # workaround for yarn cache issue
96+
sleep 5 && bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn" && break
9797
done
9898
9999
run-smoke--yarn--node-22--redoc:
@@ -110,8 +110,8 @@ jobs:
110110
- name: Clear Yarn Cache
111111
run: yarn cache clean
112112
- run: |
113-
for i in {1..3}; do
114-
bash ./__tests__/smoke/run-smoke.sh "yarn add redoc ./redocly-cli.tgz" "yarn" && break || sleep 5
113+
for i in {1..2}; do # workaround for yarn cache issue
114+
sleep 5 && bash ./__tests__/smoke/run-smoke.sh "yarn add redoc ./redocly-cli.tgz" "yarn" && break
115115
done
116116
117117
run-smoke--yarn--node-20:
@@ -128,8 +128,8 @@ jobs:
128128
- name: Clear Yarn Cache
129129
run: yarn cache clean
130130
- run: |
131-
for i in {1..3}; do
132-
bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn" && break || sleep 5
131+
for i in {1..2}; do # workaround for yarn cache issue
132+
sleep 5 && bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn" && break
133133
done
134134
135135
run-smoke--yarn--node-20--redoc:
@@ -146,8 +146,8 @@ jobs:
146146
- name: Clear Yarn Cache
147147
run: yarn cache clean
148148
- run: |
149-
for i in {1..3}; do
150-
bash ./__tests__/smoke/run-smoke.sh "yarn add redoc ./redocly-cli.tgz" "yarn" && break || sleep 5
149+
for i in {1..2}; do # workaround for yarn cache issue
150+
sleep 5 && bash ./__tests__/smoke/run-smoke.sh "yarn add redoc ./redocly-cli.tgz" "yarn" && break
151151
done
152152
153153
run-smoke--pnpm--node-22:
@@ -195,7 +195,7 @@ jobs:
195195
node-version: 22
196196
- name: Run Smoke Tests
197197
run: |
198-
Start-Sleep -Seconds 20
198+
Start-Sleep -Seconds 20 # workaround for yarn cache issue
199199
for ($i = 1; $i -le 3; $i++) {
200200
try {
201201
bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz --no-lockfile --network-timeout 100000" "yarn"
@@ -234,7 +234,7 @@ jobs:
234234
node-version: 20
235235
- name: Run Smoke Tests
236236
run: |
237-
Start-Sleep -Seconds 20
237+
Start-Sleep -Seconds 20 # workaround for yarn cache issue
238238
for ($i = 1; $i -le 3; $i++) {
239239
try {
240240
bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz --no-lockfile --network-timeout 100000" "yarn"

__tests__/lint/path-segment-plural/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ paths:
3232
get:
3333
operationId: status id
3434
summary: get first status
35+
/health: # should be ignored as it's the last segment and the ignoreLastPathSegment option is set to true
36+
get:
37+
operationId: status
38+
summary: get health status

__tests__/smoke-plugins/run-smoke.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ npm i redocly-cli.tgz -g
1616

1717
# Actual smoke test - executing the command provided as the second argument
1818
npm run redocly-version
19-
npm run redocly-lint
19+
npm run redocly-lint

__tests__/smoke/run-smoke.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ $2 redocly-respect
2121

2222
# Check for broken styles when building docs (related issue: https://github.com/Redocly/redocly-cli/issues/1073)
2323
echo "Checking docs for issues..."
24-
diff pre-built/redoc.html redoc-static.html
24+
diff pre-built/redoc.html redoc-static.html -u
2525
echo "✅ Docs built correctly."
2626

2727
# Check for broken $refs (or other issues) in the split files, especially on Windows (it will fail on a difference)
2828
echo "Checking split files for issues..."
29-
diff -r pre-split output/split
30-
echo "✅ Files split correctly."
29+
diff -r pre-split output/split -u
30+
echo "✅ Files split correctly."

packages/core/src/rules/common/path-segment-plural.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
1313
if (pathKey.startsWith('/')) {
1414
const pathSegments = pathKey.split('/');
1515
pathSegments.shift();
16-
if (ignoreLastPathSegment && pathSegments.length > 1) {
16+
if (ignoreLastPathSegment && pathSegments.length > 0) {
1717
pathSegments.pop();
1818
}
1919

0 commit comments

Comments
 (0)