Skip to content

Commit b0cf458

Browse files
committed
feat(ls): provide OpenAPI 3.0.x Server lint rules
Refs #2033
1 parent 4470ae7 commit b0cf458

File tree

12 files changed

+131
-8
lines changed

12 files changed

+131
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ enum ApilintCodes {
627627
OPENAPI3_0_COMPONENTS_FIELD_LINKS_VALUES_TYPE = 5060800,
628628
OPENAPI3_0_COMPONENTS_FIELD_CALLBACKS_VALUES_TYPE = 5060900,
629629

630+
OPENAPI3_O_SERVER = 5070000,
631+
OPENAPI3_O_SERVER_FIELD_URL_FORMAT_URI = 5070100,
632+
OPENAPI3_O_SERVER_FIELD_URL_REQUIRED,
633+
OPENAPI3_O_SERVER_FIELD_DESCRIPTION_TYPE = 5070200,
634+
OPENAPI3_O_SERVER_FIELD_VARIABLES_VALUES_TYPE = 5070300,
635+
630636
OPENAPI3_1 = 7000000,
631637

632638
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import emailFormatEmailLint from './email--format-email';
33
import nameTypeLint from './name--type';
44
import urlFormatURILint from './url--format-uri';
55

6-
const contactLints = [emailFormatEmailLint, nameTypeLint, urlFormatURILint, allowedFieldsLint];
6+
const lints = [emailFormatEmailLint, nameTypeLint, urlFormatURILint, allowedFieldsLint];
77

8-
export default contactLints;
8+
export default lints;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import descriptionTypeLint from './description--type';
33
import urlRequiredLint from './url--required';
44
import urlFormatURILint from './url--format-uri';
55

6-
const contactLints = [descriptionTypeLint, urlRequiredLint, urlFormatURILint, allowedFieldsLint];
6+
const lints = [descriptionTypeLint, urlRequiredLint, urlFormatURILint, allowedFieldsLint];
77

8-
export default contactLints;
8+
export default lints;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import licenseTypeLint from './license--type';
1111
import versionTypeLint from './version--type';
1212
import versionRequiredLint from './version--required';
1313

14-
const infoLints = [
14+
const lints = [
1515
titleTypeLint,
1616
titleRequiredLint,
1717
summaryTypeLint,
@@ -26,4 +26,4 @@ const infoLints = [
2626
allowedFields3_1Lint,
2727
];
2828

29-
export default infoLints;
29+
export default lints;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import nameTypeLint from './name--type';
33
import nameRequiredLint from './name--required';
44
import urlFormatURILint from './url--format-uri';
55

6-
const contactLints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];
6+
const lints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];
77

8-
export default contactLints;
8+
export default lints;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const allowedFieldsLint: LinterMeta = {
5+
code: ApilintCodes.NOT_ALLOWED_FIELDS,
6+
source: 'apilint',
7+
message: 'Object includes not allowed fields',
8+
severity: 1,
9+
linterFunction: 'allowedFields',
10+
linterParams: [['url', 'description', 'variables'], 'x-'],
11+
marker: 'key',
12+
targetSpecs: [
13+
{ namespace: 'openapi', version: '3.0.0' },
14+
{ namespace: 'openapi', version: '3.0.1' },
15+
{ namespace: 'openapi', version: '3.0.2' },
16+
{ namespace: 'openapi', version: '3.0.3' },
17+
{ namespace: 'openapi', version: '3.1.0' },
18+
],
19+
};
20+
21+
export default allowedFieldsLint;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const descriptionTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_DESCRIPTION_TYPE,
6+
source: 'apilint',
7+
message: "'description' must be a string",
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['string'],
11+
marker: 'value',
12+
target: 'description',
13+
data: {},
14+
};
15+
16+
export default descriptionTypeLint;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import allowedFieldsLint from './allowed-fields';
2+
import urlFormatURILint from './url--format-uri';
3+
import urlRequiredLint from './url--required';
4+
import descriptionTypeLint from './description--type';
5+
import variablesValuesTypeLint from './variables--values-type';
6+
7+
const lints = [
8+
urlFormatURILint,
9+
urlRequiredLint,
10+
descriptionTypeLint,
11+
variablesValuesTypeLint,
12+
allowedFieldsLint,
13+
];
14+
15+
export default lints;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const urlFormatURILint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_URL_FORMAT_URI,
6+
source: 'apilint',
7+
message: 'url MUST be in the format of an URL.',
8+
severity: 1,
9+
linterFunction: 'apilintValidURI',
10+
marker: 'value',
11+
target: 'url',
12+
data: {},
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+
],
20+
};
21+
22+
export default urlFormatURILint;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const urlRequiredLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_URL_REQUIRED,
6+
source: 'apilint',
7+
message: "should always have a 'url'",
8+
severity: 1,
9+
linterFunction: 'hasRequiredField',
10+
linterParams: ['url'],
11+
marker: 'key',
12+
data: {
13+
quickFix: [
14+
{
15+
message: "add 'url' field",
16+
action: 'addChild',
17+
snippetYaml: 'url: \n ',
18+
snippetJson: '"url": "",\n ',
19+
},
20+
],
21+
},
22+
};
23+
24+
export default urlRequiredLint;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const variablesValuesTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_VARIABLES_VALUES_TYPE,
6+
source: 'apilint',
7+
message: '"varialbes" members must be Server Variable Object',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasses',
10+
linterParams: [['serverVariable']],
11+
marker: 'key',
12+
markerTarget: 'variables',
13+
target: 'variables',
14+
data: {},
15+
};
16+
17+
export default variablesValuesTypeLint;

packages/apidom-ls/src/config/openapi/server/meta.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import lint from './lint';
12
import completion from './completion';
23
import documentation from './documentation';
34
import { FormatMeta } from '../../../apidom-language-types';
45

56
const meta: FormatMeta = {
7+
lint,
68
completion,
79
documentation,
810
};

0 commit comments

Comments
 (0)