diff --git a/test/compatibility-suites/openapi/response-body-schema.test.ts b/test/compatibility-suites/openapi/response-body-schema.test.ts index 57e87bf..d10f96a 100644 --- a/test/compatibility-suites/openapi/response-body-schema.test.ts +++ b/test/compatibility-suites/openapi/response-body-schema.test.ts @@ -1636,3 +1636,4 @@ describe('Openapi3 ResponseBody.Schema ', () => { describe('Openapi31 ResponseBody.Schema', () => { runCommonResponseSchema31Tests(SUITE_ID, RESPONSE_SCHEMA_PATH) }) + diff --git a/test/compatibility-suites/openapi/templates/reference-object-31.template.ts b/test/compatibility-suites/openapi/templates/reference-object-31.template.ts index c7b56e5..de08d97 100644 --- a/test/compatibility-suites/openapi/templates/reference-object-31.template.ts +++ b/test/compatibility-suites/openapi/templates/reference-object-31.template.ts @@ -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() }) } diff --git a/test/compatibility-suites/openapi/templates/response-schema31.ts b/test/compatibility-suites/openapi/templates/response-schema31.ts index 6f2a474..17a006f 100644 --- a/test/compatibility-suites/openapi/templates/response-schema31.ts +++ b/test/compatibility-suites/openapi/templates/response-schema31.ts @@ -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, + }), + ])) + }) }) } diff --git a/test/compatibility-suites/openapi/templates/schema.ts b/test/compatibility-suites/openapi/templates/schema.ts index 8c25371..4c07979 100644 --- a/test/compatibility-suites/openapi/templates/schema.ts +++ b/test/compatibility-suites/openapi/templates/schema.ts @@ -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 () => { diff --git a/test/compatibility-suites/openapi/templates/schema31.ts b/test/compatibility-suites/openapi/templates/schema31.ts index f7434e3..0202603 100644 --- a/test/compatibility-suites/openapi/templates/schema31.ts +++ b/test/compatibility-suites/openapi/templates/schema31.ts @@ -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, + }), + ])) + }) }) }