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 Info Object #3547

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
6 changes: 6 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ enum ApilintCodes {
OPENAPI2_CONTACT = 3020000,

OPENAPI2_INFO = 3030000,
OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE = 3030100,
OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE = 3030200,
OPENAPI2_INFO_FIELD_CONTACT_TYPE = 3030300,
OPENAPI2_INFO_FIELD_LICENSE_TYPE = 3030400,
OPENAPI2_INFO_FIELD_VERSION_TYPE = 3030500,
OPENAPI2_INFO_FIELD_VERSION_REQUIRED,

OPENAPI2_PATH_TEMPLATE = 3040000,
OPENAPI2_PATH_TEMPLATE_VALUE_WELL_FORMED = 3040100,
Expand Down
84 changes: 83 additions & 1 deletion packages/apidom-ls/src/config/openapi/info/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
label: 'title',
insertText: 'title',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: '**REQUIRED.** The title of the application.',
},
targetSpecs: OpenAPI2,
},
{
label: 'title',
insertText: 'title',
Expand All @@ -32,6 +45,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'description',
insertText: 'description',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A short description of the application. [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',
Expand All @@ -46,6 +73,19 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'termsOfService',
insertText: 'termsOfService',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: 'The Terms of Service for the API.',
},
targetSpecs: OpenAPI2,
},
{
label: 'termsOfService',
insertText: 'termsOfService',
Expand All @@ -59,6 +99,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'contact',
insertText: 'contact',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Contact Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#contactObject)\n\\\n\\\nThe contact information for the exposed API.',
},
targetSpecs: OpenAPI2,
},
{
label: 'contact',
insertText: 'contact',
Expand Down Expand Up @@ -87,6 +141,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'license',
insertText: 'license',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[License Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#licenseObject)\n\\\n\\\nThe license information for the exposed API.',
},
targetSpecs: OpenAPI2,
},
{
label: 'license',
insertText: 'license',
Expand Down Expand Up @@ -115,6 +183,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'version',
insertText: 'version',
kind: 14,
format: CompletionFormat.QUOTED_FORCED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required** Provides the version of the application API (not to be confused with the specification version).',
},
targetSpecs: OpenAPI2,
},
{
label: 'version',
insertText: 'version',
Expand Down
22 changes: 21 additions & 1 deletion packages/apidom-ls/src/config/openapi/info/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

/**
* Omitted fixed fields:
Expand All @@ -12,6 +12,11 @@ import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
*/

const documentation = [
{
target: 'title',
docs: '**Required.** The title of the application.',
targetSpecs: OpenAPI2,
},
{
target: 'title',
docs: '**REQUIRED.** The title of the API.',
Expand All @@ -22,16 +27,31 @@ const documentation = [
docs: 'A short summary of the API.',
targetSpecs: OpenAPI31,
},
{
target: 'description',
docs: 'A short description of the application. [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 API. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
targetSpecs: OpenAPI3,
},
{
target: 'termsOfService',
docs: 'The Terms of Service for the API.',
targetSpecs: OpenAPI2,
},
{
target: 'termsOfService',
docs: 'A URL to the Terms of Service for the API. This MUST be in the form of a URL.',
targetSpecs: OpenAPI3,
},
{
target: 'version',
docs: '**Required** Provides the version of the application API (not to be confused with the specification version).',
targetSpecs: OpenAPI2,
},
{
target: 'version',
docs: '**REQUIRED**. The version of the OpenAPI document (which is distinct from the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasVersion) or the API implementation version).',
Expand Down
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 { OpenAPI30 } from '../../target-specs';
import { OpenAPI2, OpenAPI30 } from '../../target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields3_0Lint: LinterMeta = {
const allowedFields2_0__3_0Lint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: DiagnosticSeverity.Error,
linterFunction: 'allowedFields',
linterParams: [['title', 'description', 'termsOfService', 'contact', 'license', 'version'], 'x-'],
marker: 'key',
targetSpecs: OpenAPI30,
targetSpecs: [...OpenAPI2, ...OpenAPI30],
};

export default allowedFields3_0Lint;
export default allowedFields2_0__3_0Lint;
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 contactTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_CONTACT_TYPE,
code: ApilintCodes.OPENAPI2_INFO_FIELD_CONTACT_TYPE,
source: 'apilint',
message: 'contact must be an object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const contactTypeLint: LinterMeta = {
marker: 'value',
target: 'contact',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default contactTypeLint;
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 descriptionTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_DESCRIPTION_TYPE,
code: ApilintCodes.OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE,
source: 'apilint',
message: 'description must be a string',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const descriptionTypeLint: LinterMeta = {
marker: 'value',
target: 'description',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default descriptionTypeLint;
6 changes: 4 additions & 2 deletions packages/apidom-ls/src/config/openapi/info/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import allowedFields3_0Lint from './allowed-fields-3-0';
import allowedFields2_0__3_0Lint from './allowed-fields-2-0--3-0';
import allowedFields3_1Lint from './allowed-fields-3-1';
import titleTypeLint from './title--type';
import titleRequiredLint from './title--required';
import summaryTypeLint from './summary--type';
import descriptionTypeLint from './description--type';
import termsOfServiceTypeLint from './terms-of-service--type';
import termsOfServiceFormatURILint from './terms-of-service--format-uri';
import contactTypeLint from './contact--type';
import licenseTypeLint from './license--type';
Expand All @@ -15,12 +16,13 @@ const lints = [
titleRequiredLint,
summaryTypeLint,
descriptionTypeLint,
termsOfServiceTypeLint,
termsOfServiceFormatURILint,
contactTypeLint,
licenseTypeLint,
versionTypeLint,
versionRequiredLint,
allowedFields3_0Lint,
allowedFields2_0__3_0Lint,
allowedFields3_1Lint,
];

Expand Down
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 licenseTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_LICENSE_TYPE,
code: ApilintCodes.OPENAPI2_INFO_FIELD_LICENSE_TYPE,
source: 'apilint',
message: 'license must be an object',
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const licenseTypeLint: LinterMeta = {
marker: 'value',
target: 'license',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default licenseTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2 } from '../../target-specs';

const termsOfServiceTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE,
source: 'apilint',
message: 'termsOfService must be a string',
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintType',
linterParams: ['string'],
marker: 'value',
target: 'termsOfService',
data: {},
targetSpecs: OpenAPI2,
};

export default termsOfServiceTypeLint;
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 titleRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_REQUIRED,
Expand All @@ -22,7 +22,7 @@ const titleRequiredLint: LinterMeta = {
},
],
},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default titleRequiredLint;
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 titleTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_TYPE,
Expand All @@ -14,7 +14,7 @@ const titleTypeLint: LinterMeta = {
marker: 'value',
target: 'title',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default titleTypeLint;
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 versionRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_VERSION_REQUIRED,
code: ApilintCodes.OPENAPI2_INFO_FIELD_VERSION_REQUIRED,
source: 'apilint',
message: "should always have a 'version'",
severity: DiagnosticSeverity.Error,
Expand All @@ -22,7 +22,7 @@ const versionRequiredLint: LinterMeta = {
},
],
},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI,
};

export default versionRequiredLint;
Loading