diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 49474c31ad..cd64024f5f 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -696,6 +696,7 @@ enum ApilintCodes { OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100, OPENAPI3_1_OPEN_API = 7010000, + OPENAPI3_1_OPEN_API_REQUIRED_FIELDS = 7010010, OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010100, OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, OPENAPI3_1_OPEN_API_FIELD_SERVERS_TYPE = 7010200, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts index 4502adfa11..91a09fcf35 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts @@ -126,7 +126,7 @@ const completion: ApidomCompletionItem[] = [ label: 'jsonSchemaDialect', insertText: 'jsonSchemaDialect', kind: 14, - format: CompletionFormat.UNQUOTED, + format: CompletionFormat.QUOTED, type: CompletionType.PROPERTY, insertTextFormat: 2, documentation: { diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts deleted file mode 100644 index 10aea7fceb..0000000000 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts +++ /dev/null @@ -1,32 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const componentsRequiredLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_REQUIRED, - source: 'apilint', - message: "should always have a 'components' section", - severity: 1, - linterFunction: 'hasRequiredField', - linterParams: ['components'], - marker: 'key', - // conditions: [ - // { - // // todo: fix setup so oas31 consists at least oneOf paths, components, webhooks - // targets: [{ path: 'openApi3_1' }], - // function: 'apilintContainsValue', - // params: ['components'], - // }, - // ], - data: { - quickFix: [ - { - message: "add 'components' section", - action: 'addChild', - snippetYaml: 'components: \n \n', - snippetJson: '"components": {\n \n },\n', - }, - ], - }, -}; - -export default componentsRequiredLint; 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 87e29acc3f..ffabc87468 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,12 +1,11 @@ import allowedFieldsLint from './allowed-fields'; +import requiredFieldsLint from './required-fields'; import componentsTypeLint from './components--type'; -import componentsRequiredLint from './components--required'; 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 pathsRequiredLint from './paths--required'; import securityItemsTypeLint from './security--items-type'; import securityTypeLint from './security--type'; import serversItemsTypeLint from './servers--items-type'; @@ -14,18 +13,16 @@ import serversTypeLint from './servers--type'; import tagsItemsTypeLint from './tags--items-type'; import tagsTypeLint from './tags--type'; import webhooksLint from './webhooks--type'; -import webhooksRequiredLint from './webhooks--required'; const lints = [ allowedFieldsLint, + requiredFieldsLint, componentsTypeLint, - componentsRequiredLint, externalDocsTypeLint, infoRequiredLint, infoTypeLint, jsonSchemaDialectFormatURILint, pathsTypeLint, - pathsRequiredLint, securityItemsTypeLint, securityTypeLint, serversItemsTypeLint, @@ -33,7 +30,6 @@ const lints = [ tagsItemsTypeLint, tagsTypeLint, webhooksLint, - webhooksRequiredLint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/required-fields.ts similarity index 50% rename from packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts rename to packages/apidom-ls/src/config/openapi/openapi3_1/lint/required-fields.ts index 95e2ae9a03..da7edea25b 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/required-fields.ts @@ -1,22 +1,21 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -const pathsRequiredLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_PATHS_REQUIRED, +const requiredFieldsLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_REQUIRED_FIELDS, source: 'apilint', - message: "should always have a 'paths' section", + message: 'OpenAPI Object must contain one the following fields: paths, components, webhooks', severity: 1, linterFunction: 'hasRequiredField', linterParams: ['paths'], marker: 'key', - // conditions: [ - // { - // // todo: fix setup so oas31 consists at least oneOf paths, components, webhooks - // targets: [{ path: 'openApi3_1' }], - // function: 'apilintContainsValue', - // params: ['paths'], - // }, - // ], + conditions: [ + { + targets: [{ path: 'root' }], + function: 'missingFields', + params: [['paths', 'components', 'webhooks']], + }, + ], data: { quickFix: [ { @@ -29,4 +28,4 @@ const pathsRequiredLint: LinterMeta = { }, }; -export default pathsRequiredLint; +export default requiredFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts deleted file mode 100644 index 3210b04686..0000000000 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts +++ /dev/null @@ -1,32 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const webhooksRequiredLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_REQUIRED, - source: 'apilint', - message: "should always have a 'webhooks' section", - severity: 1, - linterFunction: 'hasRequiredField', - linterParams: ['webhooks'], - marker: 'key', - // conditions: [ - // { - // // todo: fix setup so oas31 consists at least oneOf paths, components, webhooks - // targets: [{ path: 'openApi3_1' }], - // function: 'apilintContainsValue', - // params: ['webhooks'], - // }, - // ], - data: { - quickFix: [ - { - message: "add 'webhooks' section", - action: 'addChild', - snippetYaml: 'webhooks: \n \n', - snippetJson: '"webhooks": {\n \n },\n', - }, - ], - }, -}; - -export default webhooksRequiredLint;