Skip to content

Commit a945fb6

Browse files
committed
Merge branch 'develop' into feature/rename-label-semi-breaking-changes-two
2 parents efb543b + 31a23ec commit a945fb6

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

src/jsonSchema/jsonSchema.classify.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
breakingIfAfterTrue,
55
nonBreaking,
66
PARENT_JUMP,
7+
semiBreaking,
78
strictResolveValueFromContext,
89
unclassified,
910
} from '../core'
@@ -100,6 +101,9 @@ export const enumClassifyRule: ClassifyRule = [
100101
({ before }) => (isNotEmptyArray(before.parent) ? nonBreaking : breaking),
101102
({ after }) => (isNotEmptyArray(after.parent) ? breaking : nonBreaking),
102103
breaking,
104+
({ before }) => (isNotEmptyArray(before.parent) ? semiBreaking : nonBreaking),
105+
({ after }) => (isNotEmptyArray(after.parent) ? nonBreaking: semiBreaking ),
106+
nonBreaking
103107
]
104108

105109
export const nonInvertible = (rule: ClassifyRule): ClassifyRule => {

src/jsonSchema/jsonSchema.rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
transformCompareRules,
2121
unclassified,
2222
deepEqualsUniqueItemsArrayMappingResolver,
23+
semiBreaking,
2324
} from '../core'
2425
import {
2526
enumClassifyRule,
@@ -122,7 +123,7 @@ export const jsonSchemaRules = ({
122123
'/default': simpleRule([nonBreaking, breaking, breaking], resolveSchemaDescriptionTemplates('default value')),
123124

124125
'/enum': {
125-
$: [breaking, nonBreaking, breaking],
126+
$: [breaking, nonBreaking, breaking, nonBreaking, semiBreaking, nonBreaking],
126127
mapping: deepEqualsUniqueItemsArrayMappingResolver,
127128
'/*': ({ key, value }) => {
128129
if (!isNumber(key)) {

src/openapi/openapi3.classify.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getKeyValue, isExist, isNotEmptyArray } from '../utils'
1414
import { emptySecurity, getDefaultStyle, includeSecurity } from './openapi3.utils'
1515
import type { ClassifyRule, CompareContext } from '../types'
1616
import { DiffType } from '../types'
17+
import { hidePathParamNames } from './openapi3.mapping'
1718

1819
export const paramClassifyRule: ClassifyRule = [
1920
({ after }) => {
@@ -72,7 +73,7 @@ export const parameterAllowReservedClassifyRule: ClassifyRule = [
7273
export const parameterNameClassifyRule: ClassifyRule = [
7374
nonBreaking,
7475
breaking,
75-
({ before }) => (getKeyValue(before.parent, 'in') === 'path' ? nonBreaking : breaking),
76+
({ before }) => (getKeyValue(before.parent, 'in') === 'path' ? annotation : breaking),
7677
]
7778

7879
export const parameterRequiredClassifyRule: ClassifyRule = [
@@ -141,3 +142,17 @@ export const operationSecurityItemClassifyRule: ClassifyRule = [
141142
after,
142143
}) => (includeSecurity(after.parent, before.parent) || emptySecurity(after.value) ? nonBreaking : breaking),
143144
]
145+
146+
export const pathChangeClassifyRule: ClassifyRule = [
147+
nonBreaking,
148+
breaking,
149+
({ before, after }) => {
150+
const beforePath = before.key as string
151+
const afterPath = after.key as string
152+
const unifiedBeforePath = hidePathParamNames(beforePath)
153+
const unifiedAfterPath = hidePathParamNames(afterPath)
154+
155+
// If unified paths are the same, it means only parameter names changed
156+
return unifiedBeforePath === unifiedAfterPath ? annotation : breaking
157+
}
158+
]

src/openapi/openapi3.mapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const contentMediaTypeMappingResolver: MappingResolver<string> = (before,
124124
return result
125125
}
126126

127-
function hidePathParamNames(path: string): string {
127+
export function hidePathParamNames(path: string): string {
128128
return path.replace(PATH_PARAMETER_REGEXP, PATH_PARAM_UNIFIED_PLACEHOLDER)
129129
}
130130

src/openapi/openapi3.rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
parameterNameClassifyRule,
5252
parameterRequiredClassifyRule,
5353
parameterStyleClassifyRule,
54+
pathChangeClassifyRule,
5455
} from './openapi3.classify'
5556
import {
5657
contentMediaTypeMappingResolver,
@@ -341,7 +342,7 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
341342
$: allUnclassified,
342343
mapping: options.mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver,
343344
'/*': {
344-
$: [nonBreaking, breaking, breaking],
345+
$: pathChangeClassifyRule,
345346
mapping: options.mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver,
346347
'/summary': { $: allAnnotation },
347348
'/description': { $: allAnnotation },

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compareFiles, compareFilesWithMerge, TEST_DEFAULTS_DECLARATION_PATHS } from '../utils'
22
import { diffsMatcher } from '../../helper/matchers'
3-
import { annotation, breaking, DiffAction, nonBreaking } from '../../../src'
3+
import { annotation, breaking, DiffAction, nonBreaking, semiBreaking } from '../../../src'
44
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
55

66
const SUITE_ID = 'response-body-schema'
@@ -160,7 +160,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
160160
expect.objectContaining({
161161
action: DiffAction.remove,
162162
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'enum']],
163-
type: breaking,
163+
type: semiBreaking,
164164
}),
165165
]))
166166
})
@@ -172,7 +172,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
172172
expect.objectContaining({
173173
action: DiffAction.add,
174174
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'enum', 2]],
175-
type: breaking,
175+
type: semiBreaking,
176176
}),
177177
]))
178178
})
@@ -189,7 +189,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
189189
expect.objectContaining({
190190
action: DiffAction.add,
191191
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'enum', 1]],
192-
type: breaking,
192+
type: semiBreaking,
193193
}),
194194
],
195195
))

test/openapi.diff.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DIFF_META_KEY,
88
DiffAction,
99
nonBreaking,
10+
annotation,
1011
} from '../src'
1112

1213
import { OpenapiBuilder, TEST_DIFF_FLAG, TEST_ORIGINS_FLAG, TEST_SYNTHETIC_TITLE_FLAG } from './helper'
@@ -186,20 +187,19 @@ describe('Openapi3 operation changes', () => {
186187
action: DiffAction.rename,
187188
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}']],
188189
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}']],
189-
// todo fix
190-
type: breaking,
190+
type: annotation, // Only parameter names changed, unified paths are the same
191191
}),
192192
expect.objectContaining({
193193
action: DiffAction.replace,
194194
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}', 'parameters', 0, 'name']],
195195
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}', 'parameters', 1, 'name']],
196-
type: nonBreaking,
196+
type: annotation,
197197
}),
198198
expect.objectContaining({
199199
action: DiffAction.replace,
200200
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}', 'parameters', 1, 'name']],
201201
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}', 'parameters', 0, 'name']],
202-
type: nonBreaking,
202+
type: annotation,
203203
}),
204204
]))
205205
})
@@ -211,20 +211,19 @@ describe('Openapi3 operation changes', () => {
211211
action: DiffAction.rename,
212212
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}']],
213213
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}']],
214-
// todo fix
215-
type: breaking,
214+
type: annotation, // Only parameter names changed, unified paths are the same
216215
}),
217216
expect.objectContaining({
218217
action: DiffAction.replace,
219218
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}', 'get', 'parameters', 0, 'name']],
220219
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}', 'get', 'parameters', 1, 'name']],
221-
type: nonBreaking,
220+
type: annotation,
222221
}),
223222
expect.objectContaining({
224223
action: DiffAction.replace,
225224
beforeDeclarationPaths: [['paths', '/path1/{param1}/{anotherParam1}', 'get', 'parameters', 1, 'name']],
226225
afterDeclarationPaths: [['paths', '/path1/{param2}/{anotherParam2}', 'get', 'parameters', 0, 'name']],
227-
type: nonBreaking,
226+
type: annotation,
228227
}),
229228
]))
230229
})
@@ -253,14 +252,13 @@ describe('Openapi3 operation changes', () => {
253252
action: DiffAction.rename,
254253
beforeDeclarationPaths: [['paths', '/path1/{param1}']],
255254
afterDeclarationPaths: [['paths', '/path1/{param2}']],
256-
// todo fix
257-
type: breaking,
255+
type: annotation, // Only parameter name changed, unified paths are the same
258256
}),
259257
expect.objectContaining({
260258
action: DiffAction.replace,
261259
beforeDeclarationPaths: [['paths', '/path1/{param1}', 'get', 'parameters', 0, 'name']],
262260
afterDeclarationPaths: [['paths', '/path1/{param2}', 'get', 'parameters', 0, 'name']],
263-
type: nonBreaking,
261+
type: annotation,
264262
}),
265263
expect.objectContaining({
266264
action: DiffAction.add,

0 commit comments

Comments
 (0)