Skip to content

Commit 8313b46

Browse files
authored
refactor(ls): optimize linting for OpenAPI Reference Object (#2165)
Refs #2033
1 parent c1e82d5 commit 8313b46

14 files changed

+66
-78
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ enum ApilintCodes {
692692
OPENAPI3_0_RESPONSES_VALUES_TYPE,
693693

694694
OPENAPI3_0_PARAMETER = 5150000,
695-
OPENAPI3_0_PARAMETER_FIELD_$REF_VALID = 5150100,
696-
OPENAPI3_0_PARAMETER_FIELD_$REF_NO_SIBLINGS,
697695
OPENAPI3_0_PARAMETER_FIELD_NAME_TYPE = 5150200,
698696
OPENAPI3_0_PARAMETER_FIELD_NAME_REQUIRED,
699697
OPENAPI3_0_PARAMETER_FIELD_IN_TYPE = 5150300,
@@ -784,6 +782,10 @@ enum ApilintCodes {
784782
OPENAPI3_DISCRIMINATOR_FIELD_PROPERTY_NAME_REQUIRED,
785783
OPENAPI3_DISCRIMINATOR_FIELD_MAPPING_TYPE = 5250200,
786784

785+
OPENAPI3_REFERENCE = 5260000,
786+
OPENAPI3_REFERENCE_FIELD_$REF_FORMAT_URI = 5260100,
787+
OPENAPI3_REFERENCE_FIELD_$REF_NO_SIBLINGS,
788+
787789
OPENAPI3_1 = 7000000,
788790

789791
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
@@ -817,11 +819,8 @@ enum ApilintCodes {
817819
OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_TYPE = 7030100,
818820
OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_MUTUALLY_EXCLUSIVE,
819821

820-
OPENAPI3_1_PATH_ITEM = 7040000,
821-
OPENAPI3_1_PATH_ITEM_FIELD_$REF_ALLOWED_SIBLINGS = 7040100,
822-
823-
OPENAPI3_1_PARAMETER = 7050000,
824-
OPENAPI3_1_PARAMETER_FIELD_$REF_ALLOWED_SIBLINGS = 7050100,
822+
OPENAPI3_1_REFERENCE = 7040000,
823+
OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS = 7040100,
825824

826825
ADS = 8000000,
827826
ADS_INFO = 8010000,

packages/apidom-ls/src/config/openapi/parameter/completion.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,7 @@ const completion: ApidomCompletionItem[] = [
5959
documentation: {
6060
kind: 'markdown',
6161
value:
62-
'**REQUIRED**. The location of the parameter. Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.',
63-
},
64-
},
65-
{
66-
label: 'description',
67-
insertText: 'description',
68-
kind: 14,
69-
format: CompletionFormat.QUOTED,
70-
type: CompletionType.PROPERTY,
71-
insertTextFormat: 2,
72-
documentation: {
73-
kind: 'markdown',
74-
value:
75-
'A description of the API. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
62+
'A brief description of the parameter. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
7663
},
7764
},
7865
{
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
'name',
14+
'in',
15+
'description',
16+
'required',
17+
'deprecated',
18+
'allowEmptyValue',
19+
'style',
20+
'explode',
21+
'allowReserved',
22+
'schema',
23+
'example',
24+
'examples',
25+
'content',
26+
'$ref',
27+
],
28+
'x-',
29+
],
30+
marker: 'key',
31+
targetSpecs: [
32+
{ namespace: 'openapi', version: '3.0.0' },
33+
{ namespace: 'openapi', version: '3.0.1' },
34+
{ namespace: 'openapi', version: '3.0.2' },
35+
{ namespace: 'openapi', version: '3.0.3' },
36+
],
37+
};
38+
39+
export default allowedFields3_0Lint;

packages/apidom-ls/src/config/openapi/parameter/lint/allowed-fields.ts renamed to packages/apidom-ls/src/config/openapi/parameter/lint/allowed-fields-3-1.ts

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

4-
const allowedFieldsLint: LinterMeta = {
4+
// eslint-disable-next-line @typescript-eslint/naming-convention
5+
const allowedFields3_1Lint: LinterMeta = {
56
code: ApilintCodes.NOT_ALLOWED_FIELDS,
67
source: 'apilint',
78
message: 'Object includes not allowed fields',
@@ -32,6 +33,7 @@ const allowedFieldsLint: LinterMeta = {
3233
params: ['$ref'],
3334
},
3435
],
36+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
3537
};
3638

37-
export default allowedFieldsLint;
39+
export default allowedFields3_1Lint;

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import allowedFieldsLint from './allowed-fields';
2-
import $refFormatURILint from './$ref--format-uri';
3-
import $refNoSiblings3_0Lint from './$ref--no-siblings-3-0';
4-
import $refAllowedSiblings3_1Lint from './$ref--allowed-siblings-3-1';
1+
import allowedFields3_0Lint from './allowed-fields-3-0';
2+
import allowedFields3_1Lint from './allowed-fields-3-1';
53
import nameTypeLint from './name--type';
64
import nameRequiredLint from './name--required';
75
import inTypeLint from './in--type';
@@ -20,10 +18,6 @@ import examplesValuesTypeLint from './examples--values-type';
2018
import contentValuesTypeLint from './content--values-type';
2119

2220
const lints = [
23-
allowedFieldsLint,
24-
$refFormatURILint,
25-
$refNoSiblings3_0Lint,
26-
$refAllowedSiblings3_1Lint,
2721
nameTypeLint,
2822
nameRequiredLint,
2923
inTypeLint,
@@ -40,6 +34,8 @@ const lints = [
4034
schemaTypeLint,
4135
examplesValuesTypeLint,
4236
contentValuesTypeLint,
37+
allowedFields3_0Lint,
38+
allowedFields3_1Lint,
4339
];
4440

4541
export default lints;

packages/apidom-ls/src/config/openapi/path-item/lint/$ref--allowed-siblings-3-1.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/apidom-ls/src/config/openapi/path-item/lint/$ref--format-uri.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const allowedFields3_1Lint: LinterMeta = {
1010
linterFunction: 'allowedFields',
1111
linterParams: [
1212
[
13-
'$ref',
1413
'summary',
1514
'description',
1615
'get',

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import allowedFields3_0Lint from './allowed-fields-3-0';
22
import allowedFields3_1Lint from './allowed-fields-3-1';
3-
import $refFormatURILint from './$ref--format-uri';
4-
import $refAllowedSiblings3_1Lint from './$ref--allowed-siblings-3-1';
53
import summaryTypeLint from './summary--type';
64
import descriptionTypeLint from './description--type';
75
import getTypeLint from './get--type';
@@ -18,8 +16,6 @@ import parametersTypeLint from './parameters--type';
1816
import parametersItemsTypeLint from './parameters--items-type';
1917

2018
const lints = [
21-
$refFormatURILint,
22-
$refAllowedSiblings3_1Lint,
2319
summaryTypeLint,
2420
descriptionTypeLint,
2521
getTypeLint,

packages/apidom-ls/src/config/openapi/parameter/lint/$ref--allowed-siblings-3-1.ts renamed to packages/apidom-ls/src/config/openapi/reference/lint/$ref--allowed-siblings-3-1.ts

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

44
// eslint-disable-next-line @typescript-eslint/naming-convention
55
const $refAllowedSiblings3_1Lint: LinterMeta = {
6-
code: ApilintCodes.OPENAPI3_1_PARAMETER_FIELD_$REF_ALLOWED_SIBLINGS,
6+
code: ApilintCodes.OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS,
77
source: 'apilint',
88
message:
99
'All other properties other then summary and description in a Reference Object are ignored',

packages/apidom-ls/src/config/openapi/parameter/lint/$ref--format-uri.ts renamed to packages/apidom-ls/src/config/openapi/reference/lint/$ref--format-uri.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 $refFormatURILint: LinterMeta = {
5-
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_$REF_VALID,
5+
code: ApilintCodes.OPENAPI3_REFERENCE_FIELD_$REF_FORMAT_URI,
66
source: 'apilint',
77
message: "'$ref' value must be a valid URI-reference",
88
severity: 1,

packages/apidom-ls/src/config/openapi/parameter/lint/$ref--no-siblings-3-0.ts renamed to packages/apidom-ls/src/config/openapi/reference/lint/$ref--no-siblings-3-0.ts

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

44
// eslint-disable-next-line @typescript-eslint/naming-convention
55
const $refNoSiblings3_0Lint: LinterMeta = {
6-
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_$REF_NO_SIBLINGS,
6+
code: ApilintCodes.OPENAPI3_REFERENCE_FIELD_$REF_NO_SIBLINGS,
77
source: 'apilint',
88
message: 'All other properties in a "$ref" object are ignored',
99
severity: 2,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import $refFormatURILint from './$ref--format-uri';
2+
import $refNoSiblings3_0Lint from './$ref--no-siblings-3-0';
3+
import $refAllowedSiblings3_1Lint from './$ref--allowed-siblings-3-1';
4+
5+
const lints = [$refFormatURILint, $refNoSiblings3_0Lint, $refAllowedSiblings3_1Lint];
6+
7+
export default lints;

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