diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 1aa0dd003a..494bec9c1d 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -701,6 +701,11 @@ enum ApilintCodes { OPENAPI2_OPERATION_FIELD_SECURITY_TYPE = 3081300, OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE, + OPENAPI2_EXTERNAL_DOCUMENTATION = 3090000, + OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE = 3090100, + OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI = 3090200, + OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED, + OPENAPI3_0 = 5000000, OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100, diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/completion.ts b/packages/apidom-ls/src/config/openapi/external-documentation/completion.ts index a4909d6aae..7d66197f4f 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/completion.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/completion.ts @@ -3,9 +3,23 @@ import { CompletionFormat, CompletionType, } from '../../../apidom-language-types'; -import { OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../target-specs'; const completion: ApidomCompletionItem[] = [ + { + label: 'description', + insertText: 'description', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.', + }, + targetSpecs: OpenAPI2, + }, { label: 'description', insertText: 'description', @@ -20,6 +34,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'url', + insertText: 'url', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '**Required.** The URL for the target documentation. Value MUST be in the format of a URL.', + }, + targetSpecs: OpenAPI2, + }, { label: 'url', insertText: 'url', diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/documentation.ts b/packages/apidom-ls/src/config/openapi/external-documentation/documentation.ts index 70e37c0f41..fef4fec07d 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/documentation.ts @@ -1,16 +1,30 @@ -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; const documentation = [ + { + target: 'description', + docs: 'A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.', + targetSpecs: OpenAPI2, + }, { target: 'description', docs: 'A description of the target documentation. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.', targetSpecs: OpenAPI3, }, + { + target: 'url', + docs: '**Required.** The URL for the target documentation. Value MUST be in the format of a URL.', + targetSpecs: OpenAPI2, + }, { target: 'url', docs: '**REQUIRED**. The URL for the target documentation. This MUST be in the form of a URL.', targetSpecs: OpenAPI3, }, + { + docs: '#### [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#external-documentation-object)\n\nAllows referencing an external resource for extended documentation.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.\nurl | `string` | **Required.** The URL for the target documentation. Value MUST be in the format of a URL.\n\n##### Patterned Objects\n\nField Pattern | Type | Description\n---|:---:|---\n^x- | Any | Allows extensions to the Swagger Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Vendor Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#vendorExtensions) for further details.\n\n##### External Documentation Object Example\n\n```js\n{\n "description": "Find more info here",\n "url": "https://swagger.io"\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: Find more info here\nurl: https://swagger.io\n```', + targetSpecs: OpenAPI2, + }, { docs: '#### [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#externalDocumentationObject)\n\nAllows referencing an external resource for extended documentation.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A short description of the target documentation. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\nurl | `string` | **REQUIRED**. The URL for the target documentation. Value MUST be in the format of a URL.\n\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions).\n\n##### External Documentation Object Example\n\n\n\\\nJSON\n```json\n{\n "description": "Find more info here",\n "url": "https://example.com"\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: Find more info here\nurl: https://example.com\n```', targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/external-documentation/lint/allowed-fields.ts index 91c1dd7cf1..958ffc486f 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/lint/allowed-fields.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/lint/allowed-fields.ts @@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const allowedFieldsLint: LinterMeta = { code: ApilintCodes.NOT_ALLOWED_FIELDS, @@ -12,7 +12,7 @@ const allowedFieldsLint: LinterMeta = { linterFunction: 'allowedFields', linterParams: [['description', 'url'], 'x-'], marker: 'key', - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default allowedFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/lint/description--type.ts b/packages/apidom-ls/src/config/openapi/external-documentation/lint/description--type.ts index 3081be384a..d8db37b99d 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/lint/description--type.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/lint/description--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const descriptionTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE, + code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE, source: 'apilint', message: "'description' must be a string", severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const descriptionTypeLint: LinterMeta = { marker: 'value', target: 'description', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default descriptionTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--format-uri.ts b/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--format-uri.ts index 3eade3101f..ae2cf9eeab 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--format-uri.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--format-uri.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const urlFormatURILint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI, + code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI, source: 'apilint', message: "'url' value must be a valid URL", severity: DiagnosticSeverity.Error, @@ -13,7 +13,7 @@ const urlFormatURILint: LinterMeta = { marker: 'value', target: 'url', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default urlFormatURILint; diff --git a/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--required.ts b/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--required.ts index 732c7e4a82..381bab76ec 100644 --- a/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--required.ts +++ b/packages/apidom-ls/src/config/openapi/external-documentation/lint/url--required.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const urlRequiredLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED, + code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED, source: 'apilint', message: "should always have an 'url'", severity: DiagnosticSeverity.Error, @@ -22,7 +22,7 @@ const urlRequiredLint: LinterMeta = { }, ], }, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default urlRequiredLint;