From 8e2b75a7a7cfab8f9ca81dc072cef3de5cd01806 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Mon, 10 Oct 2022 13:45:32 -0700 Subject: [PATCH] feat(ls): oas31 lint rules for components object --- packages/apidom-ls/src/config/codes.ts | 2 ++ .../components/lint/allowed-fields-3-1.ts | 30 +++++++++++++++++++ .../config/openapi/components/lint/index.ts | 4 +++ .../lint/path-items--values-type.ts | 17 +++++++++++ 4 files changed, 53 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/components/lint/allowed-fields-3-1.ts create mode 100644 packages/apidom-ls/src/config/openapi/components/lint/path-items--values-type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 3e401209a6..6e56105b36 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -726,6 +726,8 @@ enum ApilintCodes { OPENAPI3_1_INFO = 7010000, OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7010100, + OPENAPI3_1_COMPONENTS_FIELD_PATH_ITEMS_VALUES_TYPE = 7061000, + ADS = 8000000, ADS_INFO = 8010000, ADS_INFO_REQUIRED = 8010010, diff --git a/packages/apidom-ls/src/config/openapi/components/lint/allowed-fields-3-1.ts b/packages/apidom-ls/src/config/openapi/components/lint/allowed-fields-3-1.ts new file mode 100644 index 0000000000..b32803b6f1 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/components/lint/allowed-fields-3-1.ts @@ -0,0 +1,30 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFieldsLint3_1: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'schemas', + 'responses', + 'parameters', + 'examples', + 'requestBodies', + 'headers', + 'securitySchemes', + 'links', + 'callbacks', + 'pathItems', + ], + 'x-', + ], + marker: 'key', + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default allowedFieldsLint3_1; diff --git a/packages/apidom-ls/src/config/openapi/components/lint/index.ts b/packages/apidom-ls/src/config/openapi/components/lint/index.ts index c3b856401c..112dd44fe7 100644 --- a/packages/apidom-ls/src/config/openapi/components/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/components/lint/index.ts @@ -1,4 +1,5 @@ import allowedFields3_0Lint from './allowed-fields-3-0'; +import allowedFieldsLint3_1 from './allowed-fields-3-1'; import schemasValuesTypeLint from './schemas--values-type'; import responsesValuesTypeLint from './responses--values-type'; import parametersValuesTypeLint from './parameters--values-type'; @@ -9,6 +10,7 @@ import securitySchemesValuesType from './security-schemes--values-type'; import linksValuesTypeLint from './links--values-type'; import callbacksValuesTypeLint from './callbacks--values-type'; import keysPatternLint from './keys--pattern'; +import pathItemsValuesTypeLint from './path-items--values-type'; const lints = [ schemasValuesTypeLint, @@ -21,7 +23,9 @@ const lints = [ linksValuesTypeLint, callbacksValuesTypeLint, keysPatternLint, + pathItemsValuesTypeLint, allowedFields3_0Lint, + allowedFieldsLint3_1, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/components/lint/path-items--values-type.ts b/packages/apidom-ls/src/config/openapi/components/lint/path-items--values-type.ts new file mode 100644 index 0000000000..cc848d2fb6 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/components/lint/path-items--values-type.ts @@ -0,0 +1,17 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const pathItemsValuesTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_COMPONENTS_FIELD_PATH_ITEMS_VALUES_TYPE, + source: 'apilint', + message: '"pathItems" members must be Path Item Object', + severity: 1, + linterFunction: 'apilintChildrenOfElementsOrClasses', + linterParams: [['pathItem']], + marker: 'key', + markerTarget: 'pathItems', + target: 'pathItems', + data: {}, +}; + +export default pathItemsValuesTypeLint;