From 075079d0a3fedf2fa4b07d5f8a57f271be52cd65 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Mon, 18 Dec 2023 16:49:37 +0100 Subject: [PATCH] feat(ls): add rules for OpenAPI 2.0 Contact Object Refs #3104 --- packages/apidom-ls/src/config/codes.ts | 3 ++ .../src/config/openapi/contact/completion.ts | 31 +++++++++++++++++-- .../config/openapi/contact/documentation.ts | 18 +++++++++-- .../openapi/contact/lint/allowed-fields.ts | 4 +-- .../contact/lint/email--format-email.ts | 6 ++-- .../config/openapi/contact/lint/name--type.ts | 6 ++-- .../openapi/contact/lint/url--format-uri.ts | 6 ++-- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 61d0369099..2063e49404 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -647,6 +647,9 @@ enum ApilintCodes { OPENAPI2_SWAGGER_FIELD_EXTERNAL_DOCS_TYPE = 3011400, OPENAPI2_CONTACT = 3020000, + OPENAPI2_CONTACT_FIELD_NAME_TYPE = 3020100, + OPENAPI2_CONTACT_FIELD_URL_FORMAT_URI = 3020200, + OPENAPI2_CONTACT_FIELD_EMAIL_FORMAT_EMAIL = 3020300, OPENAPI2_INFO = 3030000, OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE = 3030100, diff --git a/packages/apidom-ls/src/config/openapi/contact/completion.ts b/packages/apidom-ls/src/config/openapi/contact/completion.ts index 2a084c635c..09c10f80c1 100644 --- a/packages/apidom-ls/src/config/openapi/contact/completion.ts +++ b/packages/apidom-ls/src/config/openapi/contact/completion.ts @@ -3,7 +3,7 @@ import { CompletionFormat, CompletionType, } from '../../../apidom-language-types'; -import { OpenAPI3 } from '../target-specs'; +import { OpenAPI, OpenAPI2, OpenAPI3 } from '../target-specs'; const completion: ApidomCompletionItem[] = [ { @@ -17,7 +17,20 @@ const completion: ApidomCompletionItem[] = [ kind: 'markdown', value: 'The identifying name of the contact person/organization.', }, - targetSpecs: OpenAPI3, + targetSpecs: OpenAPI, + }, + { + label: 'url', + insertText: 'url', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: 'The URL pointing to the contact information. This MUST be in the format of a URL.', + }, + targetSpecs: OpenAPI2, }, { label: 'url', @@ -32,6 +45,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'email', + insertText: 'email', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The email address of the contact person/organization. This MUST be in the format of an email address.', + }, + targetSpecs: OpenAPI2, + }, { label: 'email', insertText: 'email', diff --git a/packages/apidom-ls/src/config/openapi/contact/documentation.ts b/packages/apidom-ls/src/config/openapi/contact/documentation.ts index e1cc895b62..a393c2d5bd 100644 --- a/packages/apidom-ls/src/config/openapi/contact/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/contact/documentation.ts @@ -1,21 +1,35 @@ -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI, OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; const documentation = [ { target: 'name', docs: 'The identifying name of the contact person/organization.', - targetSpecs: OpenAPI3, + targetSpecs: OpenAPI, + }, + { + target: 'url', + docs: 'The URL pointing to the contact information. MUST be in the format of a URL.', + targetSpecs: OpenAPI2, }, { target: 'url', docs: 'The URL pointing to the contact information. This MUST be in the form of a URL.', targetSpecs: OpenAPI3, }, + { + target: 'email', + docs: 'The email address of the contact person/organization. This MUST be in the format of an email address.', + targetSpecs: OpenAPI2, + }, { target: 'email', docs: 'The email address of the contact person/organization. This MUST be in the form of an email address.', targetSpecs: OpenAPI3, }, + { + docs: '#### [Contact Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#contact-object)\n\nContact information for the exposed API.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\nname | `string` | The identifying name of the contact person/organization.\nurl | `string` | The URL pointing to the contact information. MUST be in the format of a URL.\nemail | `string` | The email address of the contact person/organization. MUST be in the format of an email address.\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##### Contact Object Example:\n\n```js\n{\n "name": "API Support",\n "url": "http://www.swagger.io/support",\n "email": "support@swagger.io"\n}\n```\n\n\n\\\nYAML\n```yaml\nname: API Support\nurl: http://www.swagger.io/support\nemail: support@swagger.io\n```', + targetSpecs: OpenAPI2, + }, { docs: '#### [Contact Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contactObject)\n\nContact information for the exposed API.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\nname | `string` | The identifying name of the contact person/organization.\nurl | `string` | The URL pointing to the contact information. MUST be in the format of a URL.\nemail | `string` | The email address of the contact person/organization. MUST be in the format of an email address.\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##### Contact Object Example\n\n\n\\\nJSON\n```json\n{\n "name": "API Support",\n "url": "http://www.example.com/support",\n "email": "support@example.com"\n}\n```\n\n\n\\\nYAML\n```yaml\nname: API Support\nurl: http://www.example.com/support\nemail: support@example.com\n```', targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/contact/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/contact/lint/allowed-fields.ts index 1611a64a1d..5cb816bb28 100644 --- a/packages/apidom-ls/src/config/openapi/contact/lint/allowed-fields.ts +++ b/packages/apidom-ls/src/config/openapi/contact/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 { OpenAPI } from '../../target-specs'; const allowedFieldsLint: LinterMeta = { code: ApilintCodes.NOT_ALLOWED_FIELDS, @@ -12,7 +12,7 @@ const allowedFieldsLint: LinterMeta = { linterFunction: 'allowedFields', linterParams: [['name', 'url', 'email'], 'x-'], marker: 'key', - targetSpecs: OpenAPI3, + targetSpecs: OpenAPI, }; export default allowedFieldsLint; diff --git a/packages/apidom-ls/src/config/openapi/contact/lint/email--format-email.ts b/packages/apidom-ls/src/config/openapi/contact/lint/email--format-email.ts index 158fd7d6fd..9e24885f15 100644 --- a/packages/apidom-ls/src/config/openapi/contact/lint/email--format-email.ts +++ b/packages/apidom-ls/src/config/openapi/contact/lint/email--format-email.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 { OpenAPI } from '../../target-specs'; const emailFormatEmailLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_CONTACT_FIELD_EMAIL_FORMAT_EMAIL, + code: ApilintCodes.OPENAPI2_CONTACT_FIELD_EMAIL_FORMAT_EMAIL, source: 'apilint', message: "'email' must be a valid email", severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const emailFormatEmailLint: LinterMeta = { marker: 'value', target: 'email', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: OpenAPI, }; export default emailFormatEmailLint; diff --git a/packages/apidom-ls/src/config/openapi/contact/lint/name--type.ts b/packages/apidom-ls/src/config/openapi/contact/lint/name--type.ts index a90d8e1ad7..9fafe26e80 100644 --- a/packages/apidom-ls/src/config/openapi/contact/lint/name--type.ts +++ b/packages/apidom-ls/src/config/openapi/contact/lint/name--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 { OpenAPI } from '../../target-specs'; const nameTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_CONTACT_FIELD_NAME_TYPE, + code: ApilintCodes.OPENAPI2_CONTACT_FIELD_NAME_TYPE, source: 'apilint', message: "'name' must be a string", severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const nameTypeLint: LinterMeta = { marker: 'value', target: 'name', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: OpenAPI, }; export default nameTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/contact/lint/url--format-uri.ts b/packages/apidom-ls/src/config/openapi/contact/lint/url--format-uri.ts index afdc650686..bb393d7b40 100644 --- a/packages/apidom-ls/src/config/openapi/contact/lint/url--format-uri.ts +++ b/packages/apidom-ls/src/config/openapi/contact/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 { OpenAPI } from '../../target-specs'; const urlFormatURILint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_CONTACT_FIELD_URL_FORMAT_URI, + code: ApilintCodes.OPENAPI2_CONTACT_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: OpenAPI, }; export default urlFormatURILint;