Skip to content

Commit 582bb64

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/develop' into feature/performance-optimization
2 parents 85588a0 + fd718d8 commit 582bb64

File tree

9 files changed

+369
-115
lines changed

9 files changed

+369
-115
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"update-lock-file": "update-lock-file @netcracker"
2828
},
2929
"dependencies": {
30-
"@netcracker/qubership-apihub-api-unifier": "2.3.0",
30+
"@netcracker/qubership-apihub-api-unifier": "dev",
3131
"@netcracker/qubership-apihub-json-crawl": "1.0.4",
3232
"fast-equals": "4.0.3"
3333
},
3434
"devDependencies": {
35-
"@netcracker/qubership-apihub-compatibility-suites": "2.2.0",
35+
"@netcracker/qubership-apihub-compatibility-suites": "dev",
3636
"@netcracker/qubership-apihub-graphapi": "1.0.8",
3737
"@netcracker/qubership-apihub-npm-gitflow": "3.1.0",
3838
"@types/jest": "29.5.11",

src/openapi/openapi3.rules.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,20 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
390390
'/*': operationAnnotationRule,
391391
}
392392

393+
const pathItemObjectRules = (options: OpenApi3RulesOptions): CompareRules => ({
394+
$: pathChangeClassifyRule,
395+
mapping: options.mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver,
396+
'/description': { $: allAnnotation },
397+
'/parameters': {
398+
$: [nonBreaking, breaking, breaking],
399+
mapping: paramMappingResolver(1),
400+
...parametersRules,
401+
},
402+
'/servers': serversRules,
403+
'/summary': { $: allAnnotation },
404+
'/*': operationRule,
405+
})
406+
393407
const componentsRule: CompareRules = {
394408
$: allNonBreaking,
395409
[START_NEW_COMPARE_SCOPE_RULE]: COMPARE_SCOPE_COMPONENTS,
@@ -414,6 +428,10 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
414428
...requestSchemaRules,
415429
}),
416430
},
431+
'/pathItems': {
432+
$: [nonBreaking, breaking, breaking],
433+
'/*': pathItemObjectRules(options),
434+
},
417435
'/securitySchemes': {
418436
[AGGREGATE_DIFFS_HERE_RULE]: true,
419437
$: [breaking, nonBreaking, breaking],
@@ -441,19 +459,7 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
441459
'/paths': {
442460
$: allUnclassified,
443461
mapping: options.mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver,
444-
'/*': {
445-
$: pathChangeClassifyRule,
446-
mapping: options.mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver,
447-
'/description': { $: allAnnotation },
448-
'/parameters': {
449-
$: [nonBreaking, breaking, breaking],
450-
mapping: paramMappingResolver(1),
451-
...parametersRules,
452-
},
453-
'/servers': serversRules,
454-
'/summary': { $: allAnnotation },
455-
'/*': operationRule,
456-
},
462+
'/*': pathItemObjectRules(options),
457463
},
458464
'/components': componentsRule,
459465
'/security': {

test/compatibility-suites/openapi/general-operation-parameters.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,59 @@ describe('Openapi3 General Operation Parameters', () => {
767767
]))
768768
})
769769
})
770+
771+
const PATH_ITEM_PATH = [
772+
'components',
773+
'pathItems',
774+
'UserOps',
775+
]
776+
777+
describe('Openapi3.1 PathItems', () => {
778+
test('Add method in path item', async () => {
779+
const testId = 'add-method-in-path-item'
780+
const result = await compareFiles(SUITE_ID, testId)
781+
expect(result).toEqual(diffsMatcher([
782+
expect.objectContaining({
783+
action: DiffAction.add,
784+
afterDeclarationPaths: [[...PATH_ITEM_PATH, 'post']],
785+
type: nonBreaking,
786+
}),
787+
]))
788+
})
789+
790+
test('Remove unused method in path item', async () => {
791+
const testId = 'remove-unused-method-in-path-item'
792+
const result = await compareFiles(SUITE_ID, testId)
793+
expect(result).toEqual([])
794+
})
795+
796+
test('Add unused method in path item', async () => {
797+
const testId = 'add-unused-method-in-path-item'
798+
const result = await compareFiles(SUITE_ID, testId)
799+
expect(result).toEqual([])
800+
})
801+
802+
test('Remove method in path item', async () => {
803+
const testId = 'remove-method-in-path-item'
804+
const result = await compareFiles(SUITE_ID, testId)
805+
expect(result).toEqual(diffsMatcher([
806+
expect.objectContaining({
807+
action: DiffAction.remove,
808+
beforeDeclarationPaths: [[...PATH_ITEM_PATH, 'post']],
809+
type: breaking,
810+
}),
811+
]))
812+
})
813+
814+
test('Replace inline path item to ref', async () => {
815+
const testId = 'replace-inline-path-item-to-ref'
816+
const result = await compareFiles(SUITE_ID, testId)
817+
expect(result).toEqual([])
818+
})
819+
820+
test('Replace ref path item to inline', async () => {
821+
const testId = 'replace-ref-path-item-to-inline'
822+
const result = await compareFiles(SUITE_ID, testId)
823+
expect(result).toEqual([])
824+
})
825+
})

test/compatibility-suites/openapi/response-body-schema.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,3 +1636,4 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16361636
describe('Openapi31 ResponseBody.Schema', () => {
16371637
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
16381638
})
1639+

test/compatibility-suites/openapi/templates/reference-object-31.template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function runReferenceObjectTests(suiteId: string, refPath: JsonPath, comp
5858

5959
test(`Change referenced ${overridenField} when overridden exists`, async () => {
6060
const testId = `change-referenced-${overridenField}-when-overridden-exists`
61-
const result = await compareFiles(suiteId, testId)
62-
expect(result.length).toEqual(0)
61+
const diffs = await compareFiles(suiteId, testId)
62+
expect(diffs).toBeEmpty()
6363
})
6464
}
Lines changed: 101 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,113 @@
11
import { compareFiles } from '../../utils'
22
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
3-
import { breaking, DiffAction, nonBreaking } from '../../../../src'
3+
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../../src'
44
import { diffsMatcher } from '../../../helper/matchers'
55

6+
const COMPONENTS_SCHEMAS = ['components', 'schemas']
7+
68
export function runCommonResponseSchema31Tests(suiteId: string, commonPath: JsonPath): void {
7-
test('Add union type', async () => {
8-
const testId = 'add-union-type'
9-
const result = await compareFiles(suiteId, testId)
10-
expect(result).toEqual(diffsMatcher([
11-
expect.objectContaining({
12-
action: DiffAction.add,
13-
afterDeclarationPaths: [[...commonPath, 'type', 1]],
14-
type: breaking,
15-
}),
16-
]))
17-
})
9+
describe('Union type', () => {
10+
test('Add union type', async () => {
11+
const testId = 'add-union-type'
12+
const result = await compareFiles(suiteId, testId)
13+
expect(result).toEqual(diffsMatcher([
14+
expect.objectContaining({
15+
action: DiffAction.add,
16+
afterDeclarationPaths: [[...commonPath, 'type', 1]],
17+
type: breaking,
18+
}),
19+
]))
20+
})
1821

19-
test('Add null to union type', async () => {
20-
const testId = 'add-null-to-union-type'
21-
const result = await compareFiles(suiteId, testId)
22-
expect(result).toEqual(diffsMatcher([
23-
expect.objectContaining({
24-
action: DiffAction.add,
25-
afterDeclarationPaths: [[...commonPath, 'type', 2]],
26-
type: breaking,
27-
}),
28-
]))
29-
})
22+
test('Add null to union type', async () => {
23+
const testId = 'add-null-to-union-type'
24+
const result = await compareFiles(suiteId, testId)
25+
expect(result).toEqual(diffsMatcher([
26+
expect.objectContaining({
27+
action: DiffAction.add,
28+
afterDeclarationPaths: [[...commonPath, 'type', 2]],
29+
type: breaking,
30+
}),
31+
]))
32+
})
3033

31-
test('Remove union type', async () => {
32-
const testId = 'remove-union-type'
33-
const result = await compareFiles(suiteId, testId)
34-
expect(result).toEqual(diffsMatcher([
35-
expect.objectContaining({
36-
action: DiffAction.remove,
37-
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
38-
type: nonBreaking,
39-
}),
40-
]))
41-
})
34+
test('Remove union type', async () => {
35+
const testId = 'remove-union-type'
36+
const result = await compareFiles(suiteId, testId)
37+
expect(result).toEqual(diffsMatcher([
38+
expect.objectContaining({
39+
action: DiffAction.remove,
40+
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
41+
type: nonBreaking,
42+
}),
43+
]))
44+
})
4245

43-
test('Remove null from union type', async () => {
44-
const testId = 'remove-null-from-union-type'
45-
const result = await compareFiles(suiteId, testId)
46-
expect(result).toEqual(diffsMatcher([
47-
expect.objectContaining({
48-
action: DiffAction.remove,
49-
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
50-
type: nonBreaking,
51-
}),
52-
]))
46+
test('Remove null from union type', async () => {
47+
const testId = 'remove-null-from-union-type'
48+
const result = await compareFiles(suiteId, testId)
49+
expect(result).toEqual(diffsMatcher([
50+
expect.objectContaining({
51+
action: DiffAction.remove,
52+
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
53+
type: nonBreaking,
54+
}),
55+
]))
56+
})
57+
58+
test('Reorder types in union type', async () => {
59+
const testId = 'reorder-types-in-union-type'
60+
const result = await compareFiles(suiteId, testId)
61+
expect(result).toBeEmpty()
62+
})
5363
})
5464

55-
test('Reorder types in union type', async () => {
56-
const testId = 'reorder-types-in-union-type'
57-
const result = await compareFiles(suiteId, testId)
58-
expect(result).toBeEmpty()
65+
describe('$ref sibling properties', () => {
66+
test('Add sibling description for ref', async () => {
67+
const testId = 'add-sibling-description-for-ref'
68+
const result = await compareFiles(suiteId, testId)
69+
expect(result).toEqual(diffsMatcher([
70+
expect.objectContaining({
71+
action: DiffAction.replace,
72+
afterDeclarationPaths: [[...commonPath, 'description']],
73+
beforeDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Pet', 'description']],
74+
type: annotation,
75+
}),
76+
]))
77+
})
78+
79+
test('Change sibling enum for ref', async () => {
80+
const testId = 'change-sibling-enum-for-ref'
81+
const diffs = await compareFiles(suiteId, testId)
82+
expect(diffs).toBeEmpty()
83+
})
84+
85+
test('Change referenced enum when sibling exists for ref', async () => {
86+
const testId = 'change-referenced-enum-when-sibling-exists-for-ref'
87+
const result = await compareFiles(suiteId, testId)
88+
expect(result).toEqual(diffsMatcher([
89+
expect.objectContaining({
90+
action: DiffAction.add,
91+
afterDeclarationPaths: [
92+
[...COMPONENTS_SCHEMAS, 'Color', 'enum', 1],
93+
[...commonPath, 'enum', 1],
94+
],
95+
type: risky,
96+
}),
97+
]))
98+
})
99+
100+
test('Remove sibling maxLength for ref', async () => {
101+
const testId = 'remove-sibling-maxLength-for-ref'
102+
const result = await compareFiles(suiteId, testId)
103+
expect(result).toEqual(diffsMatcher([
104+
expect.objectContaining({
105+
action: DiffAction.replace,
106+
beforeDeclarationPaths: [[...commonPath, 'maxLength']],
107+
afterDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Color', 'maxLength']],
108+
type: breaking,
109+
}),
110+
]))
111+
})
59112
})
60113
}

test/compatibility-suites/openapi/templates/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ export function runCommonSchemaTests(suiteId: string, commonPath: JsonPath): voi
11011101
test('Update definition of free-form object', async () => {
11021102

11031103
const testId = 'update-definition-of-free-form-object'
1104-
const result = await compareFiles(suiteId, testId)
1105-
expect(result.length).toEqual(0)
1104+
const diffs = await compareFiles(suiteId, testId)
1105+
expect(diffs).toBeEmpty()
11061106
})
11071107

11081108
test('Add non-boolean additionalProperties', async () => {

0 commit comments

Comments
 (0)