Skip to content

Commit a5629c1

Browse files
committed
feat(ls): provide OpenAPI 3.0.x Server Variable lint rules
Refs #2033
1 parent b0c11f8 commit a5629c1

File tree

8 files changed

+116
-0
lines changed

8 files changed

+116
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,12 @@ enum ApilintCodes {
633633
OPENAPI3_O_SERVER_FIELD_DESCRIPTION_TYPE = 5070200,
634634
OPENAPI3_O_SERVER_FIELD_VARIABLES_VALUES_TYPE = 5070300,
635635

636+
OPENAPI3_O_SERVER_VARIABLE = 5080000,
637+
OPENAPI3_O_SERVER_VARIABLE_FIELD_ENUM_TYPE = 5080100,
638+
OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_TYPE = 5080200,
639+
OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_REQUIRED,
640+
OPENAPI3_O_SERVER_VARIABLE_FIELD_DESCRIPTION_TYPE = 5080300,
641+
636642
OPENAPI3_1 = 7000000,
637643

638644
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
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: [['enum', 'default', 'description'], '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: 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 defaultRequiredLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_REQUIRED,
6+
source: 'apilint',
7+
message: "should always have a 'default'",
8+
severity: 1,
9+
linterFunction: 'hasRequiredField',
10+
linterParams: ['default'],
11+
marker: 'key',
12+
data: {
13+
quickFix: [
14+
{
15+
message: "add 'default' field",
16+
action: 'addChild',
17+
snippetYaml: 'default: \n ',
18+
snippetJson: '"default": "",\n ',
19+
},
20+
],
21+
},
22+
};
23+
24+
export default defaultRequiredLint;
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 defaultTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_TYPE,
6+
source: 'apilint',
7+
message: "'default' must be a string",
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['string'],
11+
marker: 'value',
12+
target: 'default',
13+
data: {},
14+
};
15+
16+
export default defaultTypeLint;
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_VARIABLE_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: 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 enumTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_ENUM_TYPE,
6+
source: 'apilint',
7+
message: "'enum' must be an array of strings",
8+
severity: 1,
9+
linterFunction: 'apilintArrayOfType',
10+
linterParams: ['string'],
11+
marker: 'key',
12+
target: 'enum',
13+
data: {},
14+
};
15+
16+
export default enumTypeLint;
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 enumTypeLint from './enum--type';
3+
import defaultTypeLint from './default--type';
4+
import defaultRequiredLint from './default--required';
5+
import descriptionTypeLint from './description--type';
6+
7+
const lints = [
8+
enumTypeLint,
9+
defaultTypeLint,
10+
defaultRequiredLint,
11+
descriptionTypeLint,
12+
allowedFieldsLint,
13+
];
14+
15+
export default lints;

packages/apidom-ls/src/config/openapi/server-variable/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)