Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1636,3 +1636,4 @@ describe('Openapi3 ResponseBody.Schema ', () => {
describe('Openapi31 ResponseBody.Schema', () => {
runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH)
})

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function runReferenceObjectTests(suiteId: string, refPath: JsonPath, comp

test(`Change referenced ${overridenField} when overridden exists`, async () => {
const testId = `change-referenced-${overridenField}-when-overridden-exists`
const result = await compareFiles(suiteId, testId)
expect(result.length).toEqual(0)
const diffs = await compareFiles(suiteId, testId)
expect(diffs).toBeEmpty()
})
}
149 changes: 101 additions & 48 deletions test/compatibility-suites/openapi/templates/response-schema31.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,113 @@
import { compareFiles } from '../../utils'
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
import { breaking, DiffAction, nonBreaking } from '../../../../src'
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../../src'
import { diffsMatcher } from '../../../helper/matchers'

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

export function runCommonResponseSchema31Tests(suiteId: string, commonPath: JsonPath): void {
test('Add union type', async () => {
const testId = 'add-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 1]],
type: breaking,
}),
]))
})
describe('Union type', () => {
test('Add union type', async () => {
const testId = 'add-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 1]],
type: breaking,
}),
]))
})

test('Add null to union type', async () => {
const testId = 'add-null-to-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 2]],
type: breaking,
}),
]))
})
test('Add null to union type', async () => {
const testId = 'add-null-to-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 2]],
type: breaking,
}),
]))
})

test('Remove union type', async () => {
const testId = 'remove-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
type: nonBreaking,
}),
]))
})
test('Remove union type', async () => {
const testId = 'remove-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
type: nonBreaking,
}),
]))
})

test('Remove null from union type', async () => {
const testId = 'remove-null-from-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
type: nonBreaking,
}),
]))
test('Remove null from union type', async () => {
const testId = 'remove-null-from-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
type: nonBreaking,
}),
]))
})

test('Reorder types in union type', async () => {
const testId = 'reorder-types-in-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toBeEmpty()
})
})

test('Reorder types in union type', async () => {
const testId = 'reorder-types-in-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toBeEmpty()
describe('$ref sibling properties', () => {
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 diffs = await compareFiles(suiteId, testId)
expect(diffs).toBeEmpty()
})

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,
}),
]))
})
})
}
4 changes: 2 additions & 2 deletions test/compatibility-suites/openapi/templates/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ export function runCommonSchemaTests(suiteId: string, commonPath: JsonPath): voi
test('Update definition of free-form object', async () => {

const testId = 'update-definition-of-free-form-object'
const result = await compareFiles(suiteId, testId)
expect(result.length).toEqual(0)
const diffs = await compareFiles(suiteId, testId)
expect(diffs).toBeEmpty()
})

test('Add non-boolean additionalProperties', async () => {
Expand Down
149 changes: 101 additions & 48 deletions test/compatibility-suites/openapi/templates/schema31.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,113 @@
import { compareFiles } from '../../utils'
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
import { breaking, DiffAction, nonBreaking } from '../../../../src'
import { annotation, breaking, DiffAction, nonBreaking } from '../../../../src'
import { diffsMatcher } from '../../../helper/matchers'

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

export function runCommonSchema31Tests(suiteId: string, commonPath: JsonPath): void {
test('Add union type', async () => {
const testId = 'add-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 1]],
type: nonBreaking,
}),
]))
})
describe('Union type', () => {
test('Add union type', async () => {
const testId = 'add-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 1]],
type: nonBreaking,
}),
]))
})

test('Add null to union type', async () => {
const testId = 'add-null-to-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 2]],
type: nonBreaking,
}),
]))
})
test('Add null to union type', async () => {
const testId = 'add-null-to-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.add,
afterDeclarationPaths: [[...commonPath, 'type', 2]],
type: nonBreaking,
}),
]))
})

test('Remove union type', async () => {
const testId = 'remove-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
type: breaking,
}),
]))
})
test('Remove union type', async () => {
const testId = 'remove-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 1]],
type: breaking,
}),
]))
})

test('Remove null from union type', async () => {
const testId = 'remove-null-from-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
type: breaking,
}),
]))
test('Remove null from union type', async () => {
const testId = 'remove-null-from-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toEqual(diffsMatcher([
expect.objectContaining({
action: DiffAction.remove,
beforeDeclarationPaths: [[...commonPath, 'type', 2]],
type: breaking,
}),
]))
})

test('Reorder types in union type', async () => {
const testId = 'reorder-types-in-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toBeEmpty()
})
})

test('Reorder types in union type', async () => {
const testId = 'reorder-types-in-union-type'
const result = await compareFiles(suiteId, testId)
expect(result).toBeEmpty()
describe('$ref sibling properties', () => {
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 diffs = await compareFiles(suiteId, testId)
expect(diffs).toBeEmpty()
})

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,
}),
]))
})
})
}
Loading