From cc74e0c908b2a83018603f1f71cb70168771d412 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Tue, 25 Oct 2022 12:49:59 +0200 Subject: [PATCH] feat(ls): provide OpenAPI 3.0.x Reference lint rules Refs #2033 --- .../openapi/example/lint/$ref--no-siblings.ts | 30 ---------------- .../openapi/example/lint/$ref--valid.ts | 15 -------- .../example/lint/allowed-fields-3-0.ts | 21 ++++++++++++ .../openapi/example/lint/allowed-fields.ts | 14 -------- .../src/config/openapi/example/lint/index.ts | 8 ++--- .../request-body/lint/$ref--no-siblings.ts | 30 ---------------- .../openapi/request-body/lint/$ref--valid.ts | 15 -------- ...llowed-fields.ts => allowed-fields-3-0.ts} | 11 ++++-- .../config/openapi/request-body/lint/index.ts | 8 ++--- .../response/lint/allowed-fields-3-0.ts | 21 ++++++++++++ .../openapi/response/lint/allowed-fields.ts | 14 -------- .../src/config/openapi/response/lint/index.ts | 4 +-- .../lint/allowed-fields-3-0.ts | 34 +++++++++++++++++++ .../security-scheme/lint/allowed-fields.ts | 17 ---------- .../openapi/security-scheme/lint/index.ts | 4 +-- 15 files changed, 93 insertions(+), 153 deletions(-) delete mode 100644 packages/apidom-ls/src/config/openapi/example/lint/$ref--no-siblings.ts delete mode 100644 packages/apidom-ls/src/config/openapi/example/lint/$ref--valid.ts create mode 100644 packages/apidom-ls/src/config/openapi/example/lint/allowed-fields-3-0.ts delete mode 100644 packages/apidom-ls/src/config/openapi/example/lint/allowed-fields.ts delete mode 100644 packages/apidom-ls/src/config/openapi/request-body/lint/$ref--no-siblings.ts delete mode 100644 packages/apidom-ls/src/config/openapi/request-body/lint/$ref--valid.ts rename packages/apidom-ls/src/config/openapi/request-body/lint/{allowed-fields.ts => allowed-fields-3-0.ts} (50%) create mode 100644 packages/apidom-ls/src/config/openapi/response/lint/allowed-fields-3-0.ts delete mode 100644 packages/apidom-ls/src/config/openapi/response/lint/allowed-fields.ts create mode 100644 packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-0.ts delete mode 100644 packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields.ts diff --git a/packages/apidom-ls/src/config/openapi/example/lint/$ref--no-siblings.ts b/packages/apidom-ls/src/config/openapi/example/lint/$ref--no-siblings.ts deleted file mode 100644 index 4cf7e15399..0000000000 --- a/packages/apidom-ls/src/config/openapi/example/lint/$ref--no-siblings.ts +++ /dev/null @@ -1,30 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const $refNoSiblingsLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_EXAMPLE_FIELD_$REF_NO_SIBLINGS, - source: 'apilint', - message: 'All other properties in a "$ref" object are ignored', - severity: 2, - linterFunction: 'allowedFields', - linterParams: [['$ref']], - marker: 'key', - conditions: [ - { - function: 'existFields', - params: [['$ref']], - }, - ], - data: { - quickFix: [ - { - message: 'remove $ref', - action: 'removeChild', - functionParams: ['$ref'], - target: 'parent', - }, - ], - }, -}; - -export default $refNoSiblingsLint; diff --git a/packages/apidom-ls/src/config/openapi/example/lint/$ref--valid.ts b/packages/apidom-ls/src/config/openapi/example/lint/$ref--valid.ts deleted file mode 100644 index d16ee41016..0000000000 --- a/packages/apidom-ls/src/config/openapi/example/lint/$ref--valid.ts +++ /dev/null @@ -1,15 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const $refValidLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_EXAMPLE_FIELD_$REF_VALID, - source: 'apilint', - message: "'$ref' value must be a valid URI-reference", - severity: 1, - linterFunction: 'apilintValidURI', - marker: 'value', - target: '$ref', - data: {}, -}; - -export default $refValidLint; diff --git a/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields-3-0.ts b/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields-3-0.ts new file mode 100644 index 0000000000..96723bc7e5 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields-3-0.ts @@ -0,0 +1,21 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_0Lint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [['summary', 'description', 'value', 'externalValue', '$ref'], 'x-'], + marker: 'key', + targetSpecs: [ + { namespace: 'openapi', version: '3.0.0' }, + { namespace: 'openapi', version: '3.0.1' }, + { namespace: 'openapi', version: '3.0.2' }, + { namespace: 'openapi', version: '3.0.3' }, + ], +}; + +export default allowedFields3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields.ts deleted file mode 100644 index 0f3ce3768b..0000000000 --- a/packages/apidom-ls/src/config/openapi/example/lint/allowed-fields.ts +++ /dev/null @@ -1,14 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const allowedFieldsLint: LinterMeta = { - code: ApilintCodes.NOT_ALLOWED_FIELDS, - source: 'apilint', - message: 'Object includes not allowed fields', - severity: 1, - linterFunction: 'allowedFields', - linterParams: [['summary', 'description', 'value', 'externalValue'], 'x-'], - marker: 'key', -}; - -export default allowedFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/example/lint/index.ts b/packages/apidom-ls/src/config/openapi/example/lint/index.ts index d014ba20bb..250a260b42 100644 --- a/packages/apidom-ls/src/config/openapi/example/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/example/lint/index.ts @@ -1,6 +1,4 @@ -import allowedFieldsLint from './allowed-fields'; -import $refValidLint from './$ref--valid'; -import $refNoSiblingsLint from './$ref--no-siblings'; +import allowedFields3_0Lint from './allowed-fields-3-0'; import summaryTypeLint from './summary--type'; import descriptionTypeLint from './description--type'; import valueMutuallyExclusiveLint from './value--mutually-exclusive'; @@ -11,9 +9,7 @@ const lints = [ descriptionTypeLint, valueMutuallyExclusiveLint, externalValueFormatURILint, - $refValidLint, - $refNoSiblingsLint, - allowedFieldsLint, + allowedFields3_0Lint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--no-siblings.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--no-siblings.ts deleted file mode 100644 index 31177e6943..0000000000 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--no-siblings.ts +++ /dev/null @@ -1,30 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const $refNoSiblingsLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_$REF_NO_SIBLINGS, - source: 'apilint', - message: 'All other properties in a "$ref" object are ignored', - severity: 2, - linterFunction: 'allowedFields', - linterParams: [['$ref']], - marker: 'key', - conditions: [ - { - function: 'existFields', - params: [['$ref']], - }, - ], - data: { - quickFix: [ - { - message: 'remove $ref', - action: 'removeChild', - functionParams: ['$ref'], - target: 'parent', - }, - ], - }, -}; - -export default $refNoSiblingsLint; diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--valid.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--valid.ts deleted file mode 100644 index 330346f48f..0000000000 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref--valid.ts +++ /dev/null @@ -1,15 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const $refValidLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_$REF_VALID, - source: 'apilint', - message: "'$ref' value must be a valid URI-reference", - severity: 1, - linterFunction: 'apilintValidURI', - marker: 'value', - target: '$ref', - data: {}, -}; - -export default $refValidLint; diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields-3-0.ts similarity index 50% rename from packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields.ts rename to packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields-3-0.ts index 74f9d22966..7571bdf7e7 100644 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields.ts +++ b/packages/apidom-ls/src/config/openapi/request-body/lint/allowed-fields-3-0.ts @@ -1,7 +1,8 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -const allowedFieldsLint: LinterMeta = { +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_0Lint: LinterMeta = { code: ApilintCodes.NOT_ALLOWED_FIELDS, source: 'apilint', message: 'Object includes not allowed fields', @@ -9,6 +10,12 @@ const allowedFieldsLint: LinterMeta = { linterFunction: 'allowedFields', linterParams: [['description', 'content', 'required', '$ref'], 'x-'], marker: 'key', + targetSpecs: [ + { namespace: 'openapi', version: '3.0.0' }, + { namespace: 'openapi', version: '3.0.1' }, + { namespace: 'openapi', version: '3.0.2' }, + { namespace: 'openapi', version: '3.0.3' }, + ], }; -export default allowedFieldsLint; +export default allowedFields3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/index.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/index.ts index 4277ff59f9..38c812980f 100644 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/request-body/lint/index.ts @@ -1,19 +1,15 @@ -import allowedFieldsLint from './allowed-fields'; -import $refNoSiblingsLint from './$ref--no-siblings'; -import $refValidLint from './$ref--valid'; +import allowedFields3_0Lint from './allowed-fields-3-0'; import descriptionTypeLint from './description--type'; import contentValuesTypeLint from './content--values-type'; import contentRequiredLint from './content--required'; import requiredTypeLint from './required--type'; const lints = [ - allowedFieldsLint, - $refNoSiblingsLint, - $refValidLint, descriptionTypeLint, contentRequiredLint, contentValuesTypeLint, requiredTypeLint, + allowedFields3_0Lint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields-3-0.ts b/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields-3-0.ts new file mode 100644 index 0000000000..c16c0c58c6 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields-3-0.ts @@ -0,0 +1,21 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_0Lint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [['description', 'headers', 'content', 'links', '$ref'], 'x-'], + marker: 'key', + targetSpecs: [ + { namespace: 'openapi', version: '3.0.0' }, + { namespace: 'openapi', version: '3.0.1' }, + { namespace: 'openapi', version: '3.0.2' }, + { namespace: 'openapi', version: '3.0.3' }, + ], +}; + +export default allowedFields3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields.ts deleted file mode 100644 index f1939fd011..0000000000 --- a/packages/apidom-ls/src/config/openapi/response/lint/allowed-fields.ts +++ /dev/null @@ -1,14 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const allowedFieldsLint: LinterMeta = { - code: ApilintCodes.NOT_ALLOWED_FIELDS, - source: 'apilint', - message: 'Object includes not allowed fields', - severity: 1, - linterFunction: 'allowedFields', - linterParams: [['description', 'headers', 'content', 'links'], 'x-'], - marker: 'key', -}; - -export default allowedFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/response/lint/index.ts b/packages/apidom-ls/src/config/openapi/response/lint/index.ts index ef8f95275b..905b783b5f 100644 --- a/packages/apidom-ls/src/config/openapi/response/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/response/lint/index.ts @@ -1,4 +1,4 @@ -import allowedFieldsLint from './allowed-fields'; +import allowedFields3_0Lint from './allowed-fields-3-0'; import descriptionTypeLint from './description--type'; import descriptionRequiredLint from './description--required'; import headersValuesTypeLint from './headers--values-type'; @@ -11,7 +11,7 @@ const lints = [ headersValuesTypeLint, contentValuesTypeLint, linksValuesTypeLint, - allowedFieldsLint, + allowedFields3_0Lint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-0.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-0.ts new file mode 100644 index 0000000000..7cf8d0d95a --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-0.ts @@ -0,0 +1,34 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_0Lint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'type', + 'description', + 'name', + 'in', + 'scheme', + 'bearerFormat', + 'flows', + 'openIdConnectUrl', + '$ref', + ], + 'x-', + ], + marker: 'key', + targetSpecs: [ + { namespace: 'openapi', version: '3.0.0' }, + { namespace: 'openapi', version: '3.0.1' }, + { namespace: 'openapi', version: '3.0.2' }, + { namespace: 'openapi', version: '3.0.3' }, + ], +}; + +export default allowedFields3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields.ts deleted file mode 100644 index ed22057183..0000000000 --- a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields.ts +++ /dev/null @@ -1,17 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const allowedFieldsLint: LinterMeta = { - code: ApilintCodes.NOT_ALLOWED_FIELDS, - source: 'apilint', - message: 'Object includes not allowed fields', - severity: 1, - linterFunction: 'allowedFields', - linterParams: [ - ['type', 'description', 'name', 'in', 'scheme', 'bearerFormat', 'flows', 'openIdConnectUrl'], - 'x-', - ], - marker: 'key', -}; - -export default allowedFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts index 6a2b6f420d..2266219c12 100644 --- a/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts @@ -1,4 +1,4 @@ -import allowedFieldsLint from './allowed-fields'; +import allowedFields3_0Lint from './allowed-fields-3-0'; import typeEquals3_0Lint from './type--equals-3-0'; import descriptionTypeLint from './description--type'; import nameTypeLint from './name--type'; @@ -27,7 +27,7 @@ const lints = [ flowsRequiredLint, openIdConnectUrlFormatURILint, openIdConnectUrlRequiredLint, - allowedFieldsLint, + allowedFields3_0Lint, ]; export default lints;