Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ls): add rules for OpenAPI 2.0 Contact Object #3550

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 29 additions & 2 deletions packages/apidom-ls/src/config/openapi/contact/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand All @@ -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',
Expand All @@ -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',
Expand Down
18 changes: 16 additions & 2 deletions packages/apidom-ls/src/config/openapi/contact/documentation.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -12,7 +12,7 @@ const allowedFieldsLint: LinterMeta = {
linterFunction: 'allowedFields',
linterParams: [['name', 'url', 'email'], 'x-'],
marker: 'key',
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default allowedFieldsLint;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,7 +14,7 @@ const emailFormatEmailLint: LinterMeta = {
marker: 'value',
target: 'email',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default emailFormatEmailLint;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,7 +14,7 @@ const nameTypeLint: LinterMeta = {
marker: 'value',
target: 'name',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default nameTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ 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,
linterFunction: 'apilintValidURI',
marker: 'value',
target: 'url',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default urlFormatURILint;