Skip to content

Commit b8e8b70

Browse files
committed
fix: Review
1 parent c3b7d23 commit b8e8b70

File tree

6 files changed

+10
-149
lines changed

6 files changed

+10
-149
lines changed

src/core/compare.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,24 @@ const cleanUpRecursive = (ctx: NodeContext): NodeContext => {
156156
}
157157

158158
export const getOrCreateChildDiffAdd = (diffUniquenessCache: EvaluationCacheService, childCtx: CompareContext) => {
159-
const addDiffEntry = diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add], DiffAdd>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add], () => {
159+
const diff = diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add], DiffAdd>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add], () => {
160160
return diffFactory.added(childCtx)
161161
}, {} as DiffAdd, (result, guard) => {
162162
Object.assign(guard, result)
163163
return guard
164164
})
165165

166-
return createDiffEntry(childCtx, addDiffEntry)
166+
return createDiffEntry(childCtx, diff)
167167
}
168168

169169
export const getOrCreateChildDiffRemove = (diffUniquenessCache: EvaluationCacheService, childCtx: CompareContext) => {
170-
const getOrCreateDiffEntry = diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.remove], DiffRemove>([childCtx.before.value, buildPathsIdentifier(childCtx.before.declarativePaths), childCtx.scope, DiffAction.remove], () => {
170+
const diff = diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.remove], DiffRemove>([childCtx.before.value, buildPathsIdentifier(childCtx.before.declarativePaths), childCtx.scope, DiffAction.remove], () => {
171171
return diffFactory.removed(childCtx)
172172
}, {} as DiffRemove, (result, guard) => {
173173
Object.assign(guard, result)
174174
return guard
175175
})
176-
return createDiffEntry(childCtx, getOrCreateDiffEntry)
176+
return createDiffEntry(childCtx, diff)
177177
}
178178

179179
const adaptValues = (beforeJso: JsonNode, beforeKey: PropertyKey, afterJso: JsonNode, afterKey: PropertyKey, adapter: AdapterResolver[] | undefined, options: InternalCompareOptions) => {

test/bugs.test.ts

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@ import wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeAfter from './
4242
import shouldNotMissRemoveDiffForEnumEntryInOneOfBefore from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/before.json'
4343
import shouldNotMissRemoveDiffForEnumEntryInOneOfAfter from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/after.json'
4444

45-
import shouldCalculateDiffsCorrectlyInOneOfBefore from './helper/resources/should-calculate-diffs-correctly-in-oneOf/before.json'
46-
import shouldCalculateDiffsCorrectlyInOneOfAfter from './helper/resources/should-calculate-diffs-correctly-in-oneOf/after.json'
47-
48-
import shouldCalculateDiffsCorrectlyInAnyOfBefore from './helper/resources/should-calculate-diffs-correctly-in-anyOf/before.json'
49-
import shouldCalculateDiffsCorrectlyInAnyOfAfter from './helper/resources/should-calculate-diffs-correctly-in-anyOf/after.json'
45+
import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerBefore from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/before.json'
46+
import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerAfter from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/after.json'
5047

5148
import { diffsMatcher } from './helper/matchers'
5249
import { TEST_DIFF_FLAG, TEST_ORIGINS_FLAG } from './helper'
@@ -278,39 +275,12 @@ describe('Real Data', () => {
278275
})
279276

280277
// check diffUniquenessCache works correctly for oneOf
281-
it('should calculate diffs correctly in oneOf', () => {
282-
const before: any = shouldCalculateDiffsCorrectlyInOneOfBefore
283-
const after: any = shouldCalculateDiffsCorrectlyInOneOfAfter
284-
const { diffs } = apiDiff(before, after, OPTIONS)
285-
286-
expect(diffs).toEqual(diffsMatcher([
287-
expect.objectContaining({
288-
action: DiffAction.add,
289-
afterValue: "eventType",
290-
afterNormalizedValue: "eventType",
291-
afterDeclarationPaths: [[
292-
"paths",
293-
"/path1",
294-
"get",
295-
"responses",
296-
"200",
297-
"content",
298-
"application/json",
299-
"schema",
300-
"required",
301-
0
302-
]],
303-
type: nonBreaking,
304-
}),
305-
]))
306-
})
307-
308-
// check diffUniquenessCache works correctly for anyOf
309-
it('should calculate diffs correctly in anyOf', () => {
310-
const before: any = shouldCalculateDiffsCorrectlyInAnyOfBefore
311-
const after: any = shouldCalculateDiffsCorrectlyInAnyOfAfter
278+
it('should report single diff when required property is changed for the combiner', () => {
279+
const before: any = shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerBefore
280+
const after: any = shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerAfter
312281
const { diffs } = apiDiff(before, after, OPTIONS)
313282

283+
expect(diffs).toHaveLength(1)
314284
expect(diffs).toEqual(diffsMatcher([
315285
expect.objectContaining({
316286
action: DiffAction.add,

test/helper/resources/should-calculate-diffs-correctly-in-oneOf/after.json

Lines changed: 0 additions & 56 deletions
This file was deleted.

test/helper/resources/should-calculate-diffs-correctly-in-oneOf/before.json

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)