Skip to content

Commit d9e29fc

Browse files
authored
fix: add compatibility suite tests for OAS 3.1 (#22)
1 parent 159363a commit d9e29fc

File tree

12 files changed

+321
-7
lines changed

12 files changed

+321
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"fast-equals": "4.0.3"
3333
},
3434
"devDependencies": {
35-
"@netcracker/qubership-apihub-compatibility-suites": "2.0.3",
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",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { runCommonSchemaTests } from './templates/schema'
2+
import { runCommonSchema31Tests } from './templates/schema31'
23

34
const SUITE_ID = 'parameters-schema'
45

@@ -14,3 +15,6 @@ const PARAMETERS_SCHEMA_PATH = [
1415
describe('Openapi3 Parameters Schema', () => {
1516
runCommonSchemaTests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
1617
})
18+
describe('Openapi31 Parameters Schema', () => {
19+
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
20+
})

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { runCommonSchemaTests } from './templates/schema'
2+
import { runCommonSchema31Tests } from './templates/schema31'
23

34
const SUITE_ID = 'request-body-schema'
45

@@ -14,5 +15,8 @@ const REQUEST_SCHEMA_PATH = [
1415

1516
describe('Openapi3 Request Body Schema', () => {
1617
runCommonSchemaTests(SUITE_ID, REQUEST_SCHEMA_PATH)
18+
})
1719

20+
describe('Openapi31 Request Body Schema', () => {
21+
runCommonSchema31Tests(SUITE_ID, REQUEST_SCHEMA_PATH)
1822
})

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { compareFiles, compareFilesWithMerge, TEST_DEFAULTS_DECLARATION_PATHS }
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../src'
44
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
5+
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
56

67
const SUITE_ID = 'response-body-schema'
78

@@ -137,7 +138,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
137138
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
138139
type: nonBreaking,
139140
}),
140-
]
141+
],
141142
))
142143
})
143144

@@ -304,7 +305,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
304305
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minLength']],
305306
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
306307
type: breaking,
307-
})
308+
}),
308309
]))
309310
})
310311

@@ -693,7 +694,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
693694
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
694695
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
695696
type: nonBreaking,
696-
})
697+
}),
697698
]))
698699
})
699700

@@ -738,7 +739,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
738739
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
739740
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'minItems']],
740741
type: breaking,
741-
})
742+
}),
742743
]))
743744
})
744745

@@ -1020,7 +1021,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
10201021
beforeDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
10211022
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minProperties']],
10221023
type: nonBreaking,
1023-
})
1024+
}),
10241025
]))
10251026
})
10261027

@@ -1065,7 +1066,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
10651066
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'minProperties']],
10661067
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
10671068
type: breaking,
1068-
})
1069+
}),
10691070
]))
10701071
})
10711072

@@ -1628,3 +1629,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16281629
]))
16291630
})
16301631
})
1632+
1633+
describe('Openapi31 ResponseBody.Schema', () => {
1634+
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
1635+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
2+
3+
const SUITE_ID = 'response-headers-schema'
4+
5+
const RESPONSE_HEADERS_SCHEMA_PATH = [
6+
'paths',
7+
'/path1',
8+
'post',
9+
'responses',
10+
'200',
11+
'headers',
12+
'X-Header-1',
13+
'schema',
14+
]
15+
16+
describe('Openapi31 ResponseHeaders.Schema', () => {
17+
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_HEADERS_SCHEMA_PATH)
18+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { compareFiles } from '../../utils'
2+
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
3+
import { breaking, DiffAction, nonBreaking } from '../../../../src'
4+
import { diffsMatcher } from '../../../helper/matchers'
5+
6+
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+
})
18+
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+
})
30+
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+
})
42+
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+
]))
53+
})
54+
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()
59+
})
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { compareFiles } from '../../utils'
2+
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
3+
import { breaking, DiffAction, nonBreaking } from '../../../../src'
4+
import { diffsMatcher } from '../../../helper/matchers'
5+
6+
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+
})
18+
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+
})
30+
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+
})
42+
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+
]))
53+
})
54+
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()
59+
})
60+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"openapi": "3.1.0",
3+
"paths": {
4+
"/example": {
5+
"post": {
6+
"responses": {
7+
"200": {
8+
"description": "OK",
9+
"content": {
10+
"application/json": {
11+
"schema": {
12+
"type": [
13+
"string",
14+
"number"
15+
]
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"openapi": "3.1.0",
3+
"paths": {
4+
"/example": {
5+
"post": {
6+
"responses": {
7+
"200": {
8+
"description": "OK",
9+
"content": {
10+
"application/json": {
11+
"schema": {
12+
"anyOf": [
13+
{
14+
"type": "string"
15+
},
16+
{
17+
"type": "number"
18+
}
19+
]
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"openapi": "3.1.0",
3+
"paths": {
4+
"/example": {
5+
"post": {
6+
"responses": {
7+
"200": {
8+
"description": "OK",
9+
"content": {
10+
"application/json": {
11+
"schema": {
12+
"allOf": [
13+
{
14+
"allOf": [
15+
{
16+
"type": "string"
17+
}
18+
]
19+
},
20+
{
21+
"allOf": [
22+
{
23+
"type": "null"
24+
},
25+
{
26+
"type": "integer"
27+
},
28+
{
29+
"type": "boolean"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)