Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apidom-ls): add operations to parameter lint #3629

Merged
merged 2 commits into from
Jan 4, 2024
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
13 changes: 11 additions & 2 deletions packages/apidom-ls/src/services/validation/linter-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,18 @@ export const standardLinterfunctions: FunctionItem[] = [
isArrayElement(element.parent) &&
includesClasses(['path-item-parameters'], element.parent);

if (!isInPathItemElement) return true;
const isInOperationElement =
isArrayElement(element.parent) &&
includesClasses(['operation-parameters'], element.parent);

if (!isInPathItemElement && !isInOperationElement) return true;

const pathItemElement: Element | undefined = isInOperationElement
? element.parent?.parent?.parent?.parent?.parent
: element.parent?.parent?.parent;

if (pathItemElement?.element !== 'pathItem') return true;

const pathItemElement = element.parent.parent.parent;
const isPathItemPartOfPathTemplating = isStringElement(pathItemElement.meta.get('path'));

if (!isPathItemPartOfPathTemplating) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ paths:
required: true
type: string
format: uuid

/test:
get:
summary: Get test
operationId: getTest
responses:
'200':
description: Successful Response
parameters:
- name: x_id
in: path
required: true
type: string
schema:
type: string
format: uuid
title: X Id
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ paths:
responses:
'202':
description: "OK"

/test:
get:
summary: Get test
operationId: getTest
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
parameters:
- name: x_id
in: path
required: true
schema:
type: string
format: uuid
title: X Id
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,21 @@ paths:
responses:
'202':
description: "OK"
/test:
get:
summary: Get test
operationId: getTest
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
parameters:
- name: x_id
in: path
required: true
schema:
type: string
format: uuid
title: X Id
21 changes: 21 additions & 0 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3586,6 +3586,13 @@ describe('apidom-ls-validate', function () {
code: 3102000,
source: 'apilint',
},
{
range: { start: { line: 38, character: 10 }, end: { line: 46, character: 0 } },
message: 'parameter is not defined within path template',
severity: 1,
code: 3102000,
source: 'apilint',
},
];
assert.deepEqual(result, expected as Diagnostic[]);

Expand Down Expand Up @@ -3628,6 +3635,13 @@ describe('apidom-ls-validate', function () {
code: 3102000,
source: 'apilint',
},
{
range: { start: { line: 84, character: 10 }, end: { line: 91, character: 0 } },
message: 'parameter is not defined within path template',
severity: 1,
code: 3102000,
source: 'apilint',
},
];
assert.deepEqual(result, expected as Diagnostic[]);

Expand Down Expand Up @@ -3670,6 +3684,13 @@ describe('apidom-ls-validate', function () {
code: 3102000,
source: 'apilint',
},
{
range: { start: { line: 103, character: 10 }, end: { line: 110, character: 0 } },
message: 'parameter is not defined within path template',
severity: 1,
code: 3102000,
source: 'apilint',
},
];
assert.deepEqual(result, expected as Diagnostic[]);

Expand Down