From 67f3660188b989ecef9063477808baf278e4ebe9 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Mon, 26 Dec 2022 09:51:22 +0100 Subject: [PATCH] fix(ls): add lint rules for OpenAPI 3.1 Reference Object Affected fields: - description - summary --- packages/apidom-ls/src/config/codes.ts | 2 ++ ...blings-3-0.ts => $ref-3-0--no-siblings.ts} | 4 ++-- ...s-3-1.ts => $ref-3-1--allowed-siblings.ts} | 4 ++-- .../reference/lint/description-3-1--type.ts | 20 +++++++++++++++++++ .../config/openapi/reference/lint/index.ts | 14 ++++++++++--- .../reference/lint/summary-3-1--type.ts | 20 +++++++++++++++++++ 6 files changed, 57 insertions(+), 7 deletions(-) rename packages/apidom-ls/src/config/openapi/reference/lint/{$ref--no-siblings-3-0.ts => $ref-3-0--no-siblings.ts} (92%) rename packages/apidom-ls/src/config/openapi/reference/lint/{$ref--allowed-siblings-3-1.ts => $ref-3-1--allowed-siblings.ts} (89%) create mode 100644 packages/apidom-ls/src/config/openapi/reference/lint/description-3-1--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/reference/lint/summary-3-1--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 92ba7ab776..d1394cfa5f 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -888,6 +888,8 @@ enum ApilintCodes { OPENAPI3_1_REFERENCE = 7040000, OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS = 7040100, + OPENAPI3_1_REFERENCE_FIELD_DESCRIPTION_TYPE = 7040200, + OPENAPI3_1_REFERENCE_FIELD_SUMMARY_TYPE = 7040300, OPENAPI3_1_SECURITY_SCHEME = 7050000, OPENAPI3_1_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 7050100, diff --git a/packages/apidom-ls/src/config/openapi/reference/lint/$ref--no-siblings-3-0.ts b/packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-0--no-siblings.ts similarity index 92% rename from packages/apidom-ls/src/config/openapi/reference/lint/$ref--no-siblings-3-0.ts rename to packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-0--no-siblings.ts index 29240ebb81..71074d5401 100644 --- a/packages/apidom-ls/src/config/openapi/reference/lint/$ref--no-siblings-3-0.ts +++ b/packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-0--no-siblings.ts @@ -4,7 +4,7 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; // eslint-disable-next-line @typescript-eslint/naming-convention -const $refNoSiblings3_0Lint: LinterMeta = { +const $ref3_0NoSiblingsLint: LinterMeta = { code: ApilintCodes.OPENAPI3_0_REFERENCE_FIELD_$REF_NO_SIBLINGS, source: 'apilint', message: 'All other properties in a "$ref" object are ignored', @@ -36,4 +36,4 @@ const $refNoSiblings3_0Lint: LinterMeta = { ], }; -export default $refNoSiblings3_0Lint; +export default $ref3_0NoSiblingsLint; diff --git a/packages/apidom-ls/src/config/openapi/reference/lint/$ref--allowed-siblings-3-1.ts b/packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-1--allowed-siblings.ts similarity index 89% rename from packages/apidom-ls/src/config/openapi/reference/lint/$ref--allowed-siblings-3-1.ts rename to packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-1--allowed-siblings.ts index 5113a75745..6813b90264 100644 --- a/packages/apidom-ls/src/config/openapi/reference/lint/$ref--allowed-siblings-3-1.ts +++ b/packages/apidom-ls/src/config/openapi/reference/lint/$ref-3-1--allowed-siblings.ts @@ -4,7 +4,7 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; // eslint-disable-next-line @typescript-eslint/naming-convention -const $refAllowedSiblings3_1Lint: LinterMeta = { +const $ref3_1AllowedSiblingsLint: LinterMeta = { code: ApilintCodes.OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS, source: 'apilint', message: @@ -23,4 +23,4 @@ const $refAllowedSiblings3_1Lint: LinterMeta = { targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], }; -export default $refAllowedSiblings3_1Lint; +export default $ref3_1AllowedSiblingsLint; diff --git a/packages/apidom-ls/src/config/openapi/reference/lint/description-3-1--type.ts b/packages/apidom-ls/src/config/openapi/reference/lint/description-3-1--type.ts new file mode 100644 index 0000000000..4bf0481b03 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/reference/lint/description-3-1--type.ts @@ -0,0 +1,20 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const description3_1TypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_REFERENCE_FIELD_DESCRIPTION_TYPE, + source: 'apilint', + message: 'description must be a string', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'description', + data: {}, + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default description3_1TypeLint; diff --git a/packages/apidom-ls/src/config/openapi/reference/lint/index.ts b/packages/apidom-ls/src/config/openapi/reference/lint/index.ts index 1e1dee9036..0cff46b1e6 100644 --- a/packages/apidom-ls/src/config/openapi/reference/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/reference/lint/index.ts @@ -1,7 +1,15 @@ import $refFormatURILint from './$ref--format-uri'; -import $refNoSiblings3_0Lint from './$ref--no-siblings-3-0'; -import $refAllowedSiblings3_1Lint from './$ref--allowed-siblings-3-1'; +import $ref3_0NoSiblingsLint from './$ref-3-0--no-siblings'; +import $ref3_1AllowedSiblingsLint from './$ref-3-1--allowed-siblings'; +import description3_1TypeLint from './description-3-1--type'; +import summary3_1TypeLint from './summary-3-1--type'; -const lints = [$refFormatURILint, $refNoSiblings3_0Lint, $refAllowedSiblings3_1Lint]; +const lints = [ + $refFormatURILint, + $ref3_0NoSiblingsLint, + $ref3_1AllowedSiblingsLint, + description3_1TypeLint, + summary3_1TypeLint, +]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/reference/lint/summary-3-1--type.ts b/packages/apidom-ls/src/config/openapi/reference/lint/summary-3-1--type.ts new file mode 100644 index 0000000000..e41c5a6391 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/reference/lint/summary-3-1--type.ts @@ -0,0 +1,20 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const summary3_1TypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_REFERENCE_FIELD_SUMMARY_TYPE, + source: 'apilint', + message: 'summary must be a string', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'summary', + data: {}, + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default summary3_1TypeLint;