Skip to content

Commit ee9110d

Browse files
authored
refactor: add test for comparing OAS specs with duplicated parameters (#46)
1 parent e727205 commit ee9110d

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

.github/super-linter.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ VALIDATE_TSX=false
3636
VALIDATE_TYPESCRIPT_ES=false
3737
VALIDATE_TYPESCRIPT_PRETTIER=false
3838
VALIDATE_TYPESCRIPT_STANDARD=false
39+
40+
# Skip OPENAPI check for this repo as it contains invalid OAS specs for testing purposes
41+
VALIDATE_OPENAPI=false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"update-lock-file": "update-lock-file @netcracker"
2828
},
2929
"dependencies": {
30-
"@netcracker/qubership-apihub-api-unifier": "2.4.1",
30+
"@netcracker/qubership-apihub-api-unifier": "dev",
3131
"@netcracker/qubership-apihub-json-crawl": "1.0.4",
3232
"fast-equals": "4.0.3"
3333
},

test/bugs.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import shouldNotMissRemoveDiffForEnumEntryInOneOfAfter from './helper/resources/
4545
import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerBefore from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/before.json'
4646
import shouldReportSingleDiffWhenRequiredPropertyIsChangedForTheCombinerAfter from './helper/resources/should-report-single-diff-when-required-property-is-changed-for-the-combiner/after.json'
4747

48+
import duplicateParametersBefore from './helper/resources/duplicate-parameters/before.json'
49+
import duplicateParametersAfter from './helper/resources/duplicate-parameters/after.json'
50+
4851
import { diffsMatcher } from './helper/matchers'
4952
import { TEST_DIFF_FLAG, TEST_ORIGINS_FLAG } from './helper'
5053
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_NOTHING } from '@netcracker/qubership-apihub-api-unifier'
@@ -115,7 +118,7 @@ describe('Real Data', () => {
115118
const after: any = infinityAfter
116119
const { diffs } = apiDiff(before, after, OPTIONS)
117120
const responseContentPath = ['paths', '/api/v1/dictionaries/dictionary/item', 'get', 'responses', '200', 'content']
118-
expect(diffs).toEqual(diffsMatcher([
121+
expect(diffs).toEqual(diffsMatcher([
119122
expect.objectContaining({
120123
afterDeclarationPaths: [['components', 'schemas', 'DictionaryItem', 'x-entity']],
121124
afterValue: 'DictionaryItem',
@@ -232,7 +235,7 @@ describe('Real Data', () => {
232235
const before: any = wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeBefore
233236
const after: any = wildcardContentSchemaMediaTypeCombinedWithSpecificMediaTypeAfter
234237
const { diffs } = apiDiff(before, after, OPTIONS)
235-
238+
236239
expect(diffs).toEqual(diffsMatcher([
237240
expect.objectContaining({
238241
action: DiffAction.replace,
@@ -302,4 +305,18 @@ describe('Real Data', () => {
302305
}),
303306
]))
304307
})
308+
309+
310+
it('should not report diffs for duplicated parameters', () => {
311+
const { diffs } = apiDiff(duplicateParametersBefore, duplicateParametersAfter, OPTIONS)
312+
313+
expect(diffs).toHaveLength(1)
314+
expect(diffs).toEqual(diffsMatcher([
315+
expect.objectContaining({
316+
action: DiffAction.add,
317+
afterDeclarationPaths: [['paths', '/api/v1/user-management/user-federations/{id}/mappers/{id}', 'get', 'description']],
318+
type: annotation,
319+
}),
320+
]))
321+
})
305322
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"openapi": "3.1.1",
3+
"info": {
4+
"title": "User Management API",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/api/v1/user-management/user-federations/{id}/mappers/{id}": {
9+
"get": {
10+
"description": "Retrieve mapper details for a specific federation and mapper ID.",
11+
"parameters": [
12+
{
13+
"name": "id",
14+
"in": "path",
15+
"required": true,
16+
"schema": {
17+
"type": "string"
18+
}
19+
},
20+
{
21+
"name": "id",
22+
"in": "path",
23+
"required": true,
24+
"schema": {
25+
"type": "string"
26+
}
27+
}
28+
],
29+
"responses": {
30+
"200": {
31+
"description": "OK"
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"openapi": "3.1.1",
3+
"info": {
4+
"title": "User Management API",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/api/v1/user-management/user-federations/{id}/mappers/{id}": {
9+
"get": {
10+
"parameters": [
11+
{
12+
"name": "id",
13+
"in": "path",
14+
"required": true,
15+
"schema": {
16+
"type": "string"
17+
}
18+
},
19+
{
20+
"name": "id",
21+
"in": "path",
22+
"required": true,
23+
"schema": {
24+
"type": "string"
25+
}
26+
}
27+
],
28+
"responses": {
29+
"200": {
30+
"description": "OK"
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)