Skip to content

Commit 289fb2e

Browse files
committed
chore: merge branch 'develop' into feature/performance-optimization
2 parents f786099 + 99b6df0 commit 289fb2e

File tree

4 files changed

+168
-2
lines changed

4 files changed

+168
-2
lines changed

src/core/compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const cleanUpRecursive = (ctx: NodeContext): NodeContext => {
164164
}
165165

166166
export const getOrCreateChildDiffAdd = (diffUniquenessCache: EvaluationCacheService, childCtx: CompareContext) => {
167-
return diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add], DiffEntry<DiffAdd>>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add], () => {
167+
return diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add, PropertyKey], DiffEntry<DiffAdd>>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add, childCtx.mergeKey], () => {
168168
return diffFactory.added(childCtx)
169169
}, {} as DiffEntry<DiffAdd>, (result, guard) => {
170170
Object.assign(guard, result)

test/bugs.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { annotation, apiDiff, ClassifierType, CompareOptions, DiffAction, nonBreaking, unclassified } from '../src'
1+
import { annotation, apiDiff, breaking, ClassifierType, CompareOptions, DiffAction, nonBreaking, unclassified } from '../src'
22
import offeringQualificationBefore from './helper/resources/api-v2-offeringqualification-qualification-post/before.json'
33
import offeringQualificationAfter from './helper/resources/api-v2-offeringqualification-qualification-post/after.json'
44
import readDefaultValueOfRequiredBefore from './helper/resources/read-default-value-of-required-field/before.json'
@@ -30,6 +30,9 @@ import spearedParamsAfter from './helper/resources/speared-parameters/after.json
3030
import wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeBefore from './helper/resources/wildcard-content-schema-media-type-combined-with-specific-media-type/before.json'
3131
import wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeAfter from './helper/resources/wildcard-content-schema-media-type-combined-with-specific-media-type/after.json'
3232

33+
import shouldNotMissRemoveDiffForEnumEntryInOneOfBefore from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/before.json'
34+
import shouldNotMissRemoveDiffForEnumEntryInOneOfAfter from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/after.json'
35+
3336
import { diffsMatcher } from './helper/matchers'
3437
import { TEST_DIFF_FLAG, TEST_ORIGINS_FLAG } from './helper'
3538
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_NOTHING } from '@netcracker/qubership-apihub-api-unifier'
@@ -227,4 +230,35 @@ describe('Real Data', () => {
227230
}),
228231
]))
229232
})
233+
234+
it('should not miss remove diff for enum entry in oneOf', () => {
235+
const before: any = shouldNotMissRemoveDiffForEnumEntryInOneOfBefore
236+
const after: any = shouldNotMissRemoveDiffForEnumEntryInOneOfAfter
237+
const { merged } = apiDiff(before, after, OPTIONS)
238+
239+
expect(
240+
Object.values((merged as any).paths['/path1'].post.requestBody.content['application/json'].schema.oneOf[1].properties.scope.items.enum[TEST_DIFF_FLAG])
241+
).toEqual(diffsMatcher([
242+
expect.objectContaining({
243+
beforeValue: 'query',
244+
action: DiffAction.remove,
245+
type: breaking,
246+
}),
247+
expect.objectContaining({
248+
beforeValue: 'subscription',
249+
action: DiffAction.remove,
250+
type: breaking,
251+
}),
252+
expect.objectContaining({
253+
afterValue: 'argument',
254+
action: DiffAction.add,
255+
type: nonBreaking,
256+
}),
257+
expect.objectContaining({
258+
afterValue: 'annotation',
259+
action: DiffAction.add,
260+
type: nonBreaking,
261+
}),
262+
]))
263+
})
230264
})
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "test",
5+
"version": "0.1.0"
6+
},
7+
"paths": {
8+
"/path1": {
9+
"post": {
10+
"requestBody": {
11+
"content": {
12+
"application/json": {
13+
"schema": {
14+
"oneOf": [
15+
{
16+
"type": "object",
17+
"title": "SearchRestParams",
18+
"properties": {
19+
"apiType": {
20+
"type": "string",
21+
"enum": [
22+
"rest"
23+
]
24+
},
25+
"scope": {
26+
"type": "array",
27+
"items": {
28+
"type": "string",
29+
"enum": [
30+
"request"
31+
]
32+
}
33+
}
34+
}
35+
},
36+
{
37+
"type": "object",
38+
"title": "SearchGQLParams",
39+
"properties": {
40+
"scope": {
41+
"type": "array",
42+
"items": {
43+
"type": "string",
44+
"enum": [
45+
"argument",
46+
"annotation"
47+
]
48+
}
49+
}
50+
}
51+
}
52+
]
53+
}
54+
}
55+
}
56+
},
57+
"responses": {
58+
"200": {
59+
"description": "Success",
60+
"content": {}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "test",
5+
"version": "0.1.0"
6+
},
7+
"paths": {
8+
"/path1": {
9+
"post": {
10+
"requestBody": {
11+
"content": {
12+
"application/json": {
13+
"schema": {
14+
"oneOf": [
15+
{
16+
"type": "object",
17+
"title": "SearchRestParams",
18+
"properties": {
19+
"apiType": {
20+
"type": "string",
21+
"enum": [
22+
"Rest"
23+
]
24+
},
25+
"scope": {
26+
"type": "array",
27+
"items": {
28+
"type": "string",
29+
"enum": [
30+
"request"
31+
]
32+
}
33+
}
34+
}
35+
},
36+
{
37+
"type": "object",
38+
"title": "SearchGQLParams",
39+
"properties": {
40+
"scope": {
41+
"type": "array",
42+
"items": {
43+
"type": "string",
44+
"enum": [
45+
"query",
46+
"subscription"
47+
]
48+
}
49+
}
50+
}
51+
}
52+
]
53+
}
54+
}
55+
}
56+
},
57+
"responses": {
58+
"200": {
59+
"description": "Success",
60+
"content": {}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)