Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"fast-equals": "4.0.3"
},
"devDependencies": {
"@netcracker/qubership-apihub-compatibility-suites": "dev",
"@netcracker/qubership-apihub-compatibility-suites": "feature-sibling-properties-json-schema",
"@netcracker/qubership-apihub-graphapi": "1.0.8",
"@netcracker/qubership-apihub-npm-gitflow": "3.1.0",
"@types/jest": "29.5.11",
Expand Down
5 changes: 5 additions & 0 deletions test/compatibility-suites/openapi/parameters-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
import { runCommonSchema31Tests } from './templates/schema31'
import { runSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'

const SUITE_ID = 'parameters-schema'

Expand All @@ -21,3 +22,7 @@ describe('Openapi3 Parameters Schema', () => {
describe('Openapi31 Parameters Schema', () => {
runCommonSchema31Tests(SUITE_ID, PARAMETERS_SCHEMA_PATH)
})

describe('Openapi31 Parameters. Sibling properties Schema', () => {
runSiblingPropertiesSchema(SUITE_ID, PARAMETERS_SCHEMA_PATH)
})
5 changes: 5 additions & 0 deletions test/compatibility-suites/openapi/request-body-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { runAddRemoveDefaultValuesSchemaTests, runCommonSchemaTests } from './templates/schema'
import { runCommonSchema31Tests } from './templates/schema31'
import { runSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'

const SUITE_ID = 'request-body-schema'

Expand All @@ -22,3 +23,7 @@ describe('Openapi3 Request Body Schema', () => {
describe('Openapi31 Request Body Schema', () => {
runCommonSchema31Tests(SUITE_ID, REQUEST_SCHEMA_PATH)
})

describe('Openapi31 Request Body. Sibling properties Schema', () => {
runSiblingPropertiesSchema(SUITE_ID, REQUEST_SCHEMA_PATH)
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../s
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
import { runAddRemoveDefaultValuesSchemaTests } from './templates/schema'
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
import { runResponseSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'

const SUITE_ID = 'response-body-schema'

Expand Down Expand Up @@ -1636,3 +1637,7 @@ describe('Openapi3 ResponseBody.Schema ', () => {
describe('Openapi31 ResponseBody.Schema', () => {
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
})

describe('Openapi31 ResponseBody. Sibling properties Schema', () => {
runResponseSiblingPropertiesSchema(SUITE_ID, RESPONSE_SCHEMA_PATH)
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { runCommonResponseSchema31Tests } from './templates/response-schema31'
import { runResponseSiblingPropertiesSchema } from './templates/sibling-properties-schema.template'

const SUITE_ID = 'response-headers-schema'

Expand All @@ -16,3 +17,7 @@ const RESPONSE_HEADERS_SCHEMA_PATH = [
describe('Openapi31 ResponseHeaders.Schema', () => {
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_HEADERS_SCHEMA_PATH)
})

describe('Openapi31 ResponseHeaders. Sibling properties Schema', () => {
runResponseSiblingPropertiesSchema(SUITE_ID, RESPONSE_HEADERS_SCHEMA_PATH)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { compareFiles } from '../../utils'
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../../src'
import { diffsMatcher } from '../../../helper/matchers'

const COMPONENTS_SCHEMAS = ['components', 'schemas']

export function runResponseSiblingPropertiesSchema(suiteId: string, commonPath: JsonPath): void {
runTests(suiteId, commonPath)

test('Change referenced enum when sibling exists for ref', async () => {
const testId = 'change-referenced-enum-when-sibling-exists-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [
[...COMPONENTS_SCHEMAS, 'Color', 'enum', 1],
[...commonPath, 'enum', 1],
],
type: risky,
}),
]))
})

test('Remove sibling maxLength for ref', async () => {
const testId = 'remove-sibling-maxLength-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.replace,
beforeDeclarationPaths: [[...commonPath, 'maxLength']],
afterDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Color', 'maxLength']],
type: breaking,
}),
]))
})
}

export function runSiblingPropertiesSchema(suiteId: string, commonPath: JsonPath): void {
runTests(suiteId, commonPath)

test('Change referenced enum when sibling exists for ref', async () => {
const testId = 'change-referenced-enum-when-sibling-exists-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [
[...COMPONENTS_SCHEMAS, 'Color', 'enum', 1],
[...commonPath, 'enum', 1],
],
type: nonBreaking,
}),
]))
})

test('Remove sibling maxLength for ref', async () => {
const testId = 'remove-sibling-maxLength-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.replace,
beforeDeclarationPaths: [[...commonPath, 'maxLength']],
afterDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Color', 'maxLength']],
type: nonBreaking,
}),
]))
})
}

function runTests(suiteId: string, commonPath: JsonPath): void {
test('Add sibling description for ref', async () => {
const testId = 'add-sibling-description-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.replace,
afterDeclarationPaths: [[...commonPath, 'description']],
beforeDeclarationPaths: [[...COMPONENTS_SCHEMAS, 'Pet', 'description']],
type: annotation,
}),
]))
})

test('Change sibling enum for ref', async () => {
const testId = 'change-sibling-enum-for-ref'
const result = await compareFiles(suiteId, testId)
expect(result.length).toEqual(0)
})
}