Skip to content

Commit

Permalink
feat(ls): add lint rule for OpenAPI Operation Parameter defined in pa…
Browse files Browse the repository at this point in the history
…th template (#3629)

Refs #3546
  • Loading branch information
kowalczyk-krzysztof committed Jan 4, 2024
1 parent 28b52f9 commit 98cdfad
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/apidom-ls/src/services/validation/linter-functions.ts
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
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
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
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
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

0 comments on commit 98cdfad

Please sign in to comment.