Skip to content

Commit f0d18ac

Browse files
committed
feat(ls): provide OpenAPI 3.0.x License lint rules
Refs #2033
1 parent 773931b commit f0d18ac

File tree

7 files changed

+85
-0
lines changed

7 files changed

+85
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ enum ApilintCodes {
605605
OPENAPI3_0_CONTACT_FIELD_URL_FORMAT_URI = 5030200,
606606
OPENAPI3_0_CONTACT_FIELD_EMAIL_FORMAT_EMAIL = 5030300,
607607

608+
OPENAPI3_0_LICENSE = 5040000,
609+
OPENAPI3_0_LICENSE_FIELD_NAME_TYPE = 5040100,
610+
OPENAPI3_0_LICENSE_FIELD_NAME_REQUIRED,
611+
OPENAPI3_0_LICENSE_FIELD_URL_FORMAT_URI = 5040200,
612+
608613
OPENAPI3_1 = 7000000,
609614

610615
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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: [['name', 'url'], 'x-'],
12+
marker: 'key',
13+
};
14+
15+
export default allowedFields3_0Lint;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import allowedFields3_0Lint from './allowed-fields-3-0';
2+
import nameTypeLint from './name--type';
3+
import nameRequiredLint from './name--required';
4+
import urlFormatURILint from './url--format-uri';
5+
6+
const contactLints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];
7+
8+
export default contactLints;
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 nameRequiredLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_NAME_REQUIRED,
6+
source: 'apilint',
7+
message: "should always have a 'name'",
8+
severity: 1,
9+
linterFunction: 'hasRequiredField',
10+
linterParams: ['name'],
11+
marker: 'key',
12+
data: {
13+
quickFix: [
14+
{
15+
message: "add 'name' field",
16+
action: 'addChild',
17+
snippetYaml: 'name: \n ',
18+
snippetJson: '"name": "",\n ',
19+
},
20+
],
21+
},
22+
};
23+
24+
export default nameRequiredLint;
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 nameTypeLint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_NAME_TYPE,
6+
source: 'apilint',
7+
message: "'name' must be a string",
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['string'],
11+
marker: 'value',
12+
target: 'name',
13+
data: {},
14+
};
15+
16+
export default nameTypeLint;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const urlFormatURILint: LinterMeta = {
5+
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_URL_FORMAT_URI,
6+
source: 'apilint',
7+
message: "'url' value must be a valid URL",
8+
severity: 1,
9+
linterFunction: 'apilintValidURI',
10+
marker: 'value',
11+
target: 'url',
12+
data: {},
13+
};
14+
15+
export default urlFormatURILint;

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