diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 09688b36be..e3652ef384 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -749,6 +749,7 @@ enum ApilintCodes { OPENAPI3_0_PARAMETER_FIELD_EXAMPLES_VALUES_TYPE = 5151000, OPENAPI3_0_PARAMETER_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE, OPENAPI3_0_PARAMETER_FIELD_CONTENT_VALUES_TYPE = 5151100, + OPENAPI3_0_PARAMETER_FIELD_CONTENT_ALLOWED_FIELDS, OPENAPI3_0_REQUEST_BODY = 5160000, OPENAPI3_0_REQUEST_BODY_FIELD_DESCRIPTION_TYPE = 5160200, @@ -893,6 +894,9 @@ enum ApilintCodes { OPENAPI3_1_SERVER_VARIABLE = 7060000, OPENAPI3_1_SERVER_VARIABLE_FIELD_ENUM_TYPE = 7060100, + OPENAPI3_1_PARAMETER = 7070000, + OPENAPI3_1_PARAMETER_FIELD_CONTENT_ALLOWED_FIELDS = 7070100, + ADS = 8000000, ADS_INFO = 8010000, diff --git a/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-0.ts b/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-0.ts new file mode 100644 index 0000000000..29b4e3fb00 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-0.ts @@ -0,0 +1,43 @@ +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 contentAllowedFields3_0Lint: LinterMeta = { + code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_CONTENT_ALLOWED_FIELDS, + source: 'apilint', + message: + 'If "content" field is present, following fields are not allowed: style, explode, allowReserved, example and examples', + severity: DiagnosticSeverity.Error, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'name', + 'in', + 'description', + 'required', + 'deprecated', + 'allowEmptyValue', + 'schema', + 'content', + '$ref', + ], + 'x-', + ], + marker: 'key', + conditions: [ + { + function: 'existFields', + params: [['content']], + }, + ], + 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 contentAllowedFields3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-1.ts b/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-1.ts new file mode 100644 index 0000000000..b7048872ac --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/parameter/lint/content--allowed-fields-3-1.ts @@ -0,0 +1,32 @@ +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 contentAllowedFields3_1Lint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_PARAMETER_FIELD_CONTENT_ALLOWED_FIELDS, + source: 'apilint', + message: + 'If "content" field is present, following fields are not allowed: style, explode, allowReserved, example and examples', + severity: DiagnosticSeverity.Error, + linterFunction: 'allowedFields', + linterParams: [ + ['name', 'in', 'description', 'required', 'deprecated', 'allowEmptyValue', 'schema', 'content'], + 'x-', + ], + marker: 'key', + conditions: [ + { + function: 'existFields', + params: [['content']], + }, + { + function: 'missingField', + params: ['$ref'], + }, + ], + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default contentAllowedFields3_1Lint; diff --git a/packages/apidom-ls/src/config/openapi/parameter/lint/index.ts b/packages/apidom-ls/src/config/openapi/parameter/lint/index.ts index 45da419f3b..fc233c0fb3 100644 --- a/packages/apidom-ls/src/config/openapi/parameter/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/parameter/lint/index.ts @@ -19,6 +19,8 @@ import schemaMutuallyExclusiveLint from './schema--mutually-exclusive'; import examplesValuesTypeLint from './examples--values-type'; import examplesMutuallyExclusiveLint from './examples--mutually-exclusive'; import contentValuesTypeLint from './content--values-type'; +import contentAllowedFields3_0Lint from './content--allowed-fields-3-0'; +import contentAllowedFields3_1Lint from './content--allowed-fields-3-1'; const lints = [ nameTypeLint, @@ -39,6 +41,8 @@ const lints = [ examplesValuesTypeLint, examplesMutuallyExclusiveLint, contentValuesTypeLint, + contentAllowedFields3_0Lint, + contentAllowedFields3_1Lint, requiredFieldsLint, allowedFields3_0Lint, allowedFields3_1Lint,