Skip to content

Commit 19a8e39

Browse files
authored
feat: add compatibility suite tests for setting default values for attributes for additional cases (#23)
* feat: add compatibility suite tests for default values of operation parameters * feat: group tests related to add/remove default values * chore: set feature branch dependencies * feat: add compatibility suite tests for schema default values * feat: add compatibility suite tests for request attributes default values * feat: add compatibility suite tests for response attributes default values * fix: remove tests that duplicate style default tests and have obsolete ER now that defaults for style are supported * fix: rename default values tests for consistency and ease of support * fix: remove test that duplicate default value tests * fix: remove special handling for operation parameter style attribute it is redundant since default values for style are now supported in api-unifier * fix: adapt tests after support of default value for requestBody required attribute in api-unifier * fix: correct naming for allowReserved cases
1 parent 0bc0eae commit 19a8e39

File tree

12 files changed

+280
-91
lines changed

12 files changed

+280
-91
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openapi/openapi3.classify.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
unclassified,
1212
} from '../core'
1313
import { getKeyValue, isExist, isNotEmptyArray } from '../utils'
14-
import { emptySecurity, getDefaultStyle, includeSecurity } from './openapi3.utils'
14+
import { emptySecurity, includeSecurity } from './openapi3.utils'
1515
import type { ClassifyRule, CompareContext } from '../types'
1616
import { DiffType } from '../types'
1717
import { hidePathParamNames } from './openapi3.mapping'
@@ -47,12 +47,6 @@ export const apihubParametersRemovalClassifyRule = (ctx: CompareContext): DiffTy
4747
: breaking
4848
}
4949

50-
export const parameterStyleClassifyRule: ClassifyRule = [
51-
({ after }) => (after.value === getDefaultStyle(getKeyValue(after.parent, 'in')) ? nonBreaking : breaking),
52-
({ before }) => (before.value === getDefaultStyle(getKeyValue(before.parent, 'in')) ? nonBreaking : breaking),
53-
breaking,
54-
]
55-
5650
export const parameterExplodeClassifyRule: ClassifyRule = [
5751
({ after }) => ((after.value && getKeyValue(after.parent, 'style') === 'form') || (!after.value && getKeyValue(after.parent, 'style') !== 'form') ? annotation : breaking),
5852
({ before }) => ((before.value && getKeyValue(before.parent, 'style') === 'form') || (!before.value && getKeyValue(before.parent, 'style') !== 'form') ? annotation : breaking),

src/openapi/openapi3.rules.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ import {
4949
parameterAllowReservedClassifyRule,
5050
parameterExplodeClassifyRule,
5151
parameterNameClassifyRule,
52-
parameterRequiredClassifyRule,
53-
parameterStyleClassifyRule,
52+
parameterRequiredClassifyRule,
5453
pathChangeClassifyRule,
5554
} from './openapi3.classify'
5655
import {
@@ -157,7 +156,7 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
157156
description: diffDescription(resolveParameterDescriptionTemplates('deprecated status'))
158157
},
159158
'/style': {
160-
$: parameterStyleClassifyRule,
159+
$: allBreaking,
161160
description: diffDescription(resolveParameterDescriptionTemplates('delimited style'))
162161
},
163162
'/explode': {

src/openapi/openapi3.utils.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,6 @@ export const mapPathParams = (ctx: CompareContext, jumpsToPathLevel: number): Re
5757
return result
5858
}
5959

60-
export const getDefaultStyle = (type: unknown) => {
61-
switch (type) {
62-
case 'query':
63-
return 'form'
64-
case 'cookie':
65-
return 'form'
66-
case 'path':
67-
return 'simple'
68-
case 'header':
69-
return 'simple'
70-
}
71-
}
72-
7360
export const isResponseSchema = (path: JsonPath) => {
7461
return path[3] === 'responses' && path[7] === 'schema'
7562
}

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

Lines changed: 100 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,6 @@ describe('Openapi3 Operation Parameters', () => {
326326
))
327327
})
328328

329-
test('Add style simple for path parameter', async () => {
330-
const testId = 'add-style-simple-for-path-parameter'
331-
const result = await compareFiles(SUITE_ID, testId)
332-
expect(result).toEqual(diffsMatcher([
333-
expect.objectContaining({
334-
action: DiffAction.add,
335-
afterDeclarationPaths: [['paths', '/path1/{param1}', 'get', 'parameters', 0, 'style']],
336-
type: nonBreaking,
337-
}),
338-
]))
339-
})
340-
341329
test('Update style for path parameter', async () => {
342330
const testId = 'update-style-for-path-parameter'
343331
const result = await compareFiles(SUITE_ID, testId)
@@ -350,42 +338,7 @@ describe('Openapi3 Operation Parameters', () => {
350338
}),
351339
]))
352340
})
353-
354-
test('Add style form for query parameter', async () => {
355-
const testId = 'add-style-form-for-query-parameter'
356-
const result = await compareFiles(SUITE_ID, testId)
357-
expect(result).toEqual(diffsMatcher([
358-
expect.objectContaining({
359-
action: DiffAction.add,
360-
afterDeclarationPaths: [[...OPERATION_PARAMETERS_PATH, 0, 'style']],
361-
type: nonBreaking,
362-
}),
363-
]))
364-
})
365-
366-
test('Add style simple for header parameter', async () => {
367-
const testId = 'add-style-simple-for-header-parameter'
368-
const result = await compareFiles(SUITE_ID, testId)
369-
expect(result).toEqual(diffsMatcher([
370-
expect.objectContaining({
371-
action: DiffAction.add,
372-
afterDeclarationPaths: [[...OPERATION_PARAMETERS_PATH, 0, 'style']],
373-
type: nonBreaking,
374-
}),
375-
]))
376-
})
377-
378-
test('Add style form for cookie parameter', async () => {
379-
const testId = 'add-style-form-for-cookie-parameter'
380-
const result = await compareFiles(SUITE_ID, testId)
381-
expect(result).toEqual(diffsMatcher([
382-
expect.objectContaining({
383-
action: DiffAction.add,
384-
afterDeclarationPaths: [[...OPERATION_PARAMETERS_PATH, 0, 'style']],
385-
type: nonBreaking,
386-
}),
387-
]))
388-
})
341+
389342

390343
// TODO: fixme
391344
test.skip('Mark primitive parameter as exploded', async () => {
@@ -553,12 +506,6 @@ describe('Openapi3 Operation Parameters', () => {
553506
))
554507
})
555508

556-
test('Explicitly prohibit reserved characters for query', async () => {
557-
const testId = 'explicitly-prohibit-reserved-characters-for-query'
558-
const result = await compareFiles(SUITE_ID, testId)
559-
expect(result).toEqual([])
560-
})
561-
562509
test('Allow reserved characters for not query', async () => {
563510
const testId = 'allow-reserved-characters-for-not-query'
564511
const result = await compareFiles(SUITE_ID, testId)
@@ -677,4 +624,103 @@ describe('Openapi3 Operation Parameters', () => {
677624
}),
678625
]))
679626
})
627+
628+
describe('Add/remove default values', () => {
629+
630+
test('Add required attribute with default value for parameter', async () => {
631+
const testId = 'add-required-attribute-with-default-value-for-parameter'
632+
const result = await compareFiles(SUITE_ID, testId)
633+
expect(result).toEqual([])
634+
})
635+
636+
test('Remove required attribute with default value from parameter', async () => {
637+
const testId = 'remove-required-attribute-with-default-value-from-parameter'
638+
const result = await compareFiles(SUITE_ID, testId)
639+
expect(result).toEqual([])
640+
})
641+
642+
test('Add deprecated attribute with default value for parameter', async () => {
643+
const testId = 'add-deprecated-attribute-with-default-value-for-parameter'
644+
const result = await compareFiles(SUITE_ID, testId)
645+
expect(result).toEqual([])
646+
})
647+
648+
test('Remove deprecated attribute with default value from parameter', async () => {
649+
const testId = 'remove-deprecated-attribute-with-default-value-from-parameter'
650+
const result = await compareFiles(SUITE_ID, testId)
651+
expect(result).toEqual([])
652+
})
653+
654+
test('Add allowEmptyValue attribute with default value for parameter', async () => {
655+
const testId = 'add-allowEmptyValue-attribute-with-default-value-for-parameter'
656+
const result = await compareFiles(SUITE_ID, testId)
657+
expect(result).toEqual([])
658+
})
659+
660+
test('Remove allowEmptyValue attribute with default value from parameter', async () => {
661+
const testId = 'remove-allowEmptyValue-attribute-with-default-value-from-parameter'
662+
const result = await compareFiles(SUITE_ID, testId)
663+
expect(result).toEqual([])
664+
})
665+
666+
test('Add default style for path parameter', async () => {
667+
const testId = 'add-default-style-for-path-parameter'
668+
const result = await compareFiles(SUITE_ID, testId)
669+
expect(result).toEqual([])
670+
})
671+
672+
test('Remove default style from path parameter', async () => {
673+
const testId = 'remove-default-style-from-path-parameter'
674+
const result = await compareFiles(SUITE_ID, testId)
675+
expect(result).toEqual([])
676+
})
677+
678+
test('Add default style for query parameter', async () => {
679+
const testId = 'add-default-style-for-query-parameter'
680+
const result = await compareFiles(SUITE_ID, testId)
681+
expect(result).toEqual([])
682+
})
683+
684+
test('Remove default style from query parameter', async () => {
685+
const testId = 'remove-default-style-from-query-parameter'
686+
const result = await compareFiles(SUITE_ID, testId)
687+
expect(result).toEqual([])
688+
})
689+
690+
test('Add default style for header parameter', async () => {
691+
const testId = 'add-default-style-for-header-parameter'
692+
const result = await compareFiles(SUITE_ID, testId)
693+
expect(result).toEqual([])
694+
})
695+
696+
test('Remove default style from header parameter', async () => {
697+
const testId = 'remove-default-style-from-header-parameter'
698+
const result = await compareFiles(SUITE_ID, testId)
699+
expect(result).toEqual([])
700+
})
701+
702+
test('Add default style for cookie parameter', async () => {
703+
const testId = 'add-default-style-for-cookie-parameter'
704+
const result = await compareFiles(SUITE_ID, testId)
705+
expect(result).toEqual([])
706+
})
707+
708+
test('Remove default style from cookie parameter', async () => {
709+
const testId = 'remove-default-style-from-cookie-parameter'
710+
const result = await compareFiles(SUITE_ID, testId)
711+
expect(result).toEqual([])
712+
})
713+
714+
test('Add allowReserved attribute with default value for query parameter', async () => {
715+
const testId = 'add-allowReserved-attribute-with-default-value-for-query-parameter'
716+
const result = await compareFiles(SUITE_ID, testId)
717+
expect(result).toEqual([])
718+
})
719+
720+
test('Remove allowReserved attribute with default value from query parameter', async () => {
721+
const testId = 'remove-allowReserved-attribute-with-default-value-from-query-parameter'
722+
const result = await compareFiles(SUITE_ID, testId)
723+
expect(result).toEqual([])
724+
})
725+
})
680726
})

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runCommonSchemaTests } from './templates/schema'
1+
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
22
import { runCommonSchema31Tests } from './templates/schema31'
33

44
const SUITE_ID = 'parameters-schema'
@@ -14,7 +14,10 @@ const PARAMETERS_SCHEMA_PATH = [
1414

1515
describe('Openapi3 Parameters Schema', () => {
1616
runCommonSchemaTests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
17+
18+
runAddRemoveDefaultValuesSchemaTests(SUITE_ID)
1719
})
20+
1821
describe('Openapi31 Parameters Schema', () => {
1922
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
2023
})

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runCommonSchemaTests } from './templates/schema'
1+
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
22
import { runCommonSchema31Tests } from './templates/schema31'
33

44
const SUITE_ID = 'request-body-schema'
@@ -15,6 +15,8 @@ const REQUEST_SCHEMA_PATH = [
1515

1616
describe('Openapi3 Request Body Schema', () => {
1717
runCommonSchemaTests(SUITE_ID, REQUEST_SCHEMA_PATH)
18+
19+
runAddRemoveDefaultValuesSchemaTests(SUITE_ID)
1820
})
1921

2022
describe('Openapi31 Request Body Schema', () => {

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Openapi3 Request', () => {
5555
const result = await compareFiles(SUITE_ID, testId)
5656
expect(result).toEqual(diffsMatcher([
5757
expect.objectContaining({
58-
action: DiffAction.add,
58+
action: DiffAction.replace,
5959
afterDeclarationPaths: [[...REQUEST_BODY_PATH, 'required']],
6060
type: breaking,
6161
}),
@@ -80,7 +80,7 @@ describe('Openapi3 Request', () => {
8080
const result = await compareFiles(SUITE_ID, testId)
8181
expect(result).toEqual(diffsMatcher([
8282
expect.objectContaining({
83-
action: DiffAction.remove,
83+
action: DiffAction.replace,
8484
beforeDeclarationPaths: [[...REQUEST_BODY_PATH, 'required']],
8585
type: nonBreaking,
8686
}),
@@ -153,4 +153,31 @@ describe('Openapi3 Request', () => {
153153
}),
154154
]))
155155
})
156+
157+
describe('Add/remove default values', () => {
158+
159+
test('Add required attribute with default value for request body', async () => {
160+
const testId = 'add-required-attribute-with-default-value-for-requestBody'
161+
const result = await compareFiles(SUITE_ID, testId)
162+
expect(result).toEqual([])
163+
})
164+
165+
test('Remove required attribute with default value from request body', async () => {
166+
const testId = 'remove-required-attribute-with-default-value-from-requestBody'
167+
const result = await compareFiles(SUITE_ID, testId)
168+
expect(result).toEqual([])
169+
})
170+
171+
test('Add allowReserved attribute with default value for request body parameter encoding', async () => {
172+
const testId = 'add-allowReserved-with-default-value-for-requestBody-parameter-encoding'
173+
const result = await compareFiles(SUITE_ID, testId)
174+
expect(result).toEqual([])
175+
})
176+
177+
test('Remove allowReserved attribute with default value from request body parameter encoding', async () => {
178+
const testId = 'remove-allowReserved-with-default-value-from-requestBody-parameter-encoding'
179+
const result = await compareFiles(SUITE_ID, testId)
180+
expect(result).toEqual([])
181+
})
182+
})
156183
})

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

Lines changed: 3 additions & 0 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 { runAddRemoveDefaultValuesSchemaTests } from './templates/schema'
56
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
67

78
const SUITE_ID = 'response-body-schema'
@@ -1628,6 +1629,8 @@ describe('Openapi3 ResponseBody.Schema ', () => {
16281629
}),
16291630
]))
16301631
})
1632+
1633+
runAddRemoveDefaultValuesSchemaTests(SUITE_ID)
16311634
})
16321635

16331636
describe('Openapi31 ResponseBody.Schema', () => {

0 commit comments

Comments
 (0)