From f758bca90f58199fa01787633ed92ac028045416 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 5 Oct 2022 13:07:55 -0700 Subject: [PATCH] feat(ls): additional oas31 lint rules --- packages/apidom-ls/src/config/codes.ts | 16 ++++++++--- .../openapi3_1/lint/components--type.ts | 16 +++++++++++ .../openapi3_1/lint/external-docs--type.ts | 16 +++++++++++ .../config/openapi/openapi3_1/lint/index.ts | 27 ++++++++++++++++++- .../openapi/openapi3_1/lint/info--type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/paths--type.ts | 16 +++++++++++ .../openapi3_1/lint/security--items-type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/security--type.ts | 16 +++++++++++ .../openapi3_1/lint/servers--items-type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/servers--type.ts | 16 +++++++++++ .../openapi3_1/lint/tags--items-type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/tags--type.ts | 16 +++++++++++ 12 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/external-docs--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--items-type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--items-type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--items-type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index b60bda3b58..e6567841c0 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -696,10 +696,20 @@ enum ApilintCodes { OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100, OPENAPI3_1_OPEN_API = 7010000, - OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, - OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010200, - OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010300, + OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010100, OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, + OPENAPI3_1_OPEN_API_FIELD_SERVERS_TYPE = 7010200, + OPENAPI3_1_OPEN_API_FIELD_SERVERS_ITEMS_TYPE, + OPENAPI3_1_OPEN_API_FIELD_PATHS_TYPE = 7010300, + OPENAPI3_1_OPEN_API_FIELD_PATHS_REQUIRED, + OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_TYPE = 7010400, + OPENAPI3_1_OPEN_API_FIELD_SECURITY_TYPE = 7010500, + OPENAPI3_1_OPEN_API_FIELD_SECURITY_ITEMS_TYPE, + OPENAPI3_1_OPEN_API_FIELD_TAGS_TYPE = 7010600, + OPENAPI3_1_OPEN_API_FIELD_TAGS_ITEMS_TYPE, + OPENAPI3_1_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE = 7010700, + OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010800, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900, OPENAPI3_1_INFO = 7020000, OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--type.ts new file mode 100644 index 0000000000..c03b83aacf --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const componentsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_TYPE, + source: 'apilint', + message: 'components must be an object', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['components'], + marker: 'value', + target: 'components', + data: {}, +}; + +export default componentsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/external-docs--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/external-docs--type.ts new file mode 100644 index 0000000000..6b0726e3f1 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/external-docs--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const externalDocsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE, + source: 'apilint', + message: 'externalDocs must be an object', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['externalDocumentation'], + marker: 'value', + target: 'externalDocs', + data: {}, +}; + +export default externalDocsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts index 5deebd6ab5..d3aa9c9169 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts @@ -1,8 +1,33 @@ import allowedFieldsLint from './allowed-fields'; +import componentsTypeLint from './components--type'; +import externalDocsTypeLint from './external-docs--type'; import infoRequiredLint from './info--required'; +import infoTypeLint from './info--type'; import jsonSchemaDialectFormatURILint from './jsonSchemaDialect--format-uri'; +import pathsTypeLint from './paths--type'; +import securityItemsTypeLint from './security--items-type'; +import securityTypeLint from './security--type'; +import serversItemsTypeLint from './servers--items-type'; +import serversTypeLint from './servers--type'; +import tagsItemsTypeLint from './tags--items-type'; +import tagsTypeLint from './tags--type'; import webhooksLint from './webhooks--type'; -const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectFormatURILint, webhooksLint]; +const lints = [ + allowedFieldsLint, + componentsTypeLint, + externalDocsTypeLint, + infoRequiredLint, + infoTypeLint, + jsonSchemaDialectFormatURILint, + pathsTypeLint, + securityItemsTypeLint, + securityTypeLint, + serversItemsTypeLint, + serversTypeLint, + tagsItemsTypeLint, + tagsTypeLint, + webhooksLint, +]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--type.ts new file mode 100644 index 0000000000..82a0a641fe --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const infoTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE, + source: 'apilint', + message: 'info must be an object', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['info'], + marker: 'value', + target: 'info', + data: {}, +}; + +export default infoTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--type.ts new file mode 100644 index 0000000000..314e69547c --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const pathsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_PATHS_TYPE, + source: 'apilint', + message: 'paths must be an object', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['paths'], + marker: 'value', + target: 'paths', + data: {}, +}; + +export default pathsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--items-type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--items-type.ts new file mode 100644 index 0000000000..808cc09e34 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--items-type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const securityItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SECURITY_ITEMS_TYPE, + source: 'apilint', + message: 'security must be an array of Security Requirement Objects', + severity: 1, + linterFunction: 'apilintArrayOfElementsOrClasses', + linterParams: [['securityRequirement']], + marker: 'key', + target: 'security', + data: {}, +}; + +export default securityItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--type.ts new file mode 100644 index 0000000000..a144cd700d --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/security--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const securityTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SECURITY_TYPE, + source: 'apilint', + message: 'security must be an array', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['security'], + marker: 'value', + target: 'security', + data: {}, +}; + +export default securityTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--items-type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--items-type.ts new file mode 100644 index 0000000000..0a3f61766c --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--items-type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const serverItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SERVERS_ITEMS_TYPE, + source: 'apilint', + message: 'servers must be an array of Server Objects', + severity: 1, + linterFunction: 'apilintArrayOfElementsOrClasses', + linterParams: [['server']], + marker: 'key', + target: 'servers', + data: {}, +}; + +export default serverItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--type.ts new file mode 100644 index 0000000000..5f4cef82c5 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/servers--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const serversTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SERVERS_TYPE, + source: 'apilint', + message: 'servers must be an array', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['servers'], + marker: 'value', + target: 'servers', + data: {}, +}; + +export default serversTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--items-type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--items-type.ts new file mode 100644 index 0000000000..8c581e9cab --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--items-type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const tagsItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_TAGS_ITEMS_TYPE, + source: 'apilint', + message: 'tags must be an array of Tag Objects', + severity: 1, + linterFunction: 'apilintArrayOfElementsOrClasses', + linterParams: [['tag']], + marker: 'key', + target: 'tags', + data: {}, +}; + +export default tagsItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--type.ts new file mode 100644 index 0000000000..0243ad12b0 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/tags--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const tagsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_TAGS_TYPE, + source: 'apilint', + message: 'tags must be an array', + severity: 1, + linterFunction: 'apilintElementOrClass', + linterParams: ['tags'], + marker: 'value', + target: 'tags', + data: {}, +}; + +export default tagsTypeLint;