diff --git a/.github/super-linter.env b/.github/super-linter.env index c5b356f..be7918f 100644 --- a/.github/super-linter.env +++ b/.github/super-linter.env @@ -36,3 +36,6 @@ VALIDATE_TSX=false VALIDATE_TYPESCRIPT_ES=false VALIDATE_TYPESCRIPT_PRETTIER=false VALIDATE_TYPESCRIPT_STANDARD=false + +# Skip OPENAPI check for this repo as it contains invalid OAS specs for testing purposes +VALIDATE_OPENAPI=false diff --git a/package.json b/package.json index e9aef18..f53d3e9 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "update-lock-file": "update-lock-file @netcracker" }, "dependencies": { - "@netcracker/qubership-apihub-api-unifier": "2.4.1", + "@netcracker/qubership-apihub-api-unifier": "dev", "@netcracker/qubership-apihub-json-crawl": "1.0.4", "fast-equals": "4.0.3" }, diff --git a/test/bugs.test.ts b/test/bugs.test.ts index a6ce3cf..fe58b5c 100644 --- a/test/bugs.test.ts +++ b/test/bugs.test.ts @@ -45,6 +45,9 @@ import shouldNotMissRemoveDiffForEnumEntryInOneOfAfter from './helper/resources/ import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerBefore from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/before.json' import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerAfter from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/after.json' +import duplicateParametersBefore from './helper/resources/duplicate-parameters/before.json' +import duplicateParametersAfter from './helper/resources/duplicate-parameters/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' @@ -115,7 +118,7 @@ describe('Real Data', () => { const after: any = infinityAfter const { diffs } = apiDiff(before, after, OPTIONS) const responseContentPath = ['paths', '/api/v1/dictionaries/dictionary/item', 'get', 'responses', '200', 'content'] - expect(diffs).toEqual(diffsMatcher([ + expect(diffs).toEqual(diffsMatcher([ expect.objectContaining({ afterDeclarationPaths: [['components', 'schemas', 'DictionaryItem', 'x-entity']], afterValue: 'DictionaryItem', @@ -232,7 +235,7 @@ describe('Real Data', () => { const before: any = wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeBefore const after: any = wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeAfter const { diffs } = apiDiff(before, after, OPTIONS) - + expect(diffs).toEqual(diffsMatcher([ expect.objectContaining({ action: DiffAction.replace, @@ -302,4 +305,18 @@ describe('Real Data', () => { }), ])) }) + + + it('should not report diffs for duplicated parameters', () => { + const { diffs } = apiDiff(duplicateParametersBefore, duplicateParametersAfter, OPTIONS) + + expect(diffs).toHaveLength(1) + expect(diffs).toEqual(diffsMatcher([ + expect.objectContaining({ + action: DiffAction.add, + afterDeclarationPaths: [['paths', '/api/v1/user-management/user-federations/{id}/mappers/{id}', 'get', 'description']], + type: annotation, + }), + ])) + }) }) diff --git a/test/helper/resources/duplicate-parameters/after.json b/test/helper/resources/duplicate-parameters/after.json new file mode 100644 index 0000000..8efd865 --- /dev/null +++ b/test/helper/resources/duplicate-parameters/after.json @@ -0,0 +1,37 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "User Management API", + "version": "1.0.0" + }, + "paths": { + "/api/v1/user-management/user-federations/{id}/mappers/{id}": { + "get": { + "description": "Retrieve mapper details for a specific federation and mapper ID.", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + } + } +} diff --git a/test/helper/resources/duplicate-parameters/before.json b/test/helper/resources/duplicate-parameters/before.json new file mode 100644 index 0000000..5fcc426 --- /dev/null +++ b/test/helper/resources/duplicate-parameters/before.json @@ -0,0 +1,36 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "User Management API", + "version": "1.0.0" + }, + "paths": { + "/api/v1/user-management/user-federations/{id}/mappers/{id}": { + "get": { + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + } + } +}