Skip to content

Commit

Permalink
feat(apidom-ls): change implementation and add more fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalczyk-krzysztof committed Dec 15, 2023
1 parent 5dcdf03 commit 2778049
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 16 deletions.
46 changes: 34 additions & 12 deletions packages/apidom-ls/src/services/validation/linter-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '@swagger-api/apidom-core';
import { CompletionItem } from 'vscode-languageserver-types';
import { test, resolve } from 'openapi-path-templating';
import { OperationElement, isParameterElement } from '@swagger-api/apidom-ns-openapi-3-0';

// eslint-disable-next-line import/no-cycle
import {
Expand Down Expand Up @@ -1017,19 +1016,42 @@ export const standardLinterfunctions: FunctionItem[] = [
return true;
}

const pathTemplateResolveParams: { [key: string]: string } = {};
const parameterElements: Element[] = [];

const parametersObject = pathItemElement.get('parameters');

const isParameterPolymorphicCheck = (el: Element): boolean => el.element === 'parameter';

pathItemElement.forEach((operation) => {
const parameters = (operation as OperationElement).get('parameters');
if (isArrayElement(parameters)) {
parameters.forEach((parameter) => {
if (isParameterElement(parameter)) {
const allowedLocation = ['path', 'query'];
if (allowedLocation.includes(toValue(parameter.in))) {
pathTemplateResolveParams[toValue(parameter.name) as string] = 'placeholder';
if (isArrayElement(parametersObject)) {
parametersObject.forEach((parameter) => {
if (isParameterPolymorphicCheck(parameter)) {
parameterElements.push(parameter);
}
});
}

pathItemElement.forEach((el) => {
if (el.element === 'operation') {
// @ts-ignore
const parameters = el.get('parameters');
if (isArrayElement(parameters)) {
parameters.forEach((parameter) => {
if (isParameterPolymorphicCheck(parameter)) {
parameterElements.push(parameter);
}
}
});
});
}
}
});

const allowedLocation = ['path', 'query'];
const pathTemplateResolveParams: { [key: string]: string } = {};

parameterElements.forEach((parameter) => {
// @ts-ignore
if (allowedLocation.includes(toValue(parameter.in))) {
// @ts-ignore
pathTemplateResolveParams[toValue(parameter.name) as string] = 'placeholder';
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
swagger: '2.0'
info:
title: Foo
version: 0.1.0
parameters:
test_id:
name: test_id
in: path
required: true
schema:
type: string
format: uuid
title: Test Id
paths:
/foo/bar/{baz}/test/{foo_id}/baz/{bar_id}:
delete:
summary: Delete foo bar test baz
operationId: deleteFooBarTestBaz
parameters:
- name: foo_id
in: path
required: true
schema:
type: string
format: uuid
title: Foo Id
- name: bar_id
in: path
required: true
schema:
type: string
format: uuid
title: Bar Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/test/{foo_id}/{bar_id}:
get:
summary: Get test foo bar
operationId: getTestFooBar
parameters:
- name: foo_id
in: path
required: true
schema:
type: string
format: uuid
title: Foo Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/reference/{test_id}/{baz_id}:
get:
summary: Get test baz
operationId: getReferenceTestBaz
parameters:
- $ref: '#/parameters/test_id'
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/just_parameters_object/{x_id}/{y_id}:
parameters:
- name: x_id
in: path
required: true
schema:
type: string
format: uuid
title: X Id
/both_parameters_and_operations_object/{a_id}/{b_id}/{c_id}:
get:
summary: Get both parameters and operations object a b c
operationId: getBothParametersAndOperationsObjectABC
parameters:
- name: b_id
in: path
required: true
schema:
type: string
format: uuid
title: B Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
parameters:
- name: a_id
in: path
required: true
schema:
type: string
format: uuid
title: A Id
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,38 @@ paths:
content:
application/json:
schema: {}
/just_parameters_object/{x_id}/{y_id}:
parameters:
- name: x_id
in: path
required: true
schema:
type: string
format: uuid
title: X Id
/both_parameters_and_operations_object/{a_id}/{b_id}/{c_id}:
get:
summary: Get both parameters and operations object a b c
operationId: getBothParametersAndOperationsObjectABC
parameters:
- name: b_id
in: path
required: true
schema:
type: string
format: uuid
title: B Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
parameters:
- name: a_id
in: path
required: true
schema:
type: string
format: uuid
title: A Id
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
openapi: 3.1.0
info:
title: Foo
version: 0.1.0
components:
parameters:
test_id:
name: test_id
in: path
required: true
schema:
type: string
format: uuid
title: Test Id
paths:
/foo/bar/{baz}/test/{foo_id}/baz/{bar_id}:
delete:
summary: Delete foo bar test baz
operationId: deleteFooBarTestBaz
parameters:
- name: foo_id
in: path
required: true
schema:
type: string
format: uuid
title: Foo Id
- name: bar_id
in: path
required: true
schema:
type: string
format: uuid
title: Bar Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/test/{foo_id}/{bar_id}:
get:
summary: Get test foo bar
operationId: getTestFooBar
parameters:
- name: foo_id
in: path
required: true
schema:
type: string
format: uuid
title: Foo Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/reference/{test_id}/{baz_id}:
get:
summary: Get test baz
operationId: getReferenceTestBaz
parameters:
- $ref: '#/components/parameters/test_id'
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
/just_parameters_object/{x_id}/{y_id}:
parameters:
- name: x_id
in: path
required: true
schema:
type: string
format: uuid
title: X Id
/both_parameters_and_operations_object/{a_id}/{b_id}/{c_id}:
get:
summary: Get both parameters and operations object a b c
operationId: getBothParametersAndOperationsObjectABC
parameters:
- name: b_id
in: path
required: true
schema:
type: string
format: uuid
title: B Id
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
parameters:
- name: a_id
in: path
required: true
schema:
type: string
format: uuid
title: A Id
Loading

0 comments on commit 2778049

Please sign in to comment.