Skip to content

Commit 0bd030d

Browse files
committed
fix: extra leading dash in the the operation id when comparing prefix groups
1 parent 17cfd7f commit 0bd030d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/components/compare/compare.utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function normalizeOperationIds(operations: ResolvedOperation[], apiBuilde
146146
operations.forEach(operation => {
147147
const normalizedOperationId = apiBuilder.createNormalizedOperationId?.(operation) ?? operation.operationId
148148
// '-' is a slugified slash in the middle of a normalizedOperationId that should also be removed for a proper matching during comparison
149-
normalizedOperationIdToOperation[takeSubstringIf(!!groupSlug, normalizedOperationId, groupSlug.length + '-'.length)] = operation
149+
normalizedOperationIdToOperation[removeGroupPrefixFromOperationId(normalizedOperationId, groupSlug)] = operation
150150
})
151151
return [Object.keys(normalizedOperationIdToOperation), normalizedOperationIdToOperation]
152152
}
@@ -268,13 +268,13 @@ export function createOperationChange(
268268
const impactedSummary = calculateImpactedSummary([changeSummary])
269269

270270
const currentOperationFields = current && {
271-
operationId: takeSubstringIf(!!currentGroup, current.operationId, removeFirstSlash(currentGroup ?? '').length),
271+
operationId: removeGroupPrefixFromOperationId(current.operationId, currentGroup ?? ''),
272272
apiKind: current.apiKind,
273273
metadata: getOperationMetadata(current),
274274
}
275275

276276
const previousOperationFields = previous && {
277-
previousOperationId: takeSubstringIf(!!previousGroup, previous.operationId, removeFirstSlash(previousGroup ?? '').length),
277+
previousOperationId: removeGroupPrefixFromOperationId(previous.operationId, previousGroup ?? ''),
278278
previousApiKind: previous.apiKind,
279279
previousMetadata: getOperationMetadata(previous),
280280
}
@@ -288,3 +288,7 @@ export function createOperationChange(
288288
...previousOperationFields,
289289
}
290290
}
291+
292+
export const removeGroupPrefixFromOperationId = (operationId: string, groupPrefix: string): string => {
293+
return takeSubstringIf(!!groupPrefix, operationId, removeFirstSlash(groupPrefix).length + '-'.length)
294+
}

test/prefix-groups.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
Editor,
2121
LocalRegistry,
2222
numberOfImpactedOperationsMatcher,
23+
operationChangesMatcher,
2324
} from './helpers'
2425
import { ANNOTATION_CHANGE_TYPE, BREAKING_CHANGE_TYPE, BUILD_TYPE, NON_BREAKING_CHANGE_TYPE } from '../src'
2526

@@ -101,6 +102,17 @@ describe('Prefix Groups test', () => {
101102
config: { files: [{ fileId: 'spec1.yaml' }, { fileId: 'spec2.yaml' }] },
102103
})
103104

105+
expect(result).toEqual(operationChangesMatcher([
106+
expect.objectContaining({
107+
previousOperationId: 'removed-get',
108+
}),
109+
expect.objectContaining({
110+
operationId: 'added-get',
111+
}),
112+
expect.objectContaining({
113+
operationId: 'changed1-get',
114+
}),
115+
]))
104116
expect(result).toEqual(changesSummaryMatcher({
105117
[BREAKING_CHANGE_TYPE]: 1,
106118
[NON_BREAKING_CHANGE_TYPE]: 1,

0 commit comments

Comments
 (0)