Skip to content

Commit 0b6e0bf

Browse files
committed
feat(ls): provide OpenAPI 3.0.x Info lint rules
Refs #2033
1 parent 0fe609e commit 0b6e0bf

16 files changed

+59
-31
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,6 @@ enum ApilintCodes {
570570
OPENAPI2_CONTACT_FIELD_EMAIL_FORMAT_EMAIL = 3010300,
571571

572572
OPENAPI2_INFO = 3020000,
573-
OPENAPI2_INFO_FIELD_TITLE_TYPE = 3020100,
574-
OPENAPI2_INFO_FIELD_TITLE_REQUIRED,
575-
OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE = 3020200,
576-
OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE = 3020300,
577-
OPENAPI2_INFO_FIELD_CONTACT_TYPE = 3020400,
578-
OPENAPI2_INFO_FIELD_LICENSE_TYPE = 3020500,
579-
OPENAPI2_INFO_FIELD_VERSION_TYPE = 3020600,
580-
OPENAPI2_INFO_FIELD_VERSION_REQUIRED,
581573

582574
OPENAPI3_0 = 5000000,
583575

@@ -599,14 +591,24 @@ enum ApilintCodes {
599591
OPENAPI3_0_OPEN_API_FIELD_TAGS_TYPE = 5010600,
600592
OPENAPI3_0_OPEN_API_FIELD_TAGS_ITEMS_TYPE,
601593
OPENAPI3_0_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE = 5010700,
594+
OPENAPI3_0_INFO_FIELD_VERSION_TYPE = 5010800,
595+
OPENAPI3_0_INFO_FIELD_VERSION_REQUIRED,
596+
597+
OPENAPI3_0_INFO = 5020000,
598+
OPENAPI3_0_INFO_FIELD_TITLE_TYPE = 5020100,
599+
OPENAPI3_0_INFO_FIELD_TITLE_REQUIRED,
600+
OPENAPI3_0_INFO_FIELD_DESCRIPTION_TYPE = 5020200,
601+
OPENAPI3_0_INFO_FIELD_TERMS_OF_SERVICE_TYPE = 5020300,
602+
OPENAPI3_0_INFO_FIELD_TERMS_OF_SERVICE_FORMAT_URI,
603+
OPENAPI3_0_INFO_FIELD_CONTACT_TYPE = 5020400,
604+
OPENAPI3_0_INFO_FIELD_LICENSE_TYPE = 5020500,
602605

603606
OPENAPI3_1 = 7000000,
604607

605608
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
606609

607610
OPENAPI3_1_INFO = 7010000,
608611
OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7010100,
609-
OPENAPI3_1_INFO_FIELD_TERMS_OF_SERVICE_FORMAT_URI = 7010200,
610612

611613
ADS = 8000000,
612614
ADS_INFO = 8010000,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
// eslint-disable-next-line @typescript-eslint/naming-convention
5-
const allowedFields2_0__3_0_3Lint: LinterMeta = {
5+
const allowedFields3_0Lint: LinterMeta = {
66
code: ApilintCodes.NOT_ALLOWED_FIELDS,
77
source: 'apilint',
88
message: 'Object includes not allowed fields',
99
severity: 1,
1010
linterFunction: 'allowedFields',
11-
linterParams: [['title', 'version', 'description', 'termsOfService', 'contact', 'license'], 'x-'],
11+
linterParams: [['title', 'description', 'termsOfService', 'contact', 'license', 'version'], 'x-'],
1212
marker: 'key',
1313
targetSpecs: [
14-
{ namespace: 'openapi', version: '2.0' },
1514
{ namespace: 'openapi', version: '3.0.0' },
1615
{ namespace: 'openapi', version: '3.0.1' },
1716
{ namespace: 'openapi', version: '3.0.2' },
1817
{ namespace: 'openapi', version: '3.0.3' },
1918
],
2019
};
2120

22-
export default allowedFields2_0__3_0_3Lint;
21+
export default allowedFields3_0Lint;

packages/apidom-ls/src/config/openapi/info/lint/allowed-fields-3-1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const allowedFields3_1Lint: LinterMeta = {
99
severity: 1,
1010
linterFunction: 'allowedFields',
1111
linterParams: [
12-
['title', 'summary', 'version', 'description', 'termsOfService', 'contact', 'license'],
12+
['title', 'summary', 'description', 'termsOfService', 'contact', 'license', 'version'],
1313
'x-',
1414
],
1515
marker: 'key',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const contactTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_CONTACT_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_CONTACT_TYPE,
66
source: 'apilint',
77
message: 'contact must be an object',
88
severity: 1,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const descriptionTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_DESCRIPTION_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_DESCRIPTION_TYPE,
66
source: 'apilint',
77
message: 'description must be a string',
88
severity: 1,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import allowedFields2_0__3_0_3Lint from './allowed-fields-2-0--3-0-3';
1+
import allowedFields3_0Lint from './allowed-fields-3-0';
22
import allowedFields3_1Lint from './allowed-fields-3-1';
33
import titleTypeLint from './title--type';
44
import titleRequiredLint from './title--required';
@@ -22,7 +22,7 @@ const infoLints = [
2222
licenseTypeLint,
2323
versionTypeLint,
2424
versionRequiredLint,
25-
allowedFields2_0__3_0_3Lint,
25+
allowedFields3_0Lint,
2626
allowedFields3_1Lint,
2727
];
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const licenseTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_LICENSE_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_LICENSE_TYPE,
66
source: 'apilint',
77
message: 'license must be an object',
88
severity: 1,

packages/apidom-ls/src/config/openapi/info/lint/terms-of-service--format-uri.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const termsOfServiceFormatURILint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI3_1_INFO_FIELD_TERMS_OF_SERVICE_FORMAT_URI,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TERMS_OF_SERVICE_FORMAT_URI,
66
source: 'apilint',
77
message: 'termsOfService MUST be in the format of a URL.',
88
severity: 1,
99
linterFunction: 'apilintValidURI',
1010
marker: 'value',
1111
target: 'termsOfService',
1212
data: {},
13-
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
13+
targetSpecs: [
14+
{ namespace: 'openapi', version: '3.0.0' },
15+
{ namespace: 'openapi', version: '3.0.1' },
16+
{ namespace: 'openapi', version: '3.0.2' },
17+
{ namespace: 'openapi', version: '3.0.3' },
18+
{ namespace: 'openapi', version: '3.1.0' },
19+
],
1420
};
1521

1622
export default termsOfServiceFormatURILint;

packages/apidom-ls/src/config/openapi/info/lint/terms-of-service--type.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const termsOfServiceTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_TERMS_OF_SERVICE_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TERMS_OF_SERVICE_TYPE,
66
source: 'apilint',
77
message: 'termsOfService must be a string',
88
severity: 1,
@@ -11,6 +11,13 @@ const termsOfServiceTypeLint: LinterMeta = {
1111
marker: 'value',
1212
target: 'termsOfService',
1313
data: {},
14+
targetSpecs: [
15+
{ namespace: 'openapi', version: '3.0.0' },
16+
{ namespace: 'openapi', version: '3.0.1' },
17+
{ namespace: 'openapi', version: '3.0.2' },
18+
{ namespace: 'openapi', version: '3.0.3' },
19+
{ namespace: 'openapi', version: '3.1.0' },
20+
],
1421
};
1522

1623
export default termsOfServiceTypeLint;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const titleRequiredLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_TITLE_REQUIRED,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_REQUIRED,
66
source: 'apilint',
77
message: "should always have a 'title'",
88
severity: 1,
@@ -19,6 +19,13 @@ const titleRequiredLint: LinterMeta = {
1919
},
2020
],
2121
},
22+
targetSpecs: [
23+
{ namespace: 'openapi', version: '3.0.0' },
24+
{ namespace: 'openapi', version: '3.0.1' },
25+
{ namespace: 'openapi', version: '3.0.2' },
26+
{ namespace: 'openapi', version: '3.0.3' },
27+
{ namespace: 'openapi', version: '3.1.0' },
28+
],
2229
};
2330

2431
export default titleRequiredLint;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const titleTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_TITLE_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_TITLE_TYPE,
66
source: 'apilint',
77
message: 'title must be a string',
88
severity: 1,
@@ -11,6 +11,13 @@ const titleTypeLint: LinterMeta = {
1111
marker: 'value',
1212
target: 'title',
1313
data: {},
14+
targetSpecs: [
15+
{ namespace: 'openapi', version: '3.0.0' },
16+
{ namespace: 'openapi', version: '3.0.1' },
17+
{ namespace: 'openapi', version: '3.0.2' },
18+
{ namespace: 'openapi', version: '3.0.3' },
19+
{ namespace: 'openapi', version: '3.1.0' },
20+
],
1421
};
1522

1623
export default titleTypeLint;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const versionRequiredLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_VERSION_REQUIRED,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_VERSION_REQUIRED,
66
source: 'apilint',
77
message: "should always have a 'version'",
88
severity: 1,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ApilintCodes from '../../../codes';
22
import { LinterMeta } from '../../../../apidom-language-types';
33

44
const versionTypeLint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI2_INFO_FIELD_VERSION_TYPE,
5+
code: ApilintCodes.OPENAPI3_0_INFO_FIELD_VERSION_TYPE,
66
source: 'apilint',
77
message: 'version must be a string',
88
severity: 1,

packages/apidom-ls/test/openapi-json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ describe('apidom-ls', function () {
458458
},
459459
message: "should always have a 'title'",
460460
severity: 1,
461-
code: 3020101,
461+
code: 5020101,
462462
source: 'apilint',
463463
data: {
464464
quickFix: [
@@ -522,7 +522,7 @@ describe('apidom-ls', function () {
522522
},
523523
message: "should always have a 'version'",
524524
severity: 1,
525-
code: 3020601,
525+
code: 5010801,
526526
source: 'apilint',
527527
data: {
528528
quickFix: [

packages/apidom-ls/test/openapi-yaml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ describe('apidom-ls-yaml', function () {
483483
},
484484
message: "should always have a 'title'",
485485
severity: 1,
486-
code: 3020101,
486+
code: 5020101,
487487
source: 'apilint',
488488
data: {
489489
quickFix: [

packages/apidom-ls/test/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('apidom-ls-validate', function () {
238238
},
239239
message: "should always have a 'title'",
240240
severity: 1,
241-
code: 3020101,
241+
code: 5020101,
242242
source: 'apilint',
243243
data: {
244244
quickFix: [
@@ -807,7 +807,7 @@ describe('apidom-ls-validate', function () {
807807
},
808808
message: "should always have a 'title'",
809809
severity: 1,
810-
code: 3020101,
810+
code: 5020101,
811811
source: 'apilint',
812812
data: {
813813
quickFix: [

0 commit comments

Comments
 (0)