Skip to content

Commit 5dac8ef

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 Operation Object (#3561)
Refs #3104
1 parent b515c5e commit 5dac8ef

25 files changed

+396
-61
lines changed

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,24 @@ enum ApilintCodes {
683683
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE = 3070900,
684684
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE = 3071000,
685685

686+
OPENAPI2_OPERATION = 3080000,
687+
OPENAPI2_OPERATION_FIELD_TAGS_TYPE = 3080100,
688+
OPENAPI2_OPERATION_FIELD_SUMMARY_TYPE = 3080200,
689+
OPENAPI2_OPERATION_FIELD_DESCRIPTION_TYPE = 3080300,
690+
OPENAPI2_OPERATION_FIELD_EXTERNAL_DOCS_TYPE = 3080400,
691+
OPENAPI2_OPERATION_FIELD_OPERATION_ID_TYPE = 3080500,
692+
OPENAPI2_OPERATION_FIELD_OPERATION_ID_UNIQUE,
693+
OPENAPI2_OPERATION_FIELD_CONSUMES_TYPE = 3080600,
694+
OPENAPI2_OPERATION_FIELD_PRODUCES_TYPE = 3080700,
695+
OPENAPI2_OPERATION_FIELD_PARAMETERS_TYPE = 3080800,
696+
OPENAPI2_OPERATION_FIELD_PARAMETERS_ITEMS_TYPE = 3080900,
697+
OPENAPI2_OPERATION_FIELD_RESPONSES_TYPE = 3081000,
698+
OPENAPI2_OPERATION_FIELD_RESPONSES_REQUIRED,
699+
OPENAPI2_OPERATION_FIELD_SCHEMES_TYPE = 3081100,
700+
OPENAPI2_OPERATION_FIELD_DEPRECATED_TYPE = 3081200,
701+
OPENAPI2_OPERATION_FIELD_SECURITY_TYPE = 3081300,
702+
OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE,
703+
686704
OPENAPI3_0 = 5000000,
687705

688706
OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
@@ -801,7 +819,7 @@ enum ApilintCodes {
801819
OPENAPI3_0_OPERATION_FIELD_CALLBACKS_VALUES_TYPE = 5130900,
802820
OPENAPI3_0_OPERATION_FIELD_DEPRECATED_TYPE = 5131000,
803821
OPENAPI3_0_OPERATION_FIELD_SECURITY_TYPE = 5131100,
804-
OPENAPI3_0_OPERATION_FIELD_SECURITY_VALUES_TYPE,
822+
OPENAPI3_0_OPERATION_FIELD_SECURITY_ITEMS_TYPE,
805823
OPENAPI3_0_OPERATION_FIELD_SERVERS_TYPE = 5131200,
806824
OPENAPI3_0_OPERATION_FIELD_SERVERS_ITEMS_TYPE,
807825

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

+157-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
CompletionFormat,
44
CompletionType,
55
} from '../../../apidom-language-types';
6-
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
6+
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
77

88
const completion: ApidomCompletionItem[] = [
99
{
@@ -18,7 +18,21 @@ const completion: ApidomCompletionItem[] = [
1818
value:
1919
'[`string`]\n\\\n\\\nA list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.',
2020
},
21-
targetSpecs: OpenAPI3,
21+
targetSpecs: [...OpenAPI2, ...OpenAPI3],
22+
},
23+
{
24+
label: 'summary',
25+
insertText: 'summary',
26+
kind: 14,
27+
format: CompletionFormat.QUOTED,
28+
type: CompletionType.PROPERTY,
29+
insertTextFormat: 2,
30+
documentation: {
31+
kind: 'markdown',
32+
value:
33+
'A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.',
34+
},
35+
targetSpecs: OpenAPI2,
2236
},
2337
{
2438
label: 'summary',
@@ -33,6 +47,20 @@ const completion: ApidomCompletionItem[] = [
3347
},
3448
targetSpecs: OpenAPI3,
3549
},
50+
{
51+
label: 'description',
52+
insertText: 'description',
53+
kind: 14,
54+
format: CompletionFormat.QUOTED,
55+
type: CompletionType.PROPERTY,
56+
insertTextFormat: 2,
57+
documentation: {
58+
kind: 'markdown',
59+
value:
60+
'A verbose explanation of the operation behavior. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.',
61+
},
62+
targetSpecs: OpenAPI2,
63+
},
3664
{
3765
label: 'description',
3866
insertText: 'description',
@@ -47,6 +75,20 @@ const completion: ApidomCompletionItem[] = [
4775
},
4876
targetSpecs: OpenAPI3,
4977
},
78+
{
79+
label: 'externalDocs',
80+
insertText: 'externalDocs',
81+
kind: 14,
82+
format: CompletionFormat.OBJECT,
83+
type: CompletionType.PROPERTY,
84+
insertTextFormat: 2,
85+
documentation: {
86+
kind: 'markdown',
87+
value:
88+
'[External Documentation](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation for this operation.',
89+
},
90+
targetSpecs: OpenAPI2,
91+
},
5092
{
5193
label: 'externalDocs',
5294
insertText: 'externalDocs',
@@ -75,6 +117,20 @@ const completion: ApidomCompletionItem[] = [
75117
},
76118
targetSpecs: OpenAPI31,
77119
},
120+
{
121+
label: 'operationId',
122+
insertText: 'operationId',
123+
kind: 14,
124+
format: CompletionFormat.QUOTED,
125+
type: CompletionType.PROPERTY,
126+
insertTextFormat: 2,
127+
documentation: {
128+
kind: 'markdown',
129+
value:
130+
'Unique string used to identify the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.',
131+
},
132+
targetSpecs: OpenAPI2,
133+
},
78134
{
79135
label: 'operationId',
80136
insertText: 'operationId',
@@ -89,6 +145,48 @@ const completion: ApidomCompletionItem[] = [
89145
},
90146
targetSpecs: OpenAPI3,
91147
},
148+
{
149+
label: 'consumes',
150+
insertText: 'consumes',
151+
kind: 14,
152+
format: CompletionFormat.ARRAY,
153+
type: CompletionType.PROPERTY,
154+
insertTextFormat: 2,
155+
documentation: {
156+
kind: 'markdown',
157+
value:
158+
'[`string`]\n\\\n\\\nA list of MIME types the operation can consume. This overrides the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerConsumes) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).',
159+
},
160+
targetSpecs: OpenAPI2,
161+
},
162+
{
163+
label: 'produces',
164+
insertText: 'produces',
165+
kind: 14,
166+
format: CompletionFormat.ARRAY,
167+
type: CompletionType.PROPERTY,
168+
insertTextFormat: 2,
169+
documentation: {
170+
kind: 'markdown',
171+
value:
172+
'[`string`]\n\\\n\\\nA list of MIME types the operation can produce. This overrides the [`produces`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerProduces) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).',
173+
},
174+
targetSpecs: OpenAPI2,
175+
},
176+
{
177+
label: 'parameters',
178+
insertText: 'parameters',
179+
kind: 14,
180+
format: CompletionFormat.ARRAY,
181+
type: CompletionType.PROPERTY,
182+
insertTextFormat: 2,
183+
documentation: {
184+
kind: 'markdown',
185+
value:
186+
'[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemParameters), the new definition will override it, but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.',
187+
},
188+
targetSpecs: OpenAPI2,
189+
},
92190
{
93191
label: 'parameters',
94192
insertText: 'parameters',
@@ -145,6 +243,20 @@ const completion: ApidomCompletionItem[] = [
145243
},
146244
targetSpecs: OpenAPI31,
147245
},
246+
{
247+
label: 'responses',
248+
insertText: 'responses',
249+
kind: 14,
250+
format: CompletionFormat.OBJECT,
251+
type: CompletionType.PROPERTY,
252+
insertTextFormat: 2,
253+
documentation: {
254+
kind: 'markdown',
255+
value:
256+
'[Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesObject)\n\\\n\\\n**Required.** The list of possible responses as they are returned from executing this operation.',
257+
},
258+
targetSpecs: OpenAPI2,
259+
},
148260
{
149261
label: 'responses',
150262
insertText: 'responses',
@@ -173,6 +285,20 @@ const completion: ApidomCompletionItem[] = [
173285
},
174286
targetSpecs: OpenAPI31,
175287
},
288+
{
289+
label: 'schemes',
290+
insertText: 'schemes',
291+
kind: 14,
292+
format: CompletionFormat.ARRAY,
293+
type: CompletionType.PROPERTY,
294+
insertTextFormat: 2,
295+
documentation: {
296+
kind: 'markdown',
297+
value:
298+
'[`string`]\n\\\n\\\nThe transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the Swagger Object [`schemes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSchemes) definition.',
299+
},
300+
targetSpecs: OpenAPI2,
301+
},
176302
{
177303
label: 'callbacks',
178304
insertText: 'callbacks',
@@ -211,10 +337,38 @@ const completion: ApidomCompletionItem[] = [
211337
documentation: {
212338
kind: 'markdown',
213339
value:
214-
'Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
340+
'`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
341+
},
342+
targetSpecs: OpenAPI2,
343+
},
344+
{
345+
label: 'deprecated',
346+
insertText: 'deprecated',
347+
kind: 14,
348+
format: CompletionFormat.UNQUOTED,
349+
type: CompletionType.PROPERTY,
350+
insertTextFormat: 2,
351+
documentation: {
352+
kind: 'markdown',
353+
value:
354+
'`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
215355
},
216356
targetSpecs: OpenAPI3,
217357
},
358+
{
359+
label: 'security',
360+
insertText: 'security',
361+
kind: 14,
362+
format: CompletionFormat.ARRAY,
363+
type: CompletionType.PROPERTY,
364+
insertTextFormat: 2,
365+
documentation: {
366+
kind: 'markdown',
367+
value:
368+
'[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#serverObject)]\n\\\n\\\nA declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSecurity). To remove a top-level security declaration, an empty array can be used.',
369+
},
370+
targetSpecs: OpenAPI2,
371+
},
218372
{
219373
label: 'security',
220374
insertText: 'security',

0 commit comments

Comments
 (0)