Skip to content

Commit cc11101

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 Info Object (#3547)
Refs #3104
1 parent 0055a09 commit cc11101

14 files changed

+158
-28
lines changed

packages/apidom-ls/src/config/codes.ts

+6
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,12 @@ enum ApilintCodes {
649649
OPENAPI2_CONTACT = 3020000,
650650

651651
OPENAPI2_INFO = 3030000,
652+
OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE = 3030100,
653+
OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE = 3030200,
654+
OPENAPI2_INFO_FIELD_CONTACT_TYPE = 3030300,
655+
OPENAPI2_INFO_FIELD_LICENSE_TYPE = 3030400,
656+
OPENAPI2_INFO_FIELD_VERSION_TYPE = 3030500,
657+
OPENAPI2_INFO_FIELD_VERSION_REQUIRED,
652658

653659
OPENAPI2_PATH_TEMPLATE = 3040000,
654660
OPENAPI2_PATH_TEMPLATE_VALUE_WELL_FORMED = 3040100,

packages/apidom-ls/src/config/openapi/info/completion.ts

+83-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ import {
33
CompletionFormat,
44
CompletionType,
55
} from '../../../apidom-language-types';
6-
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
6+
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
77

88
const completion: ApidomCompletionItem[] = [
9+
{
10+
label: 'title',
11+
insertText: 'title',
12+
kind: 14,
13+
format: CompletionFormat.QUOTED,
14+
type: CompletionType.PROPERTY,
15+
insertTextFormat: 2,
16+
documentation: {
17+
kind: 'markdown',
18+
value: '**REQUIRED.** The title of the application.',
19+
},
20+
targetSpecs: OpenAPI2,
21+
},
922
{
1023
label: 'title',
1124
insertText: 'title',
@@ -32,6 +45,20 @@ const completion: ApidomCompletionItem[] = [
3245
},
3346
targetSpecs: OpenAPI31,
3447
},
48+
{
49+
label: 'description',
50+
insertText: 'description',
51+
kind: 14,
52+
format: CompletionFormat.QUOTED,
53+
type: CompletionType.PROPERTY,
54+
insertTextFormat: 2,
55+
documentation: {
56+
kind: 'markdown',
57+
value:
58+
'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.',
59+
},
60+
targetSpecs: OpenAPI2,
61+
},
3562
{
3663
label: 'description',
3764
insertText: 'description',
@@ -46,6 +73,19 @@ const completion: ApidomCompletionItem[] = [
4673
},
4774
targetSpecs: OpenAPI3,
4875
},
76+
{
77+
label: 'termsOfService',
78+
insertText: 'termsOfService',
79+
kind: 14,
80+
format: CompletionFormat.QUOTED,
81+
type: CompletionType.PROPERTY,
82+
insertTextFormat: 2,
83+
documentation: {
84+
kind: 'markdown',
85+
value: 'The Terms of Service for the API.',
86+
},
87+
targetSpecs: OpenAPI2,
88+
},
4989
{
5090
label: 'termsOfService',
5191
insertText: 'termsOfService',
@@ -59,6 +99,20 @@ const completion: ApidomCompletionItem[] = [
5999
},
60100
targetSpecs: OpenAPI3,
61101
},
102+
{
103+
label: 'contact',
104+
insertText: 'contact',
105+
kind: 14,
106+
format: CompletionFormat.OBJECT,
107+
type: CompletionType.PROPERTY,
108+
insertTextFormat: 2,
109+
documentation: {
110+
kind: 'markdown',
111+
value:
112+
'[Contact Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#contactObject)\n\\\n\\\nThe contact information for the exposed API.',
113+
},
114+
targetSpecs: OpenAPI2,
115+
},
62116
{
63117
label: 'contact',
64118
insertText: 'contact',
@@ -87,6 +141,20 @@ const completion: ApidomCompletionItem[] = [
87141
},
88142
targetSpecs: OpenAPI31,
89143
},
144+
{
145+
label: 'license',
146+
insertText: 'license',
147+
kind: 14,
148+
format: CompletionFormat.OBJECT,
149+
type: CompletionType.PROPERTY,
150+
insertTextFormat: 2,
151+
documentation: {
152+
kind: 'markdown',
153+
value:
154+
'[License Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#licenseObject)\n\\\n\\\nThe license information for the exposed API.',
155+
},
156+
targetSpecs: OpenAPI2,
157+
},
90158
{
91159
label: 'license',
92160
insertText: 'license',
@@ -115,6 +183,20 @@ const completion: ApidomCompletionItem[] = [
115183
},
116184
targetSpecs: OpenAPI31,
117185
},
186+
{
187+
label: 'version',
188+
insertText: 'version',
189+
kind: 14,
190+
format: CompletionFormat.QUOTED_FORCED,
191+
type: CompletionType.PROPERTY,
192+
insertTextFormat: 2,
193+
documentation: {
194+
kind: 'markdown',
195+
value:
196+
'**Required** Provides the version of the application API (not to be confused with the specification version).',
197+
},
198+
targetSpecs: OpenAPI2,
199+
},
118200
{
119201
label: 'version',
120202
insertText: 'version',

packages/apidom-ls/src/config/openapi/info/documentation.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
1+
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
22

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

1414
const documentation = [
15+
{
16+
target: 'title',
17+
docs: '**Required.** The title of the application.',
18+
targetSpecs: OpenAPI2,
19+
},
1520
{
1621
target: 'title',
1722
docs: '**REQUIRED.** The title of the API.',
@@ -22,16 +27,31 @@ const documentation = [
2227
docs: 'A short summary of the API.',
2328
targetSpecs: OpenAPI31,
2429
},
30+
{
31+
target: 'description',
32+
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.',
33+
targetSpecs: OpenAPI2,
34+
},
2535
{
2636
target: 'description',
2737
docs: 'A description of the API. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
2838
targetSpecs: OpenAPI3,
2939
},
40+
{
41+
target: 'termsOfService',
42+
docs: 'The Terms of Service for the API.',
43+
targetSpecs: OpenAPI2,
44+
},
3045
{
3146
target: 'termsOfService',
3247
docs: 'A URL to the Terms of Service for the API. This MUST be in the form of a URL.',
3348
targetSpecs: OpenAPI3,
3449
},
50+
{
51+
target: 'version',
52+
docs: '**Required** Provides the version of the application API (not to be confused with the specification version).',
53+
targetSpecs: OpenAPI2,
54+
},
3555
{
3656
target: 'version',
3757
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).',

packages/apidom-ls/src/config/openapi/info/lint/allowed-fields-3-0.ts renamed to packages/apidom-ls/src/config/openapi/info/lint/allowed-fields-2-0--3-0.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI30 } from '../../target-specs';
5+
import { OpenAPI2, OpenAPI30 } from '../../target-specs';
66

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

19-
export default allowedFields3_0Lint;
19+
export default allowedFields2_0__3_0Lint;

packages/apidom-ls/src/config/openapi/info/lint/contact--type.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const contactTypeLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_CONTACT_TYPE,
8+
code: ApilintCodes.OPENAPI2_INFO_FIELD_CONTACT_TYPE,
99
source: 'apilint',
1010
message: 'contact must be an object',
1111
severity: DiagnosticSeverity.Error,
@@ -14,7 +14,7 @@ const contactTypeLint: LinterMeta = {
1414
marker: 'value',
1515
target: 'contact',
1616
data: {},
17-
targetSpecs: OpenAPI3,
17+
targetSpecs: OpenAPI,
1818
};
1919

2020
export default contactTypeLint;

packages/apidom-ls/src/config/openapi/info/lint/description--type.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const descriptionTypeLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_DESCRIPTION_TYPE,
8+
code: ApilintCodes.OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE,
99
source: 'apilint',
1010
message: 'description must be a string',
1111
severity: DiagnosticSeverity.Error,
@@ -14,7 +14,7 @@ const descriptionTypeLint: LinterMeta = {
1414
marker: 'value',
1515
target: 'description',
1616
data: {},
17-
targetSpecs: OpenAPI3,
17+
targetSpecs: OpenAPI,
1818
};
1919

2020
export default descriptionTypeLint;

packages/apidom-ls/src/config/openapi/info/lint/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import allowedFields3_0Lint from './allowed-fields-3-0';
1+
import allowedFields2_0__3_0Lint from './allowed-fields-2-0--3-0';
22
import allowedFields3_1Lint from './allowed-fields-3-1';
33
import titleTypeLint from './title--type';
44
import titleRequiredLint from './title--required';
55
import summaryTypeLint from './summary--type';
66
import descriptionTypeLint from './description--type';
7+
import termsOfServiceTypeLint from './terms-of-service--type';
78
import termsOfServiceFormatURILint from './terms-of-service--format-uri';
89
import contactTypeLint from './contact--type';
910
import licenseTypeLint from './license--type';
@@ -15,12 +16,13 @@ const lints = [
1516
titleRequiredLint,
1617
summaryTypeLint,
1718
descriptionTypeLint,
19+
termsOfServiceTypeLint,
1820
termsOfServiceFormatURILint,
1921
contactTypeLint,
2022
licenseTypeLint,
2123
versionTypeLint,
2224
versionRequiredLint,
23-
allowedFields3_0Lint,
25+
allowedFields2_0__3_0Lint,
2426
allowedFields3_1Lint,
2527
];
2628

packages/apidom-ls/src/config/openapi/info/lint/license--type.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const licenseTypeLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_LICENSE_TYPE,
8+
code: ApilintCodes.OPENAPI2_INFO_FIELD_LICENSE_TYPE,
99
source: 'apilint',
1010
message: 'license must be an object',
1111
severity: DiagnosticSeverity.Error,
@@ -14,7 +14,7 @@ const licenseTypeLint: LinterMeta = {
1414
marker: 'value',
1515
target: 'license',
1616
data: {},
17-
targetSpecs: OpenAPI3,
17+
targetSpecs: OpenAPI,
1818
};
1919

2020
export default licenseTypeLint;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
2+
3+
import ApilintCodes from '../../../codes';
4+
import { LinterMeta } from '../../../../apidom-language-types';
5+
import { OpenAPI2 } from '../../target-specs';
6+
7+
const termsOfServiceTypeLint: LinterMeta = {
8+
code: ApilintCodes.OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE,
9+
source: 'apilint',
10+
message: 'termsOfService must be a string',
11+
severity: DiagnosticSeverity.Error,
12+
linterFunction: 'apilintType',
13+
linterParams: ['string'],
14+
marker: 'value',
15+
target: 'termsOfService',
16+
data: {},
17+
targetSpecs: OpenAPI2,
18+
};
19+
20+
export default termsOfServiceTypeLint;

packages/apidom-ls/src/config/openapi/info/lint/title--required.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const titleRequiredLint: LinterMeta = {
88
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_REQUIRED,
@@ -22,7 +22,7 @@ const titleRequiredLint: LinterMeta = {
2222
},
2323
],
2424
},
25-
targetSpecs: OpenAPI3,
25+
targetSpecs: OpenAPI,
2626
};
2727

2828
export default titleRequiredLint;

packages/apidom-ls/src/config/openapi/info/lint/title--type.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const titleTypeLint: LinterMeta = {
88
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_TYPE,
@@ -14,7 +14,7 @@ const titleTypeLint: LinterMeta = {
1414
marker: 'value',
1515
target: 'title',
1616
data: {},
17-
targetSpecs: OpenAPI3,
17+
targetSpecs: OpenAPI,
1818
};
1919

2020
export default titleTypeLint;

packages/apidom-ls/src/config/openapi/info/lint/version--required.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const versionRequiredLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_VERSION_REQUIRED,
8+
code: ApilintCodes.OPENAPI2_INFO_FIELD_VERSION_REQUIRED,
99
source: 'apilint',
1010
message: "should always have a 'version'",
1111
severity: DiagnosticSeverity.Error,
@@ -22,7 +22,7 @@ const versionRequiredLint: LinterMeta = {
2222
},
2323
],
2424
},
25-
targetSpecs: OpenAPI3,
25+
targetSpecs: OpenAPI,
2626
};
2727

2828
export default versionRequiredLint;

0 commit comments

Comments
 (0)