Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Path Item Object
Browse files Browse the repository at this point in the history
Refs #3104
  • Loading branch information
char0n committed Dec 19, 2023
1 parent d26cb00 commit bc7f7cf
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 37 deletions.
12 changes: 12 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,18 @@ enum ApilintCodes {
OPENAPI2_PATHS = 3060000,
OPENAPI2_PATHS_VALUES_TYPE = 3060100,

OPENAPI2_PATH_ITEM = 3070000,
OPENAPI2_PATH_ITEM_FIELD_$REF_FORMAT_URI = 3070100,
OPENAPI2_PATH_ITEM_FIELD_GET_TYPE = 3070200,
OPENAPI2_PATH_ITEM_FIELD_PUT_TYPE = 3070300,
OPENAPI2_PATH_ITEM_FIELD_POST_TYPE = 3070400,
OPENAPI2_PATH_ITEM_FIELD_DELETE_TYPE = 3070500,
OPENAPI2_PATH_ITEM_FIELD_OPTIONS_TYPE = 3070600,
OPENAPI2_PATH_ITEM_FIELD_HEAD_TYPE = 3070700,
OPENAPI2_PATH_ITEM_FIELD_PATCH_TYPE = 3070800,
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE = 3070900,
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE = 3071000,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
128 changes: 127 additions & 1 deletion packages/apidom-ls/src/config/openapi/path-item/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
label: '$ref',
insertText: '\\$ref',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemObject). If there are conflicts between the referenced',
},
targetSpecs: OpenAPI2,
},
{
label: '$ref',
insertText: '\\$ref',
Expand Down Expand Up @@ -60,6 +74,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'get',
insertText: 'get',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a GET operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'get',
insertText: 'get',
Expand Down Expand Up @@ -102,6 +130,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI30,
},
{
label: 'put',
insertText: 'put',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a PUT operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'put',
insertText: 'put',
Expand All @@ -116,6 +158,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'post',
insertText: 'post',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a POST operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'post',
insertText: 'post',
Expand Down Expand Up @@ -144,6 +200,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'delete',
insertText: 'delete',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a DELETE operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'delete',
insertText: 'delete',
Expand Down Expand Up @@ -172,6 +242,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'options',
insertText: 'options',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a OPTIONS operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'options',
insertText: 'options',
Expand Down Expand Up @@ -200,6 +284,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'head',
insertText: 'head',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a HEAD operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'head',
insertText: 'head',
Expand Down Expand Up @@ -228,6 +326,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'patch',
insertText: 'patch',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a PATCH operation on this path.',
},
targetSpecs: OpenAPI2,
},
{
label: 'patch',
insertText: 'patch',
Expand Down Expand Up @@ -312,6 +424,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'parameters',
insertText: 'parameters',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.',
},
targetSpecs: OpenAPI2,
},
{
label: 'parameters',
insertText: 'parameters',
Expand Down
24 changes: 19 additions & 5 deletions packages/apidom-ls/src/config/openapi/path-item/documentation.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const $refFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_$REF_FORMAT_URI,
source: 'apilint',
message: "'$ref' value must be a valid URI-reference",
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintValidURI',
marker: 'value',
target: '$ref',
data: {},
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default $refFormatURILint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2 } from '../../target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields2_0Lint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: DiagnosticSeverity.Error,
linterFunction: 'allowedFields',
linterParams: [
[
'$ref',
'summary',
'description',
'get',
'put',
'post',
'delete',
'options',
'head',
'patch',
'parameters',
],
'x-',
],
marker: 'key',
targetSpecs: OpenAPI2,
};
export default allowedFields2_0Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const deleteTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_DELETE_TYPE,
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_DELETE_TYPE,
source: 'apilint',
message: '"delete" must be in a shape of the Operation Object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const deleteTypeLint: LinterMeta = {
marker: 'value',
target: 'delete',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default deleteTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const getTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_GET_TYPE,
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_GET_TYPE,
source: 'apilint',
message: '"get" must be in a shape of the Operation Object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const getTypeLint: LinterMeta = {
marker: 'value',
target: 'get',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default getTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const headTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_HEAD_TYPE,
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_HEAD_TYPE,
source: 'apilint',
message: '"head" must be in a shape of the Operation Object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const headTypeLint: LinterMeta = {
marker: 'value',
target: 'head',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default headTypeLint;
4 changes: 4 additions & 0 deletions packages/apidom-ls/src/config/openapi/path-item/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import allowedFields2_0Lint from './allowed-fields-2-0';
import allowedFields3_0Lint from './allowed-fields-3-0';
import allowedFields3_1Lint from './allowed-fields-3-1';
import $refFormatURILint from './$ref--format-uri';
import summaryTypeLint from './summary--type';
import descriptionTypeLint from './description--type';
import getTypeLint from './get--type';
Expand All @@ -16,6 +18,7 @@ import parametersTypeLint from './parameters--type';
import parametersItemsTypeLint from './parameters--items-type';

const lints = [
$refFormatURILint,
summaryTypeLint,
descriptionTypeLint,
getTypeLint,
Expand All @@ -30,6 +33,7 @@ const lints = [
serversItemsTypeLint,
parametersTypeLint,
parametersItemsTypeLint,
allowedFields2_0Lint,
allowedFields3_0Lint,
allowedFields3_1Lint,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const optionsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_OPTIONS_TYPE,
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_OPTIONS_TYPE,
source: 'apilint',
message: '"options" must be in a shape of the Operation Object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const optionsTypeLint: LinterMeta = {
marker: 'value',
target: 'options',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default optionsTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const parametersItemsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE,
code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE,
source: 'apilint',
message: 'parameters must be an array of Parameter Objects',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const parametersItemsTypeLint: LinterMeta = {
marker: 'key',
target: 'parameters',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default parametersItemsTypeLint;

0 comments on commit bc7f7cf

Please sign in to comment.