From 70c34fdffc2b5b48375ef564b4905ff780e21242 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Fri, 21 Oct 2022 11:02:16 -0700 Subject: [PATCH] feat(ls): OpenAPI 3.x.x mutually exclusive lint rule for Media Type --- packages/apidom-ls/src/config/codes.ts | 1 + .../lint/examples--mutually-exclusive.ts | 21 +++++++++++++++++++ .../config/openapi/media-type/lint/index.ts | 9 +++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/apidom-ls/src/config/openapi/media-type/lint/examples--mutually-exclusive.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index ef290dbecd..d153ea3dba 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -723,6 +723,7 @@ enum ApilintCodes { OPENAPI3_0_MEDIA_TYPE_FIELD_SCHEMA_VALUES_TYPE = 5170100, OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_VALUES_TYPE = 5170200, OPENAPI3_0_MEDIA_TYPE_FIELD_ENCODING_VALUES_TYPE = 5170300, + OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE, OPENAPI3_0_ENCODING = 5180000, OPENAPI3_0_ENCODING_FIELD_CONTENT_TYPE_TYPE = 5180100, diff --git a/packages/apidom-ls/src/config/openapi/media-type/lint/examples--mutually-exclusive.ts b/packages/apidom-ls/src/config/openapi/media-type/lint/examples--mutually-exclusive.ts new file mode 100644 index 0000000000..7cf99e8c1a --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/media-type/lint/examples--mutually-exclusive.ts @@ -0,0 +1,21 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const examplesMutuallyExclusiveLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE, + source: 'apilint', + message: 'The `example` field and `examples` field are mutually exclusive.', + severity: 1, + linterFunction: 'missingFields', + linterParams: [['examples']], + marker: 'key', + markerTarget: 'examples', + conditions: [ + { + function: 'existFields', + params: [['example']], + }, + ], +}; + +export default examplesMutuallyExclusiveLint; diff --git a/packages/apidom-ls/src/config/openapi/media-type/lint/index.ts b/packages/apidom-ls/src/config/openapi/media-type/lint/index.ts index a2df63b9d9..9226c5fe31 100644 --- a/packages/apidom-ls/src/config/openapi/media-type/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/media-type/lint/index.ts @@ -2,7 +2,14 @@ import allowedFieldsLint from './allowed-fields'; import schemaTypeLint from './schema--type'; import examplesValuesTypeLint from './examples--values-type'; import encodingValuesTypeLint from './encoding--values-type'; +import examplesMutuallyExclusiveLint from './examples--mutually-exclusive'; -const lints = [schemaTypeLint, examplesValuesTypeLint, encodingValuesTypeLint, allowedFieldsLint]; +const lints = [ + schemaTypeLint, + examplesValuesTypeLint, + encodingValuesTypeLint, + allowedFieldsLint, + examplesMutuallyExclusiveLint, +]; export default lints;