From e72e0f7ac8817086390aae6345336b3124a752cf Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 16 Dec 2022 11:57:08 +0100 Subject: [PATCH] fix(ls): add OpenAPI 3.x lint rule for Header.schema field The rule is concerned with mutual exclusivity between Header.content and Header.schema field. --- packages/apidom-ls/src/config/codes.ts | 1 + .../src/config/openapi/header/lint/index.ts | 2 ++ .../header/lint/schema--mutually-exclusive.ts | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/schema--mutually-exclusive.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 330b6fdbb1..57dd61132c 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -837,6 +837,7 @@ enum ApilintCodes { OPENAPI3_0_HEADER_FIELD_EXPLODE_TYPE = 5280600, OPENAPI3_0_HEADER_FIELD_ALLOW_RESERVED_TYPE = 5280700, OPENAPI3_0_HEADER_FIELD_SCHEMA_TYPE = 5280800, + OPENAPI3_0_HEADER_FIELD_SCHEMA_MUTUALLY_EXCLUSIVE, OPENAPI3_0_HEADER_FIELD_EXAMPLES_VALUES_TYPE = 5280900, OPENAPI3_0_HEADER_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE, OPENAPI3_0_HEADER_FIELD_CONTENT_VALUES_TYPE = 5281000, diff --git a/packages/apidom-ls/src/config/openapi/header/lint/index.ts b/packages/apidom-ls/src/config/openapi/header/lint/index.ts index 165a258b8e..65bd4d52fd 100644 --- a/packages/apidom-ls/src/config/openapi/header/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/header/lint/index.ts @@ -8,6 +8,7 @@ import styleTypeLint from './style--type'; import explodeTypeLint from './explode--type'; import allowReservedTypeLint from './allow-reserved--type'; import schemaTypeLint from './schema--type'; +import schemaMutuallyExclusiveLint from './schema--mutually-exclusive'; import examplesValuesTypeLint from './examples--values-type'; import examplesMutuallyExclusiveLint from './examples--mutually-exclusive'; import contentValuesTypeLint from './content--values-type'; @@ -21,6 +22,7 @@ const lints = [ explodeTypeLint, allowReservedTypeLint, schemaTypeLint, + schemaMutuallyExclusiveLint, examplesValuesTypeLint, examplesMutuallyExclusiveLint, contentValuesTypeLint, diff --git a/packages/apidom-ls/src/config/openapi/header/lint/schema--mutually-exclusive.ts b/packages/apidom-ls/src/config/openapi/header/lint/schema--mutually-exclusive.ts new file mode 100644 index 0000000000..2f741a1955 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/schema--mutually-exclusive.ts @@ -0,0 +1,23 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const schemaMutuallyExclusiveLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_SCHEMA_MUTUALLY_EXCLUSIVE, + source: 'apilint', + message: 'The `schema` field and `content` field are mutually exclusive.', + severity: DiagnosticSeverity.Error, + linterFunction: 'missingFields', + linterParams: [['schema']], + marker: 'key', + markerTarget: 'schema', + conditions: [ + { + function: 'existFields', + params: [['content']], + }, + ], +}; + +export default schemaMutuallyExclusiveLint;