diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 7f6d20a3a4..b5b17789e4 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -768,8 +768,27 @@ 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_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, + 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_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_VALUES_TYPE = 7010800, + OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_REQUIRED, + OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_DIALECT_FORMAT_URI = 7010900, + + OPENAPI3_1_INFO = 7020000, + OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100, OPENAPI3_1_COMPONENTS = 7020000, OPENAPI3_1_COMPONENTS_FIELD_PATH_ITEMS_VALUES_TYPE = 7020100, 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, 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..ab16b0df83 --- /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 [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.', + }, + }, + { + 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: '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', + 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: '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', + 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.', + }, + }, +]; + +export default completion; 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', 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/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 new file mode 100644 index 0000000000..b16891935c --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts @@ -0,0 +1,35 @@ +import allowedFieldsLint from './allowed-fields'; +import requiredFieldsLint from './required-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 './json-schema-dialect--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 webhooksValuesTypeLint from './webhooks--values--type'; + +const lints = [ + allowedFieldsLint, + requiredFieldsLint, + componentsTypeLint, + externalDocsTypeLint, + infoRequiredLint, + infoTypeLint, + jsonSchemaDialectFormatURILint, + pathsTypeLint, + securityItemsTypeLint, + securityTypeLint, + serversItemsTypeLint, + serversTypeLint, + tagsItemsTypeLint, + tagsTypeLint, + webhooksValuesTypeLint, +]; + +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; 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/json-schema-dialect--format-uri.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--format-uri.ts new file mode 100644 index 0000000000..3650c4c2fe --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/json-schema-dialect--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_DIALECT_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/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/required-fields.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/required-fields.ts new file mode 100644 index 0000000000..da7edea25b --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/required-fields.ts @@ -0,0 +1,31 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const requiredFieldsLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_REQUIRED_FIELDS, + source: 'apilint', + message: 'OpenAPI Object must contain one the following fields: paths, components, webhooks', + severity: 1, + linterFunction: 'hasRequiredField', + linterParams: ['paths'], + marker: 'key', + conditions: [ + { + targets: [{ path: 'root' }], + function: 'missingFields', + params: [['paths', 'components', 'webhooks']], + }, + ], + data: { + quickFix: [ + { + message: "add 'paths' section", + action: 'addChild', + snippetYaml: 'paths: \n \n', + snippetJson: '"paths": {\n \n },\n', + }, + ], + }, +}; + +export default requiredFieldsLint; 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; diff --git a/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts new file mode 100644 index 0000000000..c639f06503 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--values--type.ts @@ -0,0 +1,17 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const webhooksLint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_VALUES_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 33a6f79694..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,7 +1,11 @@ +import lint from './lint'; +import completion from './completion'; import documentation from './documentation'; import { FormatMeta } from '../../../apidom-language-types'; const meta: FormatMeta = { + lint, + completion, documentation, }; 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..6f7742bacb 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: { diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index bb988fe25b..fb8331ce18 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -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,286 +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: 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 ,)', @@ -542,7 +551,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 () { diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 6c2634b3c6..611e98f037 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -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: { @@ -489,11 +690,13 @@ 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); + /** + * 10/22 Dev note: not sure why the following is/was needed or progress status + */ // TODO yaml errors not recovered? no result? - /* assert.deepEqual(result, [ + // const specErrorDoc = TextDocument.create('foo://bar/specError.yaml', 'yaml', 0, specError); + // const specErrorResult = await languageService.doValidation(doc, validationContext); + /* assert.deepEqual(specErrorResult, [ { range: { start: { line: 16, character: 5 }, end: { line: 16, character: 6 } }, message: '(Error ,)', 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: {