From 7ff19e44ed7d9d49f6660752456d85bd8123738c Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 12:55:44 -0700 Subject: [PATCH 01/26] fix(ls): oas31 docs formatting --- .../apidom-ls/src/config/openapi/openapi3_1/documentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts index 241c4fab29..1823ccca7a 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts @@ -13,7 +13,7 @@ const documentation = [ { target: 'openapi', - docs: '`**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', + docs: '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', }, { target: 'jsonSchemaDialect', From 32d2b20f67c7863f57f4cabc12a1e155e95adfce Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 13:02:25 -0700 Subject: [PATCH 02/26] feat(ls): oas31 completion rules for top level objects --- .../config/openapi/openapi3_1/completion.ts | 140 ++++++++++++++++++ .../src/config/openapi/openapi3_1/meta.ts | 2 + 2 files changed, 142 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts new file mode 100644 index 0000000000..68e61dd2ab --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts @@ -0,0 +1,140 @@ +import { + ApidomCompletionItem, + CompletionFormat, + CompletionType, +} from '../../../apidom-language-types'; + +const completion: ApidomCompletionItem[] = [ + { + label: 'openapi', + insertText: 'openapi', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '**REQUIRED**. This string MUST be the [semantic version number](https://semver.org/spec/v2.0.0.html) of the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string', + }, + }, + { + label: 'info', + insertText: 'info', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', + }, + }, + { + label: 'servers', + insertText: 'servers', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + }, + { + label: 'paths', + insertText: 'paths', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + }, + { + label: 'components', + insertText: 'components', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + }, + { + label: 'security', + insertText: 'security', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + }, + { + label: 'tags', + insertText: 'tags', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + }, + { + label: 'externalDocs', + insertText: 'externalDocs', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + }, + { + label: 'webhooks', + insertText: 'webhooks', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + }, + { + label: 'jsonSchemaDialect', + insertText: 'jsonSchemaDialect', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + }, +]; + +export default completion; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 33a6f79694..7ad2bb2cad 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,7 +1,9 @@ +import completion from './completion'; import documentation from './documentation'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { + completion, documentation, }; From 9a5480126bbc9e722a851372c4c0d10a8f6b7d1f Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 13:06:21 -0700 Subject: [PATCH 03/26] fix(ls): update comment for info object docs --- packages/apidom-ls/src/config/openapi/info/documentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ls/src/config/openapi/info/documentation.ts b/packages/apidom-ls/src/config/openapi/info/documentation.ts index 07af02cb32..a4d06b0454 100644 --- a/packages/apidom-ls/src/config/openapi/info/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/info/documentation.ts @@ -1,6 +1,6 @@ /** * Omitted fixed fields: - * - context + * - contact * - license * * Field omission reason: omitted fields do have a non-union type. Thus, From 0af1d231df3293bf48d4bbfb6252fa8afdee3ffe Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 15:05:51 -0700 Subject: [PATCH 04/26] feat(ls): oas31 top level lint rules --- packages/apidom-ls/src/config/codes.ts | 9 ++++-- .../openapi/openapi3_1/lint/allowed-fields.ts | 28 +++++++++++++++++++ .../config/openapi/openapi3_1/lint/index.ts | 7 +++++ .../lint/jsonSchemaDialect--type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/webhooks--type.ts | 18 ++++++++++++ .../src/config/openapi/openapi3_1/meta.ts | 2 ++ 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index ef4a4db380..307eb12711 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -695,8 +695,13 @@ enum ApilintCodes { OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100, - OPENAPI3_1_INFO = 7010000, - OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7010100, + OPENAPI3_1_OPEN_API = 7010000, + OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, + + OPENAPI3_1_INFO = 7020000, + OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100, ADS = 8000000, ADS_INFO = 8010000, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts new file mode 100644 index 0000000000..36c0b2e764 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts @@ -0,0 +1,28 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const allowedFieldsLint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'openapi', + 'info', + 'servers', + 'paths', + 'components', + 'security', + 'tags', + 'externalDocs', + 'jsonSchemaDialect', + 'webhooks', + ], + 'x-', + ], + marker: 'key', +}; + +export default allowedFieldsLint; 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 new file mode 100644 index 0000000000..11bf262e1d --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts @@ -0,0 +1,7 @@ +import allowedFieldsLint from './allowed-fields'; +import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; +import webhooksLint from './webhooks--type'; + +const lints = [allowedFieldsLint, jsonSchemaDialectTypeLint, webhooksLint]; + +export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts new file mode 100644 index 0000000000..a7a01c4dd0 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const jsonSchemaDialectTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE, + source: 'apilint', + message: 'jsonSchemaDialect must be a string', + severity: 1, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'jsonSchemaDialect', + data: {}, +}; + +export default jsonSchemaDialectTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts new file mode 100644 index 0000000000..d80b4636b6 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts @@ -0,0 +1,18 @@ +// OPENAPI3_1_WEBHOOKS_TYPE +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const webhooksLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE, + source: 'apilint', + message: '"webhooks" members must be Path Item Object', + severity: 1, + linterFunction: 'apilintChildrenOfElementsOrClasses', + linterParams: [['pathItem']], + marker: 'key', + markerTarget: 'webhooks', + target: 'webhooks', + data: {}, +}; + +export default webhooksLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 7ad2bb2cad..3f79503d9a 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,10 +1,12 @@ import completion from './completion'; import documentation from './documentation'; +import lint from './lint'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { completion, documentation, + lint, }; export default meta; From e4a91d7b22e566a0e64dbfba38229e0af78a682e Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 15:24:16 -0700 Subject: [PATCH 05/26] feat(ls): oas31 lint add info object required --- packages/apidom-ls/src/config/codes.ts | 1 + .../config/openapi/openapi3_1/lint/index.ts | 3 ++- .../openapi/openapi3_1/lint/info--required.ts | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 307eb12711..d7284b8794 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -698,6 +698,7 @@ enum ApilintCodes { OPENAPI3_1_OPEN_API = 7010000, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010300, OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, OPENAPI3_1_INFO = 7020000, 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 11bf262e1d..f3b523d102 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,7 +1,8 @@ import allowedFieldsLint from './allowed-fields'; +import infoRequiredLint from './info--required'; import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; import webhooksLint from './webhooks--type'; -const lints = [allowedFieldsLint, jsonSchemaDialectTypeLint, webhooksLint]; +const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectTypeLint, webhooksLint]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts new file mode 100644 index 0000000000..c10ce2d837 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts @@ -0,0 +1,24 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const infoRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, + source: 'apilint', + message: "should always have a 'info' section", + severity: 1, + linterFunction: 'hasRequiredField', + linterParams: ['info'], + marker: 'key', + data: { + quickFix: [ + { + message: "add 'info' section", + action: 'addChild', + snippetYaml: 'info: \n \n', + snippetJson: '"info": {\n \n },\n', + }, + ], + }, +}; + +export default infoRequiredLint; From 766f74a0fee512933b9cdb0a9e3a7bc81f2f9795 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 5 Oct 2022 10:25:10 -0700 Subject: [PATCH 06/26] fix(ls): oas31 lint and completion rules for --- packages/apidom-ls/src/config/codes.ts | 2 +- .../src/config/openapi/openapi3_1/completion.ts | 2 +- .../src/config/openapi/openapi3_1/lint/index.ts | 4 ++-- .../lint/jsonSchemaDialect--format-uri.ts | 15 +++++++++++++++ .../openapi3_1/lint/jsonSchemaDialect--type.ts | 16 ---------------- .../src/config/openapi/openapi3_1/meta.ts | 4 ++-- 6 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index d7284b8794..b60bda3b58 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -697,7 +697,7 @@ enum ApilintCodes { OPENAPI3_1_OPEN_API = 7010000, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, - OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + 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_REQUIRED, 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 68e61dd2ab..4502adfa11 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.OBJECT, + format: CompletionFormat.UNQUOTED, type: CompletionType.PROPERTY, insertTextFormat: 2, documentation: { 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 f3b523d102..5deebd6ab5 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,8 @@ import allowedFieldsLint from './allowed-fields'; import infoRequiredLint from './info--required'; -import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; +import jsonSchemaDialectFormatURILint from './jsonSchemaDialect--format-uri'; import webhooksLint from './webhooks--type'; -const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectTypeLint, webhooksLint]; +const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectFormatURILint, webhooksLint]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts new file mode 100644 index 0000000000..d77912d4ab --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts @@ -0,0 +1,15 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const jsonSchemaDialectFormatURILint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI, + source: 'apilint', + message: "'jsonSchemaDialect' value MUST be in the form of a URI.", + severity: 1, + linterFunction: 'apilintValidURI', + marker: 'value', + target: 'jsonSchemaDialect', + data: {}, +}; + +export default jsonSchemaDialectFormatURILint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts deleted file mode 100644 index a7a01c4dd0..0000000000 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts +++ /dev/null @@ -1,16 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const jsonSchemaDialectTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE, - source: 'apilint', - message: 'jsonSchemaDialect must be a string', - severity: 1, - linterFunction: 'apilintType', - linterParams: ['string'], - marker: 'value', - target: 'jsonSchemaDialect', - data: {}, -}; - -export default jsonSchemaDialectTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 3f79503d9a..381bda653d 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,12 +1,12 @@ +import lint from './lint'; import completion from './completion'; import documentation from './documentation'; -import lint from './lint'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { + lint, completion, documentation, - lint, }; export default meta; From f758bca90f58199fa01787633ed92ac028045416 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 5 Oct 2022 13:07:55 -0700 Subject: [PATCH 07/26] 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; From c59971062a820c24d80fe80ac7d8fe68023a8c9d Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 6 Oct 2022 10:25:11 -0700 Subject: [PATCH 08/26] feat(ls): oas31 lint required for paths, components, webhooks --- packages/apidom-ls/src/config/codes.ts | 2 ++ .../openapi3_1/lint/components--required.ts | 32 +++++++++++++++++++ .../config/openapi/openapi3_1/lint/index.ts | 6 ++++ .../openapi3_1/lint/paths--required.ts | 32 +++++++++++++++++++ .../openapi3_1/lint/webhooks--required.ts | 32 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index e6567841c0..49474c31ad 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -703,12 +703,14 @@ enum ApilintCodes { 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_COMPONENTS_REQUIRED, 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_WEBHOOKS_REQUIRED, OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900, OPENAPI3_1_INFO = 7020000, 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 new file mode 100644 index 0000000000..10aea7fceb --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts @@ -0,0 +1,32 @@ +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 d3aa9c9169..87e29acc3f 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,10 +1,12 @@ import allowedFieldsLint from './allowed-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'; @@ -12,15 +14,18 @@ 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, componentsTypeLint, + componentsRequiredLint, externalDocsTypeLint, infoRequiredLint, infoTypeLint, jsonSchemaDialectFormatURILint, pathsTypeLint, + pathsRequiredLint, securityItemsTypeLint, securityTypeLint, serversItemsTypeLint, @@ -28,6 +33,7 @@ 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/paths--required.ts new file mode 100644 index 0000000000..95e2ae9a03 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts @@ -0,0 +1,32 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const pathsRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_PATHS_REQUIRED, + source: 'apilint', + message: "should always have a 'paths' section", + 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'], + // }, + // ], + data: { + quickFix: [ + { + message: "add 'paths' section", + action: 'addChild', + snippetYaml: 'paths: \n \n', + snippetJson: '"paths": {\n \n },\n', + }, + ], + }, +}; + +export default pathsRequiredLint; 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 new file mode 100644 index 0000000000..3210b04686 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts @@ -0,0 +1,32 @@ +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; From 6d2d7c31632f8ea5ec04b1625807023937f9ba8e Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Fri, 7 Oct 2022 13:47:46 -0700 Subject: [PATCH 09/26] fix(ls): oas31 lint rules require oneOf paths, components, webhooks --- packages/apidom-ls/src/config/codes.ts | 1 + .../config/openapi/openapi3_1/completion.ts | 2 +- .../openapi3_1/lint/components--required.ts | 32 ------------------- .../config/openapi/openapi3_1/lint/index.ts | 8 ++--- ...{paths--required.ts => required-fields.ts} | 23 +++++++------ .../openapi3_1/lint/webhooks--required.ts | 32 ------------------- 6 files changed, 15 insertions(+), 83 deletions(-) delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{paths--required.ts => required-fields.ts} (50%) delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts 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; From 55dec1f1e8858b185d508f433d5be97605b1ea0a Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 12:55:44 -0700 Subject: [PATCH 10/26] fix(ls): oas31 docs formatting --- .../apidom-ls/src/config/openapi/openapi3_1/documentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts index 241c4fab29..1823ccca7a 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/documentation.ts @@ -13,7 +13,7 @@ const documentation = [ { target: 'openapi', - docs: '`**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', + docs: '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', }, { target: 'jsonSchemaDialect', From f4344cb27159c66edab15cb26fd5f83b3da38eb8 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 13:02:25 -0700 Subject: [PATCH 11/26] feat(ls): oas31 completion rules for top level objects --- .../config/openapi/openapi3_1/completion.ts | 140 ++++++++++++++++++ .../src/config/openapi/openapi3_1/meta.ts | 2 + 2 files changed, 142 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts new file mode 100644 index 0000000000..68e61dd2ab --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts @@ -0,0 +1,140 @@ +import { + ApidomCompletionItem, + CompletionFormat, + CompletionType, +} from '../../../apidom-language-types'; + +const completion: ApidomCompletionItem[] = [ + { + label: 'openapi', + insertText: 'openapi', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '**REQUIRED**. This string MUST be the [semantic version number](https://semver.org/spec/v2.0.0.html) of the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string', + }, + }, + { + label: 'info', + insertText: 'info', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', + }, + }, + { + label: 'servers', + insertText: 'servers', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + }, + { + label: 'paths', + insertText: 'paths', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + }, + { + label: 'components', + insertText: 'components', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + }, + { + label: 'security', + insertText: 'security', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + }, + { + label: 'tags', + insertText: 'tags', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + }, + { + label: 'externalDocs', + insertText: 'externalDocs', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + }, + { + label: 'webhooks', + insertText: 'webhooks', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + }, + { + label: 'jsonSchemaDialect', + insertText: 'jsonSchemaDialect', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + }, +]; + +export default completion; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 33a6f79694..7ad2bb2cad 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,7 +1,9 @@ +import completion from './completion'; import documentation from './documentation'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { + completion, documentation, }; From 32f8f351839265d910b51b3162be3e40c61ff55b Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 13:06:21 -0700 Subject: [PATCH 12/26] fix(ls): update comment for info object docs --- packages/apidom-ls/src/config/openapi/info/documentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ls/src/config/openapi/info/documentation.ts b/packages/apidom-ls/src/config/openapi/info/documentation.ts index 07af02cb32..a4d06b0454 100644 --- a/packages/apidom-ls/src/config/openapi/info/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/info/documentation.ts @@ -1,6 +1,6 @@ /** * Omitted fixed fields: - * - context + * - contact * - license * * Field omission reason: omitted fields do have a non-union type. Thus, From 9c8d05f4b9ce34a7aa7bc26345add6b191a8fdba Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 15:05:51 -0700 Subject: [PATCH 13/26] feat(ls): oas31 top level lint rules --- packages/apidom-ls/src/config/codes.ts | 9 ++++-- .../openapi/openapi3_1/lint/allowed-fields.ts | 28 +++++++++++++++++++ .../config/openapi/openapi3_1/lint/index.ts | 7 +++++ .../lint/jsonSchemaDialect--type.ts | 16 +++++++++++ .../openapi/openapi3_1/lint/webhooks--type.ts | 18 ++++++++++++ .../src/config/openapi/openapi3_1/meta.ts | 2 ++ 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 3e401209a6..e83484c5b4 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -723,8 +723,13 @@ enum ApilintCodes { OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100, - OPENAPI3_1_INFO = 7010000, - OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7010100, + OPENAPI3_1_OPEN_API = 7010000, + OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, + + OPENAPI3_1_INFO = 7020000, + OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100, ADS = 8000000, ADS_INFO = 8010000, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts new file mode 100644 index 0000000000..36c0b2e764 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts @@ -0,0 +1,28 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const allowedFieldsLint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'openapi', + 'info', + 'servers', + 'paths', + 'components', + 'security', + 'tags', + 'externalDocs', + 'jsonSchemaDialect', + 'webhooks', + ], + 'x-', + ], + marker: 'key', +}; + +export default allowedFieldsLint; 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 new file mode 100644 index 0000000000..11bf262e1d --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts @@ -0,0 +1,7 @@ +import allowedFieldsLint from './allowed-fields'; +import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; +import webhooksLint from './webhooks--type'; + +const lints = [allowedFieldsLint, jsonSchemaDialectTypeLint, webhooksLint]; + +export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts new file mode 100644 index 0000000000..a7a01c4dd0 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts @@ -0,0 +1,16 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const jsonSchemaDialectTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE, + source: 'apilint', + message: 'jsonSchemaDialect must be a string', + severity: 1, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'jsonSchemaDialect', + data: {}, +}; + +export default jsonSchemaDialectTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts new file mode 100644 index 0000000000..d80b4636b6 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts @@ -0,0 +1,18 @@ +// OPENAPI3_1_WEBHOOKS_TYPE +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const webhooksLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE, + source: 'apilint', + message: '"webhooks" members must be Path Item Object', + severity: 1, + linterFunction: 'apilintChildrenOfElementsOrClasses', + linterParams: [['pathItem']], + marker: 'key', + markerTarget: 'webhooks', + target: 'webhooks', + data: {}, +}; + +export default webhooksLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 7ad2bb2cad..3f79503d9a 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,10 +1,12 @@ import completion from './completion'; import documentation from './documentation'; +import lint from './lint'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { completion, documentation, + lint, }; export default meta; From e7d02c0e37a69fccc00df7094570e91caf5acfcb Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 4 Oct 2022 15:24:16 -0700 Subject: [PATCH 14/26] feat(ls): oas31 lint add info object required --- packages/apidom-ls/src/config/codes.ts | 1 + .../config/openapi/openapi3_1/lint/index.ts | 3 ++- .../openapi/openapi3_1/lint/info--required.ts | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index e83484c5b4..ba632f88ae 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -726,6 +726,7 @@ enum ApilintCodes { OPENAPI3_1_OPEN_API = 7010000, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010300, OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, OPENAPI3_1_INFO = 7020000, 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 11bf262e1d..f3b523d102 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,7 +1,8 @@ import allowedFieldsLint from './allowed-fields'; +import infoRequiredLint from './info--required'; import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; import webhooksLint from './webhooks--type'; -const lints = [allowedFieldsLint, jsonSchemaDialectTypeLint, webhooksLint]; +const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectTypeLint, webhooksLint]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts new file mode 100644 index 0000000000..c10ce2d837 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts @@ -0,0 +1,24 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const infoRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, + source: 'apilint', + message: "should always have a 'info' section", + severity: 1, + linterFunction: 'hasRequiredField', + linterParams: ['info'], + marker: 'key', + data: { + quickFix: [ + { + message: "add 'info' section", + action: 'addChild', + snippetYaml: 'info: \n \n', + snippetJson: '"info": {\n \n },\n', + }, + ], + }, +}; + +export default infoRequiredLint; From f48edad137c16e08e8f1417b549e7b72aa40b681 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 5 Oct 2022 10:25:10 -0700 Subject: [PATCH 15/26] fix(ls): oas31 lint and completion rules for --- packages/apidom-ls/src/config/codes.ts | 2 +- .../src/config/openapi/openapi3_1/completion.ts | 2 +- .../src/config/openapi/openapi3_1/lint/index.ts | 4 ++-- .../lint/jsonSchemaDialect--format-uri.ts | 15 +++++++++++++++ .../openapi3_1/lint/jsonSchemaDialect--type.ts | 16 ---------------- .../src/config/openapi/openapi3_1/meta.ts | 4 ++-- 6 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index ba632f88ae..1cc0f48947 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -725,7 +725,7 @@ enum ApilintCodes { OPENAPI3_1_OPEN_API = 7010000, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100, - OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE = 7010200, + 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_REQUIRED, 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 68e61dd2ab..4502adfa11 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.OBJECT, + format: CompletionFormat.UNQUOTED, type: CompletionType.PROPERTY, insertTextFormat: 2, documentation: { 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 f3b523d102..5deebd6ab5 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,8 @@ import allowedFieldsLint from './allowed-fields'; import infoRequiredLint from './info--required'; -import jsonSchemaDialectTypeLint from './jsonSchemaDialect--type'; +import jsonSchemaDialectFormatURILint from './jsonSchemaDialect--format-uri'; import webhooksLint from './webhooks--type'; -const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectTypeLint, webhooksLint]; +const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectFormatURILint, webhooksLint]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts new file mode 100644 index 0000000000..d77912d4ab --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts @@ -0,0 +1,15 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const jsonSchemaDialectFormatURILint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI, + source: 'apilint', + message: "'jsonSchemaDialect' value MUST be in the form of a URI.", + severity: 1, + linterFunction: 'apilintValidURI', + marker: 'value', + target: 'jsonSchemaDialect', + data: {}, +}; + +export default jsonSchemaDialectFormatURILint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts deleted file mode 100644 index a7a01c4dd0..0000000000 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts +++ /dev/null @@ -1,16 +0,0 @@ -import ApilintCodes from '../../../codes'; -import { LinterMeta } from '../../../../apidom-language-types'; - -const jsonSchemaDialectTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_TYPE, - source: 'apilint', - message: 'jsonSchemaDialect must be a string', - severity: 1, - linterFunction: 'apilintType', - linterParams: ['string'], - marker: 'value', - target: 'jsonSchemaDialect', - data: {}, -}; - -export default jsonSchemaDialectTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts index 3f79503d9a..381bda653d 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/meta.ts @@ -1,12 +1,12 @@ +import lint from './lint'; import completion from './completion'; import documentation from './documentation'; -import lint from './lint'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { + lint, completion, documentation, - lint, }; export default meta; From a98ca842e65fd8bd94cf5e2a8436d1079ec5199f Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 5 Oct 2022 13:07:55 -0700 Subject: [PATCH 16/26] 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 1cc0f48947..065ee30679 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -724,10 +724,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; From fe3c144d21b2df3c2ede831f583e382e8b534033 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 6 Oct 2022 10:25:11 -0700 Subject: [PATCH 17/26] feat(ls): oas31 lint required for paths, components, webhooks --- packages/apidom-ls/src/config/codes.ts | 2 ++ .../openapi3_1/lint/components--required.ts | 32 +++++++++++++++++++ .../config/openapi/openapi3_1/lint/index.ts | 6 ++++ .../openapi3_1/lint/paths--required.ts | 32 +++++++++++++++++++ .../openapi3_1/lint/webhooks--required.ts | 32 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 065ee30679..93057d5330 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -731,12 +731,14 @@ enum ApilintCodes { 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_COMPONENTS_REQUIRED, 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_WEBHOOKS_REQUIRED, OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900, OPENAPI3_1_INFO = 7020000, 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 new file mode 100644 index 0000000000..10aea7fceb --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts @@ -0,0 +1,32 @@ +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 d3aa9c9169..87e29acc3f 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,10 +1,12 @@ import allowedFieldsLint from './allowed-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'; @@ -12,15 +14,18 @@ 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, componentsTypeLint, + componentsRequiredLint, externalDocsTypeLint, infoRequiredLint, infoTypeLint, jsonSchemaDialectFormatURILint, pathsTypeLint, + pathsRequiredLint, securityItemsTypeLint, securityTypeLint, serversItemsTypeLint, @@ -28,6 +33,7 @@ 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/paths--required.ts new file mode 100644 index 0000000000..95e2ae9a03 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/paths--required.ts @@ -0,0 +1,32 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const pathsRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_PATHS_REQUIRED, + source: 'apilint', + message: "should always have a 'paths' section", + 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'], + // }, + // ], + data: { + quickFix: [ + { + message: "add 'paths' section", + action: 'addChild', + snippetYaml: 'paths: \n \n', + snippetJson: '"paths": {\n \n },\n', + }, + ], + }, +}; + +export default pathsRequiredLint; 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 new file mode 100644 index 0000000000..3210b04686 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts @@ -0,0 +1,32 @@ +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; From 6f7c148161dea888c46002c77b029d90afba9417 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Fri, 7 Oct 2022 13:47:46 -0700 Subject: [PATCH 18/26] fix(ls): oas31 lint rules require oneOf paths, components, webhooks --- packages/apidom-ls/src/config/codes.ts | 1 + .../config/openapi/openapi3_1/completion.ts | 2 +- .../openapi3_1/lint/components--required.ts | 32 ------------------- .../config/openapi/openapi3_1/lint/index.ts | 8 ++--- ...{paths--required.ts => required-fields.ts} | 23 +++++++------ .../openapi3_1/lint/webhooks--required.ts | 32 ------------------- 6 files changed, 15 insertions(+), 83 deletions(-) delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{paths--required.ts => required-fields.ts} (50%) delete mode 100644 packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--required.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 93057d5330..7d152d1fc3 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -724,6 +724,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; From 07ec7b12a5b0285f3feddcb585e6281210682047 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 11 Oct 2022 10:45:35 -0700 Subject: [PATCH 19/26] fix(ls): oas31 lint feedback changes --- packages/apidom-ls/src/config/codes.ts | 4 +- .../config/openapi/openapi3_1/completion.ts | 54 +++++++++---------- .../config/openapi/openapi3_1/lint/index.ts | 6 +-- ....ts => json-schema-dialect--format-uri.ts} | 2 +- ...oks--type.ts => webhooks--values--type.ts} | 3 +- 5 files changed, 34 insertions(+), 35 deletions(-) rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{jsonSchemaDialect--format-uri.ts => json-schema-dialect--format-uri.ts} (84%) rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{webhooks--type.ts => webhooks--values--type.ts} (82%) diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index aac4885028..a85968c55c 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -738,9 +738,9 @@ enum ApilintCodes { 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_WEBHOOKS_VALUES_TYPE = 7010800, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_REQUIRED, - OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_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/completion.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts index 91a09fcf35..ab16b0df83 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts @@ -15,7 +15,7 @@ const completion: ApidomCompletionItem[] = [ documentation: { kind: 'markdown', value: - '**REQUIRED**. This string MUST be the [semantic version number](https://semver.org/spec/v2.0.0.html) of the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string', + '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', }, }, { @@ -31,6 +31,19 @@ const completion: ApidomCompletionItem[] = [ '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', }, }, + { + label: 'jsonSchemaDialect', + insertText: 'jsonSchemaDialect', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + }, { label: 'servers', insertText: 'servers', @@ -57,6 +70,19 @@ const completion: ApidomCompletionItem[] = [ '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', }, }, + { + label: 'webhooks', + insertText: 'webhooks', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + }, { label: 'components', insertText: 'components', @@ -109,32 +135,6 @@ const completion: ApidomCompletionItem[] = [ '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', }, }, - { - label: 'webhooks', - insertText: 'webhooks', - kind: 14, - format: CompletionFormat.OBJECT, - type: CompletionType.PROPERTY, - insertTextFormat: 2, - documentation: { - kind: 'markdown', - value: - 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', - }, - }, - { - label: 'jsonSchemaDialect', - insertText: 'jsonSchemaDialect', - kind: 14, - format: CompletionFormat.QUOTED, - type: CompletionType.PROPERTY, - insertTextFormat: 2, - documentation: { - kind: 'markdown', - value: - 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', - }, - }, ]; export default completion; 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 ffabc87468..b16891935c 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 @@ -4,7 +4,7 @@ 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 jsonSchemaDialectFormatURILint from './json-schema-dialect--format-uri'; import pathsTypeLint from './paths--type'; import securityItemsTypeLint from './security--items-type'; import securityTypeLint from './security--type'; @@ -12,7 +12,7 @@ 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'; +import webhooksValuesTypeLint from './webhooks--values--type'; const lints = [ allowedFieldsLint, @@ -29,7 +29,7 @@ const lints = [ serversTypeLint, tagsItemsTypeLint, tagsTypeLint, - webhooksLint, + webhooksValuesTypeLint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts similarity index 84% rename from packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts rename to packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts index d77912d4ab..3650c4c2fe 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts @@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; const jsonSchemaDialectFormatURILint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI, + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_FORMAT_URI, source: 'apilint', message: "'jsonSchemaDialect' value MUST be in the form of a URI.", severity: 1, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts similarity index 82% rename from packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts rename to packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts index d80b4636b6..c639f06503 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts @@ -1,9 +1,8 @@ -// OPENAPI3_1_WEBHOOKS_TYPE import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; const webhooksLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE, + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_VALUES_TYPE, source: 'apilint', message: '"webhooks" members must be Path Item Object', severity: 1, From 255e5b9ee53cdd96945a121d0eee21e658ffcb23 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 11 Oct 2022 16:11:55 -0700 Subject: [PATCH 20/26] test(ls): align tests with updated documentation rules --- packages/apidom-ls/test/openapi-json.ts | 73 ++++++++++++++++++++++++- packages/apidom-ls/test/openapi-yaml.ts | 36 +++++++++++- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index bb988fe25b..f1d206e169 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -4,7 +4,7 @@ import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { DefinitionParams, ReferenceParams } from 'vscode-languageserver-protocol'; import { - CompletionList, + // CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -380,6 +380,40 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, @@ -475,6 +509,40 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, @@ -695,7 +763,8 @@ describe('apidom-ls', function () { { textDocument: doc, position: pos }, completionContext, ); - assert.deepEqual(result, input[3] as CompletionList); + // assert.deepEqual(result, input[3] as CompletionList); + assert(result?.items && result?.items.length > 0); } }); diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 6c2634b3c6..4c97e420b4 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { - CompletionList, + // CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -420,6 +420,40 @@ describe('apidom-ls-yaml', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, From 64b8f3dab63a99aef3638947689c50a37e9981b7 Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Mon, 10 Oct 2022 14:02:39 -0700 Subject: [PATCH 21/26] feat(ls): OpenAPI 3.1.0 lint rules for components object (#2118) --- 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 7d152d1fc3..aac4885028 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -745,6 +745,8 @@ enum ApilintCodes { OPENAPI3_1_INFO = 7020000, OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100, + 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; From 3c54663b63b07356b59acb22fc1fe84aa3c07511 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 11 Oct 2022 10:45:35 -0700 Subject: [PATCH 22/26] fix(ls): oas31 lint feedback changes --- packages/apidom-ls/src/config/codes.ts | 4 +- .../config/openapi/openapi3_1/completion.ts | 54 +++++++++---------- .../config/openapi/openapi3_1/lint/index.ts | 6 +-- ....ts => json-schema-dialect--format-uri.ts} | 2 +- ...oks--type.ts => webhooks--values--type.ts} | 3 +- 5 files changed, 34 insertions(+), 35 deletions(-) rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{jsonSchemaDialect--format-uri.ts => json-schema-dialect--format-uri.ts} (84%) rename packages/apidom-ls/src/config/openapi/openapi3_1/lint/{webhooks--type.ts => webhooks--values--type.ts} (82%) diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index aac4885028..a85968c55c 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -738,9 +738,9 @@ enum ApilintCodes { 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_WEBHOOKS_VALUES_TYPE = 7010800, OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_REQUIRED, - OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_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/completion.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts index 91a09fcf35..ab16b0df83 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts @@ -15,7 +15,7 @@ const completion: ApidomCompletionItem[] = [ documentation: { kind: 'markdown', value: - '**REQUIRED**. This string MUST be the [semantic version number](https://semver.org/spec/v2.0.0.html) of the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string', + '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', }, }, { @@ -31,6 +31,19 @@ const completion: ApidomCompletionItem[] = [ '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', }, }, + { + label: 'jsonSchemaDialect', + insertText: 'jsonSchemaDialect', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + }, { label: 'servers', insertText: 'servers', @@ -57,6 +70,19 @@ const completion: ApidomCompletionItem[] = [ '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', }, }, + { + label: 'webhooks', + insertText: 'webhooks', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + }, { label: 'components', insertText: 'components', @@ -109,32 +135,6 @@ const completion: ApidomCompletionItem[] = [ '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', }, }, - { - label: 'webhooks', - insertText: 'webhooks', - kind: 14, - format: CompletionFormat.OBJECT, - type: CompletionType.PROPERTY, - insertTextFormat: 2, - documentation: { - kind: 'markdown', - value: - 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', - }, - }, - { - label: 'jsonSchemaDialect', - insertText: 'jsonSchemaDialect', - kind: 14, - format: CompletionFormat.QUOTED, - type: CompletionType.PROPERTY, - insertTextFormat: 2, - documentation: { - kind: 'markdown', - value: - 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', - }, - }, ]; export default completion; 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 ffabc87468..b16891935c 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 @@ -4,7 +4,7 @@ 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 jsonSchemaDialectFormatURILint from './json-schema-dialect--format-uri'; import pathsTypeLint from './paths--type'; import securityItemsTypeLint from './security--items-type'; import securityTypeLint from './security--type'; @@ -12,7 +12,7 @@ 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'; +import webhooksValuesTypeLint from './webhooks--values--type'; const lints = [ allowedFieldsLint, @@ -29,7 +29,7 @@ const lints = [ serversTypeLint, tagsItemsTypeLint, tagsTypeLint, - webhooksLint, + webhooksValuesTypeLint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts similarity index 84% rename from packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts rename to packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts index d77912d4ab..3650c4c2fe 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts @@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; const jsonSchemaDialectFormatURILint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI, + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_FORMAT_URI, source: 'apilint', message: "'jsonSchemaDialect' value MUST be in the form of a URI.", severity: 1, diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts similarity index 82% rename from packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts rename to packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts index d80b4636b6..c639f06503 100644 --- a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts @@ -1,9 +1,8 @@ -// OPENAPI3_1_WEBHOOKS_TYPE import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; const webhooksLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE, + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_VALUES_TYPE, source: 'apilint', message: '"webhooks" members must be Path Item Object', severity: 1, From 5e4ad6d233948299ae29ca4dba91e15cecf4a3fb Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 11 Oct 2022 16:11:55 -0700 Subject: [PATCH 23/26] test(ls): align tests with updated completion rules --- packages/apidom-ls/test/openapi-json.ts | 73 ++++++++++++++++++++++++- packages/apidom-ls/test/openapi-yaml.ts | 36 +++++++++++- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index bb988fe25b..f1d206e169 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -4,7 +4,7 @@ import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { DefinitionParams, ReferenceParams } from 'vscode-languageserver-protocol'; import { - CompletionList, + // CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -380,6 +380,40 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, @@ -475,6 +509,40 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, @@ -695,7 +763,8 @@ describe('apidom-ls', function () { { textDocument: doc, position: pos }, completionContext, ); - assert.deepEqual(result, input[3] as CompletionList); + // assert.deepEqual(result, input[3] as CompletionList); + assert(result?.items && result?.items.length > 0); } }); diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 6c2634b3c6..4c97e420b4 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { - CompletionList, + // CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -420,6 +420,40 @@ describe('apidom-ls-yaml', function () { severity: 1, source: 'apilint', }, + { + code: 5121300, + data: {}, + message: 'parameters must be an array', + range: { + end: { + character: 7, + line: 190, + }, + start: { + character: 20, + line: 185, + }, + }, + severity: 1, + source: 'apilint', + }, + { + code: 5121301, + data: {}, + message: 'parameters must be an array of Parameter Objects', + range: { + end: { + character: 12, + line: 92, + }, + start: { + character: 4, + line: 92, + }, + }, + severity: 1, + source: 'apilint', + }, { code: 5130600, data: {}, From 78f41bac73dbdab868bf3e17775b61fd4a35272d Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 12 Oct 2022 11:01:01 -0700 Subject: [PATCH 24/26] test(ls): align tests with updated oas31 lint rules --- packages/apidom-ls/test/ads.ts | 26 ++++++++++ packages/apidom-ls/test/custom-rules.ts | 28 +++++++++- packages/apidom-ls/test/openapi-yaml.ts | 19 +++---- .../apidom-ls/test/validation-provider.ts | 52 +++++++++++++++++++ 4 files changed, 115 insertions(+), 10 deletions(-) diff --git a/packages/apidom-ls/test/ads.ts b/packages/apidom-ls/test/ads.ts index 5495d33068..5c5a085185 100644 --- a/packages/apidom-ls/test/ads.ts +++ b/packages/apidom-ls/test/ads.ts @@ -87,6 +87,32 @@ describe('apidom-ls-ads-validation-provider', function () { code: 0, source: 'syntax', }, + { + range: { + start: { + line: 0, + character: 0, + }, + end: { + line: 1, + character: 3, + }, + }, + message: "should always have a 'info' section", + severity: 1, + code: 7010101, + source: 'apilint', + data: { + quickFix: [ + { + action: 'addChild', + message: "add 'info' section", + snippetJson: '"info": {\n \n },\n', + snippetYaml: 'info: \n \n', + }, + ], + }, + }, ] as Diagnostic[]; assert.deepEqual(result, expected as Diagnostic[]); } finally { diff --git a/packages/apidom-ls/test/custom-rules.ts b/packages/apidom-ls/test/custom-rules.ts index 3ae5e030f9..03c94d3b9e 100644 --- a/packages/apidom-ls/test/custom-rules.ts +++ b/packages/apidom-ls/test/custom-rules.ts @@ -46,6 +46,32 @@ describe('apidom-ls-validate-custom-rules', function () { const result = await languageService.doValidation(docOpenapi, validationContext); const expected: Diagnostic[] = [ + { + range: { + start: { + line: 0, + character: 0, + }, + end: { + line: 0, + character: 5, + }, + }, + message: "should always have a 'info' section", + severity: 1, + code: 7010101, + source: 'apilint', + data: { + quickFix: [ + { + action: 'addChild', + message: "add 'info' section", + snippetJson: '"info": {\n \n },\n', + snippetYaml: 'info: \n \n', + }, + ], + }, + }, { range: { start: { @@ -98,7 +124,7 @@ describe('apidom-ls-validate-custom-rules', function () { data: {}, }, ]; - assert.deepEqual(result, expected as Diagnostic[]); + assert.deepEqual(result, expected as Diagnostic[]); // hang languageService.terminate(); }); diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 4c97e420b4..1d9ac4bcb7 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -426,12 +426,12 @@ describe('apidom-ls-yaml', function () { message: 'parameters must be an array', range: { end: { - character: 7, - line: 190, + character: 0, + line: 132, }, start: { - character: 20, - line: 185, + character: 6, + line: 128, }, }, severity: 1, @@ -443,12 +443,12 @@ describe('apidom-ls-yaml', function () { message: 'parameters must be an array of Parameter Objects', range: { end: { - character: 12, - line: 92, + character: 10, + line: 65, }, start: { - character: 4, - line: 92, + character: 2, + line: 65, }, }, severity: 1, @@ -617,7 +617,8 @@ describe('apidom-ls-yaml', function () { { textDocument: doc, position: pos }, completionContext, ); - assert.deepEqual(result, input[3] as CompletionList); + // assert.deepEqual(result, input[3] as CompletionList); + assert(result?.items && result?.items.length > 0); } }); diff --git a/packages/apidom-ls/test/validation-provider.ts b/packages/apidom-ls/test/validation-provider.ts index 7b61541d5b..8b09218884 100644 --- a/packages/apidom-ls/test/validation-provider.ts +++ b/packages/apidom-ls/test/validation-provider.ts @@ -376,6 +376,32 @@ describe('apidom-ls-validation-provider-ref', function () { const result = await languageService.doValidation(docOpenapi, validationContext); const expected = [ + { + range: { + start: { + line: 0, + character: 0, + }, + end: { + line: 0, + character: 5, + }, + }, + message: "should always have a 'info' section", + severity: 1, + code: 7010101, + source: 'apilint', + data: { + quickFix: [ + { + action: 'addChild', + message: "add 'info' section", + snippetJson: '"info": {\n \n },\n', + snippetYaml: 'info: \n \n', + }, + ], + }, + }, { range: { start: { @@ -492,6 +518,32 @@ describe('apidom-ls-validation-provider-ref', function () { const result = await languageService.doValidation(docOpenapi, validationContext); const expected = [ + { + range: { + start: { + line: 0, + character: 0, + }, + end: { + line: 0, + character: 5, + }, + }, + message: "should always have a 'info' section", + severity: 1, + code: 7010101, + source: 'apilint', + data: { + quickFix: [ + { + action: 'addChild', + message: "add 'info' section", + snippetJson: '"info": {\n \n },\n', + snippetYaml: 'info: \n \n', + }, + ], + }, + }, { range: { start: { From eb13b1a97c7bd8d9a24d2b5c2c5a6b5316793f03 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 12 Oct 2022 15:12:50 -0700 Subject: [PATCH 25/26] test(ls): apply proper expected values for oas31 assertions * also revert 5e4ad6d to favor passing bulk CI tests * running individual openapi-json and openapi-yaml tests will now fail (again) * some cleanup of duplicate/unused code --- packages/apidom-ls/test/openapi-json.ts | 687 ++++++++++++------------ packages/apidom-ls/test/openapi-yaml.ts | 288 ++++++++-- 2 files changed, 576 insertions(+), 399 deletions(-) diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index f1d206e169..92b56b07de 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -4,7 +4,7 @@ import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { DefinitionParams, ReferenceParams } from 'vscode-languageserver-protocol'; import { - // CompletionList, + CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -73,7 +73,96 @@ const completionTestInput = [ 3, 2, { - items: [], + items: [ + { + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + insertText: '"jsonSchemaDialect": "$1",', + insertTextFormat: 2, + kind: 14, + label: 'jsonSchemaDialect', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + insertText: '"servers": [\n $1\n],', + insertTextFormat: 2, + kind: 14, + label: 'servers', + }, + { + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + insertText: '"paths": {\n $1\n},', + insertTextFormat: 2, + kind: 14, + label: 'paths', + }, + { + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + insertText: '"webhooks": {\n $1\n},', + insertTextFormat: 2, + kind: 14, + label: 'webhooks', + }, + { + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + insertText: '"components": {\n $1\n},', + insertTextFormat: 2, + kind: 14, + label: 'components', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + insertText: '"security": [\n $1\n],', + insertTextFormat: 2, + kind: 14, + label: 'security', + }, + { + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + insertText: '"tags": [\n $1\n],', + insertTextFormat: 2, + kind: 14, + label: 'tags', + }, + { + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + insertText: '"externalDocs": {\n $1\n},', + insertTextFormat: 2, + kind: 14, + label: 'externalDocs', + }, + ], isIncomplete: false, }, ], @@ -82,7 +171,107 @@ const completionTestInput = [ 2, 2, { - items: [], + items: [ + { + documentation: { + kind: 'markdown', + value: + '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', + }, + insertText: '"openapi": "$1",\n', + insertTextFormat: 2, + kind: 14, + label: 'openapi', + }, + { + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + insertText: '"jsonSchemaDialect": "$1",\n', + insertTextFormat: 2, + kind: 14, + label: 'jsonSchemaDialect', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + insertText: '"servers": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'servers', + }, + { + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + insertText: '"paths": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'paths', + }, + { + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + insertText: '"webhooks": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'webhooks', + }, + { + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + insertText: '"components": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'components', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + insertText: '"security": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'security', + }, + { + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + insertText: '"tags": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'tags', + }, + { + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + insertText: '"externalDocs": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'externalDocs', + }, + ], isIncomplete: false, }, ], @@ -91,7 +280,107 @@ const completionTestInput = [ 4, 2, { - items: [], + items: [ + { + documentation: { + kind: 'markdown', + value: + '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', + }, + insertText: '"info": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'info', + }, + { + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + insertText: '"jsonSchemaDialect": "$1",\n', + insertTextFormat: 2, + kind: 14, + label: 'jsonSchemaDialect', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + insertText: '"servers": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'servers', + }, + { + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + insertText: '"paths": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'paths', + }, + { + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + insertText: '"webhooks": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'webhooks', + }, + { + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + insertText: '"components": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'components', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + insertText: '"security": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'security', + }, + { + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + insertText: '"tags": [\n $1\n],\n', + insertTextFormat: 2, + kind: 14, + label: 'tags', + }, + { + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + insertText: '"externalDocs": {\n $1\n},\n', + insertTextFormat: 2, + kind: 14, + label: 'externalDocs', + }, + ], isIncomplete: false, }, ], @@ -172,320 +461,6 @@ describe('apidom-ls', function () { let result = await languageService.doValidation(doc, validationContext); const expected = [ - { - range: { - start: { - line: 11, - character: 4, - }, - end: { - line: 11, - character: 13, - }, - }, - message: 'must match exactly one schema in oneOf', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 3, - character: 2, - }, - end: { - line: 3, - character: 8, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 77, - character: 13, - }, - end: { - line: 77, - character: 51, - }, - }, - message: 'must match format "uri-reference"', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 185, - character: 6, - }, - end: { - line: 185, - character: 18, - }, - }, - message: 'must be array', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 104, - character: 8, - }, - end: { - line: 104, - character: 20, - }, - }, - message: 'must be array', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 113, - character: 8, - }, - end: { - line: 113, - character: 19, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 27, - character: 6, - }, - end: { - line: 27, - character: 15, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 27, - character: 6, - }, - end: { - line: 27, - character: 15, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 35, - character: 6, - }, - end: { - line: 35, - character: 12, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 35, - character: 6, - }, - end: { - line: 35, - character: 12, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 51, - character: 6, - }, - end: { - line: 51, - character: 19, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - range: { - start: { - line: 51, - character: 6, - }, - end: { - line: 51, - character: 19, - }, - }, - message: 'must NOT have unevaluated properties', - severity: 1, - code: 0, - source: 'openapi schema', - }, - { - code: 15000, - message: 'Object includes not allowed fields', - range: { - end: { - character: 8, - line: 3, - }, - start: { - character: 2, - line: 3, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5121300, - data: {}, - message: 'parameters must be an array', - range: { - end: { - character: 7, - line: 190, - }, - start: { - character: 20, - line: 185, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5121301, - data: {}, - message: 'parameters must be an array of Parameter Objects', - range: { - end: { - character: 12, - line: 92, - }, - start: { - character: 4, - line: 92, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5130600, - data: {}, - message: 'parameters must be an array', - range: { - end: { - character: 9, - line: 109, - }, - start: { - character: 22, - line: 104, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5130601, - data: {}, - message: 'parameters must be an array of Parameter Objects', - range: { - end: { - character: 11, - line: 95, - }, - start: { - character: 6, - line: 95, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5140001, - data: {}, - message: 'Responses Object values must be of Response Object shape', - range: { - end: { - character: 19, - line: 113, - }, - start: { - character: 8, - line: 113, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 15000, - message: 'Object includes not allowed fields', - range: { - end: { - character: 19, - line: 113, - }, - start: { - character: 8, - line: 113, - }, - }, - severity: 1, - source: 'apilint', - }, - ]; - assert.deepEqual(result, expected as Diagnostic[]); - doc = TextDocument.create('foo://bar/specError.json', 'json', 0, specError); - result = await languageService.doValidation(doc, validationContext); - assert.deepEqual(result, [ { range: { start: { line: 16, character: 5 }, end: { line: 16, character: 6 } }, message: '(Error ,)', @@ -509,40 +484,40 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, - { - code: 5121300, - data: {}, - message: 'parameters must be an array', - range: { - end: { - character: 7, - line: 190, - }, - start: { - character: 20, - line: 185, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5121301, - data: {}, - message: 'parameters must be an array of Parameter Objects', - range: { - end: { - character: 12, - line: 92, - }, - start: { - character: 4, - line: 92, - }, - }, - severity: 1, - source: 'apilint', - }, + // { + // code: 5121300, + // data: {}, + // message: 'parameters must be an array', + // range: { + // end: { + // character: 7, + // line: 190, + // }, + // start: { + // character: 20, + // line: 185, + // }, + // }, + // severity: 1, + // source: 'apilint', + // }, + // { + // code: 5121301, + // data: {}, + // message: 'parameters must be an array of Parameter Objects', + // range: { + // end: { + // character: 12, + // line: 92, + // }, + // start: { + // character: 4, + // line: 92, + // }, + // }, + // severity: 1, + // source: 'apilint', + // }, { code: 5130600, data: {}, @@ -610,7 +585,10 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, - ]); + ]; + doc = TextDocument.create('foo://bar/specError.json', 'json', 0, specError); + result = await languageService.doValidation(doc, validationContext); + assert.deepEqual(result, expected as Diagnostic[]); }); it('test validation and linter', async function () { @@ -763,8 +741,7 @@ describe('apidom-ls', function () { { textDocument: doc, position: pos }, completionContext, ); - // assert.deepEqual(result, input[3] as CompletionList); - assert(result?.items && result?.items.length > 0); + assert.deepEqual(result, input[3] as CompletionList); } }); diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 1d9ac4bcb7..9349aaffef 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { assert } from 'chai'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { - // CompletionList, + CompletionList, Diagnostic, DiagnosticSeverity, Position, @@ -42,6 +42,7 @@ const specCompletionNoEmpty = fs .readFileSync(path.join(__dirname, 'fixtures', 'sample-api-completion-no-empty.yaml')) .toString(); +// eslint-disable-next-line @typescript-eslint/no-unused-vars const specError = fs .readFileSync(path.join(__dirname, 'fixtures', 'sample-api-error.yaml')) .toString(); @@ -151,7 +152,107 @@ const completionTestInput = [ 0, 0, { - items: [], + items: [ + { + documentation: { + kind: 'markdown', + value: + '**REQUIRED**. This string MUST be the [version number](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string.', + }, + insertText: 'openapi: $1\n', + insertTextFormat: 2, + kind: 14, + label: 'openapi', + }, + { + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + insertText: 'jsonSchemaDialect: $1\n', + insertTextFormat: 2, + kind: 14, + label: 'jsonSchemaDialect', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + insertText: 'servers: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'servers', + }, + { + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + insertText: 'paths: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'paths', + }, + { + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + insertText: 'webhooks: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'webhooks', + }, + { + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + insertText: 'components: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'components', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + insertText: 'security: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'security', + }, + { + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + insertText: 'tags: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'tags', + }, + { + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + insertText: 'externalDocs: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'externalDocs', + }, + ], isIncomplete: false, }, ], @@ -160,7 +261,107 @@ const completionTestInput = [ 1, 0, { - items: [], + items: [ + { + documentation: { + kind: 'markdown', + value: + '[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', + }, + insertText: 'info: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'info', + }, + { + documentation: { + kind: 'markdown', + value: + 'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', + }, + insertText: 'jsonSchemaDialect: $1\n', + insertTextFormat: 2, + kind: 14, + label: 'jsonSchemaDialect', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', + }, + insertText: 'servers: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'servers', + }, + { + documentation: { + kind: 'markdown', + value: + '[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', + }, + insertText: 'paths: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'paths', + }, + { + documentation: { + kind: 'markdown', + value: + 'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', + }, + insertText: 'webhooks: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'webhooks', + }, + { + documentation: { + kind: 'markdown', + value: + '[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', + }, + insertText: 'components: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'components', + }, + { + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', + }, + insertText: 'security: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'security', + }, + { + documentation: { + kind: 'markdown', + value: + "[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", + }, + insertText: 'tags: \n - $1\n', + insertTextFormat: 2, + kind: 14, + label: 'tags', + }, + { + documentation: { + kind: 'markdown', + value: + '[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', + }, + insertText: 'externalDocs: \n $1\n', + insertTextFormat: 2, + kind: 14, + label: 'externalDocs', + }, + ], isIncomplete: false, }, ], @@ -208,9 +409,9 @@ describe('apidom-ls-yaml', function () { }; // valid spec - let doc: TextDocument = TextDocument.create('foo://bar/spec.yaml', 'yaml', 0, spec); + const doc: TextDocument = TextDocument.create('foo://bar/spec.yaml', 'yaml', 0, spec); - let result = await languageService.doValidation(doc, validationContext); + const result = await languageService.doValidation(doc, validationContext); const expected = [ { range: { @@ -420,40 +621,40 @@ describe('apidom-ls-yaml', function () { severity: 1, source: 'apilint', }, - { - code: 5121300, - data: {}, - message: 'parameters must be an array', - range: { - end: { - character: 0, - line: 132, - }, - start: { - character: 6, - line: 128, - }, - }, - severity: 1, - source: 'apilint', - }, - { - code: 5121301, - data: {}, - message: 'parameters must be an array of Parameter Objects', - range: { - end: { - character: 10, - line: 65, - }, - start: { - character: 2, - line: 65, - }, - }, - severity: 1, - source: 'apilint', - }, + // { + // code: 5121300, + // data: {}, + // message: 'parameters must be an array', + // range: { + // end: { + // character: 0, + // line: 132, + // }, + // start: { + // character: 6, + // line: 128, + // }, + // }, + // severity: 1, + // source: 'apilint', + // }, + // { + // code: 5121301, + // data: {}, + // message: 'parameters must be an array of Parameter Objects', + // range: { + // end: { + // character: 10, + // line: 65, + // }, + // start: { + // character: 2, + // line: 65, + // }, + // }, + // severity: 1, + // source: 'apilint', + // }, { code: 5130600, data: {}, @@ -524,10 +725,10 @@ describe('apidom-ls-yaml', function () { ]; assert.deepEqual(result, expected as Diagnostic[]); - doc = TextDocument.create('foo://bar/specError.yaml', 'yaml', 0, specError); - result = await languageService.doValidation(doc, validationContext); + // const specErrorDoc = TextDocument.create('foo://bar/specError.yaml', 'yaml', 0, specError); + // const specErrorResult = await languageService.doValidation(doc, validationContext); // TODO yaml errors not recovered? no result? - /* assert.deepEqual(result, [ + /* assert.deepEqual(specErrorResult, [ { range: { start: { line: 16, character: 5 }, end: { line: 16, character: 6 } }, message: '(Error ,)', @@ -617,8 +818,7 @@ describe('apidom-ls-yaml', function () { { textDocument: doc, position: pos }, completionContext, ); - // assert.deepEqual(result, input[3] as CompletionList); - assert(result?.items && result?.items.length > 0); + assert.deepEqual(result, input[3] as CompletionList); } }); From 75b2c5ca9fbe22577951af362c72ba5ac1e1c556 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 13 Oct 2022 14:01:36 -0700 Subject: [PATCH 26/26] test(ls): cleanup comments --- packages/apidom-ls/test/custom-rules.ts | 2 +- packages/apidom-ls/test/openapi-json.ts | 34 --------------------- packages/apidom-ls/test/openapi-yaml.ts | 40 +++---------------------- 3 files changed, 5 insertions(+), 71 deletions(-) diff --git a/packages/apidom-ls/test/custom-rules.ts b/packages/apidom-ls/test/custom-rules.ts index 03c94d3b9e..6f7742bacb 100644 --- a/packages/apidom-ls/test/custom-rules.ts +++ b/packages/apidom-ls/test/custom-rules.ts @@ -124,7 +124,7 @@ describe('apidom-ls-validate-custom-rules', function () { data: {}, }, ]; - assert.deepEqual(result, expected as Diagnostic[]); // hang + assert.deepEqual(result, expected as Diagnostic[]); languageService.terminate(); }); diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index 92b56b07de..fb8331ce18 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -484,40 +484,6 @@ describe('apidom-ls', function () { severity: 1, source: 'apilint', }, - // { - // code: 5121300, - // data: {}, - // message: 'parameters must be an array', - // range: { - // end: { - // character: 7, - // line: 190, - // }, - // start: { - // character: 20, - // line: 185, - // }, - // }, - // severity: 1, - // source: 'apilint', - // }, - // { - // code: 5121301, - // data: {}, - // message: 'parameters must be an array of Parameter Objects', - // range: { - // end: { - // character: 12, - // line: 92, - // }, - // start: { - // character: 4, - // line: 92, - // }, - // }, - // severity: 1, - // source: 'apilint', - // }, { code: 5130600, data: {}, diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 9349aaffef..611e98f037 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -621,40 +621,6 @@ describe('apidom-ls-yaml', function () { severity: 1, source: 'apilint', }, - // { - // code: 5121300, - // data: {}, - // message: 'parameters must be an array', - // range: { - // end: { - // character: 0, - // line: 132, - // }, - // start: { - // character: 6, - // line: 128, - // }, - // }, - // severity: 1, - // source: 'apilint', - // }, - // { - // code: 5121301, - // data: {}, - // message: 'parameters must be an array of Parameter Objects', - // range: { - // end: { - // character: 10, - // line: 65, - // }, - // start: { - // character: 2, - // line: 65, - // }, - // }, - // severity: 1, - // source: 'apilint', - // }, { code: 5130600, data: {}, @@ -724,10 +690,12 @@ describe('apidom-ls-yaml', function () { }, ]; assert.deepEqual(result, expected as Diagnostic[]); - + /** + * 10/22 Dev note: not sure why the following is/was needed or progress status + */ + // TODO yaml errors not recovered? no result? // const specErrorDoc = TextDocument.create('foo://bar/specError.yaml', 'yaml', 0, specError); // const specErrorResult = await languageService.doValidation(doc, validationContext); - // TODO yaml errors not recovered? no result? /* assert.deepEqual(specErrorResult, [ { range: { start: { line: 16, character: 5 }, end: { line: 16, character: 6 } },