Skip to content

Commit 1a6e2a0

Browse files
authored
fix: add compatibility suite tests for description and summary override via Reference Object for OAS 3.1 (#26)
1 parent 5d717af commit 1a6e2a0

File tree

9 files changed

+154
-52
lines changed

9 files changed

+154
-52
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.2.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.1.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",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
2+
3+
const SUITE_ID = 'headers'
4+
const HEADER_PATH = ['paths', '/path1', 'get', 'responses', '200', 'headers', 'X-Rate-Limit']
5+
const COMPONENTS_HEADER_PATH = ['components', 'headers', 'X-Rate-Limit']
6+
7+
describe('Reference object. Headers. Description fields in ref object', () => {
8+
runRefObjectDescriptionTests(SUITE_ID, HEADER_PATH, COMPONENTS_HEADER_PATH)
9+
})

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles, TEST_DEFAULTS_DECLARATION_PATHS } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, deprecated, DiffAction, nonBreaking, unclassified } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'operation-parameters'
67

@@ -338,7 +339,6 @@ describe('Openapi3 Operation Parameters', () => {
338339
}),
339340
]))
340341
})
341-
342342

343343
// TODO: fixme
344344
test.skip('Mark primitive parameter as exploded', async () => {
@@ -724,3 +724,8 @@ describe('Openapi3 Operation Parameters', () => {
724724
})
725725
})
726726
})
727+
728+
const COMPONENTS_OPERATION_PARAMETER_PATH = ['components', 'parameters', 'status']
729+
describe('Reference object. Operation parameters. Description fields in ref object', () => {
730+
runRefObjectDescriptionTests(SUITE_ID, [...OPERATION_PARAMETERS_PATH, 0], COMPONENTS_OPERATION_PARAMETER_PATH)
731+
})

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests, runRefObjectSummaryTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'parameters-examples'
67

7-
const PARAMETERS_EXAMPLES_PATH = [
8-
'paths',
9-
'/path1',
10-
'post',
11-
'parameters',
12-
0,
13-
'examples',
14-
]
8+
const PARAMETERS_EXAMPLES_PATH = ['paths', '/path1', 'post', 'parameters', 0, 'examples']
159

1610
describe('Openapi3 Parameters Examples', () => {
1711

@@ -168,3 +162,10 @@ describe('Openapi3 Parameters Examples', () => {
168162
]))
169163
})
170164
})
165+
166+
const COMPONENTS_PARAMETERS_EXAMPLE_PATH = ['components', 'examples', 'ex1']
167+
describe('Reference object. Parameters examples. Description and Summary fields in ref object', () => {
168+
runRefObjectDescriptionTests(SUITE_ID, [...PARAMETERS_EXAMPLES_PATH, 'ex1'], COMPONENTS_PARAMETERS_EXAMPLE_PATH)
169+
runRefObjectSummaryTests(SUITE_ID, [...PARAMETERS_EXAMPLES_PATH, 'ex1'], COMPONENTS_PARAMETERS_EXAMPLE_PATH)
170+
})
171+

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'request-body-examples'
67

7-
const REQUEST_BODY_PATH = [
8-
'paths',
9-
'/path1',
10-
'post',
11-
'requestBody',
12-
]
8+
const REQUEST_BODY_CONTENT_EXAMPLES_PATH = ['paths', '/path1', 'post', 'requestBody', 'content', 'application/json', 'examples']
139

1410
describe('Openapi3 Request Body Examples', () => {
1511

@@ -19,7 +15,7 @@ describe('Openapi3 Request Body Examples', () => {
1915
expect(result).toEqual(diffsMatcher([
2016
expect.objectContaining({
2117
action: DiffAction.add,
22-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1']],
18+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1']],
2319
type: annotation,
2420
}),
2521
]))
@@ -31,7 +27,7 @@ describe('Openapi3 Request Body Examples', () => {
3127
expect(result).toEqual(diffsMatcher([
3228
expect.objectContaining({
3329
action: DiffAction.add,
34-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example2']],
30+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example2']],
3531
type: annotation,
3632
}),
3733
]))
@@ -43,8 +39,8 @@ describe('Openapi3 Request Body Examples', () => {
4339
expect(result).toEqual(diffsMatcher([
4440
expect.objectContaining({
4541
action: DiffAction.replace,
46-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'value']],
47-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'value']],
42+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'value']],
43+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'value']],
4844
type: annotation,
4945
}),
5046
]))
@@ -56,12 +52,12 @@ describe('Openapi3 Request Body Examples', () => {
5652
expect(result).toEqual(diffsMatcher([
5753
expect.objectContaining({
5854
action: DiffAction.remove,
59-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1']],
55+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1']],
6056
type: annotation,
6157
}),
6258
expect.objectContaining({
6359
action: DiffAction.add,
64-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example0']],
60+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example0']],
6561
type: annotation,
6662
}),
6763
]))
@@ -73,8 +69,8 @@ describe('Openapi3 Request Body Examples', () => {
7369
expect(result).toEqual(diffsMatcher([
7470
expect.objectContaining({
7571
action: DiffAction.replace,
76-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'externalValue']],
77-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'externalValue']],
72+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
73+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
7874
type: annotation,
7975
}),
8076
]))
@@ -86,7 +82,7 @@ describe('Openapi3 Request Body Examples', () => {
8682
expect(result).toEqual(diffsMatcher([
8783
expect.objectContaining({
8884
action: DiffAction.remove,
89-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'externalValue']],
85+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
9086
type: annotation,
9187
}),
9288
]))
@@ -98,7 +94,7 @@ describe('Openapi3 Request Body Examples', () => {
9894
expect(result).toEqual(diffsMatcher([
9995
expect.objectContaining({
10096
action: DiffAction.add,
101-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'summary']],
97+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
10298
type: annotation,
10399
}),
104100
]))
@@ -110,8 +106,8 @@ describe('Openapi3 Request Body Examples', () => {
110106
expect(result).toEqual(diffsMatcher([
111107
expect.objectContaining({
112108
action: DiffAction.replace,
113-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'summary']],
114-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'summary']],
109+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
110+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
115111
type: annotation,
116112
}),
117113
]))
@@ -123,7 +119,7 @@ describe('Openapi3 Request Body Examples', () => {
123119
expect(result).toEqual(diffsMatcher([
124120
expect.objectContaining({
125121
action: DiffAction.remove,
126-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'summary']],
122+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
127123
type: annotation,
128124
}),
129125
]))
@@ -135,7 +131,7 @@ describe('Openapi3 Request Body Examples', () => {
135131
expect(result).toEqual(diffsMatcher([
136132
expect.objectContaining({
137133
action: DiffAction.add,
138-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'description']],
134+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
139135
type: annotation,
140136
}),
141137
]))
@@ -147,8 +143,8 @@ describe('Openapi3 Request Body Examples', () => {
147143
expect(result).toEqual(diffsMatcher([
148144
expect.objectContaining({
149145
action: DiffAction.replace,
150-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'description']],
151-
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'description']],
146+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
147+
afterDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
152148
type: annotation,
153149
}),
154150
]))
@@ -160,9 +156,14 @@ describe('Openapi3 Request Body Examples', () => {
160156
expect(result).toEqual(diffsMatcher([
161157
expect.objectContaining({
162158
action: DiffAction.remove,
163-
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'content', 'application/json', 'examples', 'example1', 'description']],
159+
beforeDeclarationPaths: [[...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
164160
type: annotation,
165161
}),
166162
]))
167163
})
168164
})
165+
166+
const COMPONENTS_EXAMPLES_PATH = ['components', 'examples', 'ex1']
167+
describe('Reference object. Request body examples. Description fields in ref object', () => {
168+
runRefObjectDescriptionTests(SUITE_ID, [...REQUEST_BODY_CONTENT_EXAMPLES_PATH, 'ex1'], COMPONENTS_EXAMPLES_PATH)
169+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
2+
3+
const SUITE_ID = 'request-body'
4+
const REQUEST_BODY_PATH = ['paths', '/path1', 'post', 'requestBody']
5+
const COMPONENTS_REQUEST_BODY_PATH = ['components', 'requestBodies', 'rb1']
6+
7+
describe('Reference object. Request body. Description fields in ref object', () => {
8+
runRefObjectDescriptionTests(SUITE_ID, REQUEST_BODY_PATH, COMPONENTS_REQUEST_BODY_PATH)
9+
})

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, DiffAction } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'response-body-examples'
67

7-
const COMMON_PATH = ['paths', '/path1', 'post', 'responses', '200', 'content', 'application/json']
8+
const RESPONSE_CONTENT_EXAMPLES_PATH = ['paths', '/path1', 'post', 'responses', '200', 'content', 'application/json', 'examples']
89

910
describe('Openapi3 Response Body Examples', () => {
1011

@@ -14,7 +15,7 @@ describe('Openapi3 Response Body Examples', () => {
1415
expect(result).toEqual(diffsMatcher([
1516
expect.objectContaining({
1617
action: DiffAction.add,
17-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1']],
18+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1']],
1819
type: annotation,
1920
}),
2021
]))
@@ -26,7 +27,7 @@ describe('Openapi3 Response Body Examples', () => {
2627
expect(result).toEqual(diffsMatcher([
2728
expect.objectContaining({
2829
action: DiffAction.add,
29-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example2']],
30+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example2']],
3031
type: annotation,
3132
}),
3233
]))
@@ -38,8 +39,8 @@ describe('Openapi3 Response Body Examples', () => {
3839
expect(result).toEqual(diffsMatcher([
3940
expect.objectContaining({
4041
action: DiffAction.replace,
41-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'value']],
42-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'value']],
42+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'value']],
43+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'value']],
4344
type: annotation,
4445
}),
4546
]))
@@ -51,12 +52,12 @@ describe('Openapi3 Response Body Examples', () => {
5152
expect(result).toEqual(diffsMatcher([
5253
expect.objectContaining({
5354
action: DiffAction.remove,
54-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1']],
55+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1']],
5556
type: annotation,
5657
}),
5758
expect.objectContaining({
5859
action: DiffAction.add,
59-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example0']],
60+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example0']],
6061
type: annotation,
6162
}),
6263
]))
@@ -68,8 +69,8 @@ describe('Openapi3 Response Body Examples', () => {
6869
expect(result).toEqual(diffsMatcher([
6970
expect.objectContaining({
7071
action: DiffAction.replace,
71-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'externalValue']],
72-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'externalValue']],
72+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
73+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
7374
type: annotation,
7475
}),
7576
]))
@@ -81,7 +82,7 @@ describe('Openapi3 Response Body Examples', () => {
8182
expect(result).toEqual(diffsMatcher([
8283
expect.objectContaining({
8384
action: DiffAction.remove,
84-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'externalValue']],
85+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'externalValue']],
8586
type: annotation,
8687
}),
8788
]))
@@ -93,7 +94,7 @@ describe('Openapi3 Response Body Examples', () => {
9394
expect(result).toEqual(diffsMatcher([
9495
expect.objectContaining({
9596
action: DiffAction.add,
96-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'summary']],
97+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
9798
type: annotation,
9899
}),
99100
]))
@@ -105,8 +106,8 @@ describe('Openapi3 Response Body Examples', () => {
105106
expect(result).toEqual(diffsMatcher([
106107
expect.objectContaining({
107108
action: DiffAction.replace,
108-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'summary']],
109-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'summary']],
109+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
110+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
110111
type: annotation,
111112
}),
112113
]))
@@ -118,7 +119,7 @@ describe('Openapi3 Response Body Examples', () => {
118119
expect(result).toEqual(diffsMatcher([
119120
expect.objectContaining({
120121
action: DiffAction.remove,
121-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'summary']],
122+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'summary']],
122123
type: annotation,
123124
}),
124125
]))
@@ -130,7 +131,7 @@ describe('Openapi3 Response Body Examples', () => {
130131
expect(result).toEqual(diffsMatcher([
131132
expect.objectContaining({
132133
action: DiffAction.add,
133-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'description']],
134+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
134135
type: annotation,
135136
}),
136137
]))
@@ -142,8 +143,8 @@ describe('Openapi3 Response Body Examples', () => {
142143
expect(result).toEqual(diffsMatcher([
143144
expect.objectContaining({
144145
action: DiffAction.replace,
145-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'description']],
146-
afterDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'description']],
146+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
147+
afterDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
147148
type: annotation,
148149
}),
149150
]))
@@ -155,9 +156,14 @@ describe('Openapi3 Response Body Examples', () => {
155156
expect(result).toEqual(diffsMatcher([
156157
expect.objectContaining({
157158
action: DiffAction.remove,
158-
beforeDeclarationPaths: [[...COMMON_PATH, 'examples', 'example1', 'description']],
159+
beforeDeclarationPaths: [[...RESPONSE_CONTENT_EXAMPLES_PATH, 'example1', 'description']],
159160
type: annotation,
160161
}),
161162
]))
162163
})
163164
})
165+
166+
const COMPONENTS_EXAMPLES_PATH = ['components', 'examples', 'ex1']
167+
describe('Reference object. Response body examples. Description fields in ref object', () => {
168+
runRefObjectDescriptionTests(SUITE_ID, [...RESPONSE_CONTENT_EXAMPLES_PATH, 'ex1'], COMPONENTS_EXAMPLES_PATH)
169+
})

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compareFiles } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
33
import { annotation, breaking, DiffAction, nonBreaking } from '../../../src'
4+
import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45

56
const SUITE_ID = 'response'
67

@@ -252,3 +253,9 @@ describe('Openapi3 Response', () => {
252253
})
253254
})
254255
})
256+
257+
const RESPONSES_POST_PATH = ['paths', '/path1', 'post', 'responses']
258+
const COMPONENTS_RESPONSE_PATH = ['components', 'responses', 'response200']
259+
describe('Reference object. Response. Description fields in ref object', () => {
260+
runRefObjectDescriptionTests(SUITE_ID, [...RESPONSES_POST_PATH, '200'], COMPONENTS_RESPONSE_PATH)
261+
})

0 commit comments

Comments
 (0)