Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const cleanUpRecursive = (ctx: NodeContext): NodeContext => {
}

export const getOrCreateChildDiffAdd = (diffUniquenessCache: EvaluationCacheService, childCtx: CompareContext) => {
return diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add], DiffEntry<DiffAdd>>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add], () => {
return diffUniquenessCache.cacheEvaluationResultByFootprint<[unknown, string, CompareScope, typeof DiffAction.add, PropertyKey], DiffEntry<DiffAdd>>([childCtx.after.value, buildPathsIdentifier(childCtx.after.declarativePaths), childCtx.scope, DiffAction.add, childCtx.mergeKey], () => {
return diffFactory.added(childCtx)
}, {} as DiffEntry<DiffAdd>, (result, guard) => {
Object.assign(guard, result)
Expand Down
36 changes: 35 additions & 1 deletion test/bugs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { annotation, apiDiff, ClassifierType, CompareOptions, DiffAction, nonBreaking, unclassified } from '../src'
import { annotation, apiDiff, breaking, ClassifierType, CompareOptions, DiffAction, nonBreaking, unclassified } from '../src'
import offeringQualificationBefore from './helper/resources/api-v2-offeringqualification-qualification-post/before.json'
import offeringQualificationAfter from './helper/resources/api-v2-offeringqualification-qualification-post/after.json'
import readDefaultValueOfRequiredBefore from './helper/resources/read-default-value-of-required-field/before.json'
Expand Down Expand Up @@ -30,6 +30,9 @@ import spearedParamsAfter from './helper/resources/speared-parameters/after.json
import wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeBefore from './helper/resources/wildcard-content-schema-media-type-combined-with-specific-media-type/before.json'
import wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeAfter from './helper/resources/wildcard-content-schema-media-type-combined-with-specific-media-type/after.json'

import shouldNotMissRemoveDiffForEnumEntryInOneOfBefore from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/before.json'
import shouldNotMissRemoveDiffForEnumEntryInOneOfAfter from './helper/resources/should-not-miss-remove-diff-for-enum-entry-in-oneOf/after.json'

import { diffsMatcher } from './helper/matchers'
import { TEST_DIFF_FLAG, TEST_ORIGINS_FLAG } from './helper'
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_NOTHING } from '@netcracker/qubership-apihub-api-unifier'
Expand Down Expand Up @@ -227,4 +230,35 @@ describe('Real Data', () => {
}),
]))
})

it('should not miss remove diff for enum entry in oneOf', () => {
const before: any = shouldNotMissRemoveDiffForEnumEntryInOneOfBefore
const after: any = shouldNotMissRemoveDiffForEnumEntryInOneOfAfter
const { merged } = apiDiff(before, after, OPTIONS)

expect(
Object.values((merged as any).paths['/path1'].post.requestBody.content['application/json'].schema.oneOf[1].properties.scope.items.enum[TEST_DIFF_FLAG])
).toEqual(diffsMatcher([
expect.objectContaining({
beforeValue: 'query',
action: DiffAction.remove,
type: breaking,
}),
expect.objectContaining({
beforeValue: 'subscription',
action: DiffAction.remove,
type: breaking,
}),
expect.objectContaining({
afterValue: 'argument',
action: DiffAction.add,
type: nonBreaking,
}),
expect.objectContaining({
afterValue: 'annotation',
action: DiffAction.add,
type: nonBreaking,
}),
]))
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"openapi": "3.0.3",
"info": {
"title": "test",
"version": "0.1.0"
},
"paths": {
"/path1": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"type": "object",
"title": "SearchRestParams",
"properties": {
"apiType": {
"type": "string",
"enum": [
"rest"
]
},
"scope": {
"type": "array",
"items": {
"type": "string",
"enum": [
"request"
]
}
}
}
},
{
"type": "object",
"title": "SearchGQLParams",
"properties": {
"scope": {
"type": "array",
"items": {
"type": "string",
"enum": [
"argument",
"annotation"
]
}
}
}
}
]
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"openapi": "3.0.3",
"info": {
"title": "test",
"version": "0.1.0"
},
"paths": {
"/path1": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"type": "object",
"title": "SearchRestParams",
"properties": {
"apiType": {
"type": "string",
"enum": [
"Rest"
]
},
"scope": {
"type": "array",
"items": {
"type": "string",
"enum": [
"request"
]
}
}
}
},
{
"type": "object",
"title": "SearchGQLParams",
"properties": {
"scope": {
"type": "array",
"items": {
"type": "string",
"enum": [
"query",
"subscription"
]
}
}
}
}
]
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {}
}
}
}
}
}
}
Loading