Skip to content

Commit af07fd3

Browse files
committed
feat(ls): provide OpenAPI 3.0.x Header lint rules
Refs #2033
1 parent cee0d9c commit af07fd3

15 files changed

+279
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,18 @@ enum ApilintCodes {
793793
OPENAPI3_0_LINK_FIELD_DESCRIPTION_TYPE = 5270300,
794794
OPENAPI3_0_LINK_FIELD_SERVER_TYPE = 5270400,
795795

796+
OPENAPI3_0_HEADER = 5280000,
797+
OPENAPI3_0_HEADER_FIELD_DESCRIPTION_TYPE = 5280100,
798+
OPENAPI3_0_HEADER_FIELD_REQUIRED_TYPE = 5280200,
799+
OPENAPI3_0_HEADER_FIELD_DEPRECATED_TYPE = 5280300,
800+
OPENAPI3_0_HEADER_FIELD_ALLOW_EMPTY_VALUE_TYPE = 5280400,
801+
OPENAPI3_0_HEADER_FIELD_STYLE_TYPE = 5280500,
802+
OPENAPI3_0_HEADER_FIELD_EXPLODE_TYPE = 5280600,
803+
OPENAPI3_0_HEADER_FIELD_ALLOW_RESERVED_TYPE = 5280700,
804+
OPENAPI3_0_HEADER_FIELD_SCHEMA_TYPE = 5280800,
805+
OPENAPI3_0_HEADER_FIELD_EXAMPLES_VALUES_TYPE = 5280900,
806+
OPENAPI3_0_HEADER_FIELD_CONTENT_VALUES_TYPE = 5281000,
807+
796808
OPENAPI3_1 = 7000000,
797809

798810
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
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 allowEmptyValueTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_ALLOW_EMPTY_VALUE_TYPE,
6+
source: 'apilint',
7+
message: 'allowEmptyValue must be a boolean',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['boolean'],
11+
marker: 'value',
12+
target: 'allowEmptyValue',
13+
data: {},
14+
};
15+
16+
export default allowEmptyValueTypeLint;
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 allowReservedTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_ALLOW_RESERVED_TYPE,
6+
source: 'apilint',
7+
message: 'allowReserved must be a boolean',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['boolean'],
11+
marker: 'value',
12+
target: 'allowReserved',
13+
data: {},
14+
};
15+
16+
export default allowReservedTypeLint;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
// eslint-disable-next-line @typescript-eslint/naming-convention
5+
const allowedFields3_0Lint: LinterMeta = {
6+
code: ApilintCodes.NOT_ALLOWED_FIELDS,
7+
source: 'apilint',
8+
message: 'Object includes not allowed fields',
9+
severity: 1,
10+
linterFunction: 'allowedFields',
11+
linterParams: [
12+
[
13+
'description',
14+
'required',
15+
'deprecated',
16+
'allowEmptyValue',
17+
'style',
18+
'explode',
19+
'allowReserved',
20+
'schema',
21+
'example',
22+
'examples',
23+
'content',
24+
'$ref',
25+
],
26+
'x-',
27+
],
28+
marker: 'key',
29+
targetSpecs: [
30+
{ namespace: 'openapi', version: '3.0.0' },
31+
{ namespace: 'openapi', version: '3.0.1' },
32+
{ namespace: 'openapi', version: '3.0.2' },
33+
{ namespace: 'openapi', version: '3.0.3' },
34+
],
35+
};
36+
37+
export default allowedFields3_0Lint;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
// eslint-disable-next-line @typescript-eslint/naming-convention
5+
const allowedFields3_1Lint: LinterMeta = {
6+
code: ApilintCodes.NOT_ALLOWED_FIELDS,
7+
source: 'apilint',
8+
message: 'Object includes not allowed fields',
9+
severity: 1,
10+
linterFunction: 'allowedFields',
11+
linterParams: [
12+
[
13+
'description',
14+
'required',
15+
'deprecated',
16+
'allowEmptyValue',
17+
'style',
18+
'explode',
19+
'allowReserved',
20+
'schema',
21+
'example',
22+
'examples',
23+
'content',
24+
],
25+
'x-',
26+
],
27+
marker: 'key',
28+
conditions: [
29+
{
30+
function: 'missingField',
31+
params: ['$ref'],
32+
},
33+
],
34+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
35+
};
36+
37+
export default allowedFields3_1Lint;
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 contentValuesTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_CONTENT_VALUES_TYPE,
6+
source: 'apilint',
7+
message: '"content" members must be Media Type Object',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasses',
10+
linterParams: [['mediaType']],
11+
marker: 'key',
12+
markerTarget: 'content',
13+
target: 'content',
14+
data: {},
15+
};
16+
17+
export default contentValuesTypeLint;
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 deprecatedTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_DEPRECATED_TYPE,
6+
source: 'apilint',
7+
message: 'deprecated must be a boolean',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['boolean'],
11+
marker: 'value',
12+
target: 'deprecated',
13+
data: {},
14+
};
15+
16+
export default deprecatedTypeLint;
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_0_HEADER_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: 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 examplesValuesTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_EXAMPLES_VALUES_TYPE,
6+
source: 'apilint',
7+
message: '"examples" members must be Example Object',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasses',
10+
linterParams: [['example']],
11+
marker: 'key',
12+
markerTarget: 'examples',
13+
target: 'examples',
14+
data: {},
15+
};
16+
17+
export default examplesValuesTypeLint;
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 explodeTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_EXPLODE_TYPE,
6+
source: 'apilint',
7+
message: 'explode must be a boolean',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['boolean'],
11+
marker: 'value',
12+
target: 'explode',
13+
data: {},
14+
};
15+
16+
export default explodeTypeLint;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import allowedFields3_0Lint from './allowed-fields-3-0';
2+
import allowedFields3_1Lint from './allowed-fields-3-1';
3+
import descriptionTypeLint from './description--type';
4+
import requiredTypeLint from './required--type';
5+
import deprecatedTypeLint from './deprecated--type';
6+
import allowEmptyValueTypeLint from './allow-empty-value--type';
7+
import styleTypeLint from './style--type';
8+
import explodeTypeLint from './explode--type';
9+
import allowReservedTypeLint from './allow-reserved--type';
10+
import schemaTypeLint from './schema--type';
11+
import examplesValuesTypeLint from './examples--values-type';
12+
import contentValuesTypeLint from './content--values-type';
13+
14+
const lints = [
15+
descriptionTypeLint,
16+
requiredTypeLint,
17+
deprecatedTypeLint,
18+
allowEmptyValueTypeLint,
19+
styleTypeLint,
20+
explodeTypeLint,
21+
allowReservedTypeLint,
22+
schemaTypeLint,
23+
examplesValuesTypeLint,
24+
contentValuesTypeLint,
25+
allowedFields3_0Lint,
26+
allowedFields3_1Lint,
27+
];
28+
29+
export default lints;
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 requiredTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_REQUIRED_TYPE,
6+
source: 'apilint',
7+
message: 'required must be a boolean',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['boolean'],
11+
marker: 'value',
12+
target: 'required',
13+
data: {},
14+
};
15+
16+
export default requiredTypeLint;
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 schemaTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_SCHEMA_TYPE,
6+
source: 'apilint',
7+
message: 'schema must be an object',
8+
severity: 1,
9+
linterFunction: 'apilintElementOrClass',
10+
linterParams: ['schema'],
11+
marker: 'value',
12+
target: 'schema',
13+
data: {},
14+
};
15+
16+
export default schemaTypeLint;
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 styleTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_HEADER_FIELD_STYLE_TYPE,
6+
source: 'apilint',
7+
message: 'style must be a string',
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['string'],
11+
marker: 'value',
12+
target: 'style',
13+
data: {},
14+
};
15+
16+
export default styleTypeLint;

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