Skip to content

Commit beb02b9

Browse files
authored
feat(ls): provide OpenAPI 3.1.0 lint and completion for Link object (#2195)
1 parent 50baf52 commit beb02b9

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ const completion: ApidomCompletionItem[] = [
3636
{ namespace: 'openapi', version: '3.0.3' },
3737
],
3838
},
39+
{
40+
label: 'operationRef',
41+
insertText: 'operationRef',
42+
kind: 14,
43+
format: CompletionFormat.QUOTED,
44+
type: CompletionType.PROPERTY,
45+
insertTextFormat: 2,
46+
documentation: {
47+
kind: 'markdown',
48+
value:
49+
'A relative or absolute URI reference to an OAS operation. This field is mutually exclusive of the `operationId` field, and MUST point to an [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject). Relative `operationRef` values MAY be used to locate an existing [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) in the OpenAPI definition. See the rules for resolving [Relative References](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relativeReferencesURI).',
50+
},
51+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
52+
},
3953
{
4054
label: 'operationId',
4155
insertText: 'operationId',
@@ -68,6 +82,20 @@ const completion: ApidomCompletionItem[] = [
6882
{ namespace: 'openapi', version: '3.0.3' },
6983
],
7084
},
85+
{
86+
label: 'parameters',
87+
insertText: 'parameters',
88+
kind: 14,
89+
format: CompletionFormat.OBJECT,
90+
type: CompletionType.PROPERTY,
91+
insertTextFormat: 2,
92+
documentation: {
93+
kind: 'markdown',
94+
value:
95+
'Map[`string`, Any | [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression)]\n\\\n\\\nA map representing parameters to pass to an operation as specified with `operationId` or identified via `operationRef`. The key is the parameter name to be used, whereas the value can be a constant or an expression to be evaluated and passed to the linked operation. The parameter name can be qualified using the [parameter location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterIn) `[{in}.]{name}` for operations that use the same parameter name in different locations (e.g. path.id).',
96+
},
97+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
98+
},
7199
{
72100
label: 'requestBody',
73101
insertText: 'requestBody',
@@ -87,6 +115,20 @@ const completion: ApidomCompletionItem[] = [
87115
{ namespace: 'openapi', version: '3.0.3' },
88116
],
89117
},
118+
{
119+
label: 'requestBody',
120+
insertText: 'requestBody',
121+
kind: 14,
122+
format: CompletionFormat.QUOTED,
123+
type: CompletionType.PROPERTY,
124+
insertTextFormat: 2,
125+
documentation: {
126+
kind: 'markdown',
127+
value:
128+
'Any | [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression)\n\\\n\\\nA literal value or [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression) to use as a request body when calling the target operation.',
129+
},
130+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
131+
},
90132
{
91133
label: 'description',
92134
insertText: 'description',
@@ -112,6 +154,26 @@ const completion: ApidomCompletionItem[] = [
112154
value:
113155
'[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)\n\\\n\\\nA server object to be used by the target operation.',
114156
},
157+
targetSpecs: [
158+
{ namespace: 'openapi', version: '3.0.0' },
159+
{ namespace: 'openapi', version: '3.0.1' },
160+
{ namespace: 'openapi', version: '3.0.2' },
161+
{ namespace: 'openapi', version: '3.0.3' },
162+
],
163+
},
164+
{
165+
label: 'server',
166+
insertText: 'server',
167+
kind: 14,
168+
format: CompletionFormat.OBJECT,
169+
type: CompletionType.PROPERTY,
170+
insertTextFormat: 2,
171+
documentation: {
172+
kind: 'markdown',
173+
value:
174+
'[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)\n\\\n\\\nA server object to be used by the target operation.',
175+
},
176+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
115177
},
116178
];
117179

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+
// 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+
['operationRef', 'operationId', 'parameters', 'requestBody', 'description', 'server'],
13+
'x-',
14+
],
15+
marker: 'key',
16+
conditions: [
17+
{
18+
function: 'missingField',
19+
params: ['$ref'],
20+
},
21+
],
22+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
23+
};
24+
export default allowedFields3_1Lint;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import allowedFields3_0Lint from './allowed-fields-3-0';
2+
import allowedFields3_1Lint from './allowed-fields-3-1';
23
import operationRefFormatUriLink from './operation-ref--format-uri';
34
import operationIdTypeLint from './operation-id--type';
45
import descriptionTypeLint from './description--type';
@@ -10,6 +11,7 @@ const links = [
1011
descriptionTypeLint,
1112
serverTypeLint,
1213
allowedFields3_0Lint,
14+
allowedFields3_1Lint,
1315
];
1416

1517
export default links;

0 commit comments

Comments
 (0)