Skip to content

Commit fd718d8

Browse files
authored
fix: add compatibility suite tests for $ref sibling properties in JSON schema (#35)
1 parent c5cbc14 commit fd718d8

File tree

5 files changed

+207
-100
lines changed

5 files changed

+207
-100
lines changed

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 () => {
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 } from '../../../../src'
44
import { diffsMatcher } from '../../../helper/matchers'
55

6+
const COMPONENTS_SCHEMAS = ['components', 'schemas']
7+
68
export function runCommonSchema31Tests(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: nonBreaking,
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: nonBreaking,
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: nonBreaking,
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: nonBreaking,
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: breaking,
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: breaking,
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: breaking,
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: breaking,
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: nonBreaking,
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: nonBreaking,
109+
}),
110+
]))
111+
})
59112
})
60113
}

0 commit comments

Comments
 (0)