Skip to content

Commit 1eb1a38

Browse files
fix: parameter unique name validation for oas2
1 parent 21fe90c commit 1eb1a38

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

packages/apidom-ls/src/config/openapi/parameter/lint/unique-name.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const parametersTypeLint: LinterMeta = {
1010
message: 'Name must be unique among all parameters',
1111
severity: DiagnosticSeverity.Error,
1212
linterFunction: 'apilintPropertyUniqueSiblingValue',
13-
linterParams: [['parameters'], 'name'],
13+
linterParams: ['parameters', 'name'],
1414
marker: 'key',
1515
markerTarget: 'name',
1616
target: 'name',
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
swagger: "2.0"
2+
info:
3+
version: 1.0.0
4+
title: 'test'
5+
paths:
6+
/pets:
7+
get:
8+
responses:
9+
parameters:
10+
- name: pathLevel
11+
type: string
12+
in: query
13+
description: tags to filter by
14+
schema:
15+
type: string
16+
- name: pathLevel
17+
type: string
18+
in: query
19+
description: tags to filter by
20+
schema:
21+
type: string

packages/apidom-ls/test/validate.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,6 +3714,69 @@ describe('apidom-ls-validate', function () {
37143714
languageService.terminate();
37153715
});
37163716

3717+
it('oas 2.0 / yaml - parameter name should be unique', async function () {
3718+
const validationContext: ValidationContext = {
3719+
comments: DiagnosticSeverity.Error,
3720+
maxNumberOfProblems: 100,
3721+
relatedInformation: false,
3722+
};
3723+
3724+
const spec = fs
3725+
.readFileSync(
3726+
path.join(__dirname, 'fixtures', 'validation', 'oas', 'parameter-unique-name-2-0.yaml'),
3727+
)
3728+
.toString();
3729+
const doc: TextDocument = TextDocument.create(
3730+
'foo://bar/parameter-unique-name-2-0.yaml',
3731+
'yaml',
3732+
0,
3733+
spec,
3734+
);
3735+
3736+
const languageService: LanguageService = getLanguageService(contextNoSchema);
3737+
3738+
const result = await languageService.doValidation(doc, validationContext);
3739+
const expected: Diagnostic[] = [
3740+
{
3741+
code: 3103000,
3742+
data: {},
3743+
message: 'Name must be unique among all parameters',
3744+
range: {
3745+
end: {
3746+
character: 14,
3747+
line: 9,
3748+
},
3749+
start: {
3750+
character: 10,
3751+
line: 9,
3752+
},
3753+
},
3754+
severity: 1,
3755+
source: 'apilint',
3756+
},
3757+
{
3758+
code: 3103000,
3759+
data: {},
3760+
message: 'Name must be unique among all parameters',
3761+
range: {
3762+
end: {
3763+
character: 14,
3764+
line: 15,
3765+
},
3766+
start: {
3767+
character: 10,
3768+
line: 15,
3769+
},
3770+
},
3771+
severity: 1,
3772+
source: 'apilint',
3773+
},
3774+
];
3775+
assert.deepEqual(result, expected as Diagnostic[]);
3776+
3777+
languageService.terminate();
3778+
});
3779+
37173780
it('oas 3.0 / yaml - parameter Authorization is ignored', async function () {
37183781
const validationContext: ValidationContext = {
37193782
comments: DiagnosticSeverity.Error,

0 commit comments

Comments
 (0)