Skip to content

Commit e8ba3bc

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 Security Scheme Object (#3670)
Refs #3619
1 parent 37e773f commit e8ba3bc

20 files changed

+575
-35
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@ enum ApilintCodes {
794794
OPENAPI2_SECURITY_REQUIREMENT = 3210000,
795795
OPENAPI2_SECURITY_REQUIREMENT_KEYS_DEFINED,
796796

797+
OPENAPI2_SECURITY_SCHEME = 3220000,
798+
OPENAPI2_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 3220100,
799+
OPENAPI2_SECURITY_SCHEME_FIELD_DESCRIPTION_TYPE = 3220200,
800+
OPENAPI2_SECURITY_SCHEME_FIELD_NAME_TYPE = 3220300,
801+
OPENAPI2_SECURITY_SCHEME_FIELD_NAME_REQUIRED,
802+
OPENAPI2_SECURITY_SCHEME_FIELD_IN_EQUALS = 3220400,
803+
OPENAPI2_SECURITY_SCHEME_FIELD_IN_REQUIRED,
804+
OPENAPI2_SECURITY_SCHEME_FIELD_FLOW_EQUALS = 3220500,
805+
OPENAPI2_SECURITY_SCHEME_FIELD_FLOW_REQUIRED,
806+
OPENAPI2_SECURITY_SCHEME_FIELD_AUTHORIZATION_URL_FORMAT_URI = 3220600,
807+
OPENAPI2_SECURITY_SCHEME_FIELD_AUTHORIZATION_URL_REQUIRED,
808+
OPENAPI2_SECURITY_SCHEME_FIELD_TOKEN_URL_FORMAT_URI = 3220700,
809+
OPENAPI2_SECURITY_SCHEME_FIELD_TOKEN_URL_REQUIRED,
810+
OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_TYPE = 3220800,
811+
OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_REQUIRED,
812+
797813
OPENAPI3_0 = 5000000,
798814

799815
OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,

packages/apidom-ls/src/config/openapi/security-scheme/completion.ts

+171-10
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
{
@@ -17,7 +17,21 @@ const completion: ApidomCompletionItem[] = [
1717
kind: 'markdown',
1818
value: 'A reference to a Security Scheme.',
1919
},
20-
targetSpecs: OpenAPI3,
20+
targetSpecs: OpenAPI2,
21+
},
22+
{
23+
label: 'type',
24+
insertText: 'type',
25+
kind: 14,
26+
format: CompletionFormat.QUOTED,
27+
type: CompletionType.PROPERTY,
28+
insertTextFormat: 2,
29+
documentation: {
30+
kind: 'markdown',
31+
value:
32+
'**Required.** The type of the security scheme. Valid values are `"basic"`, `"apiKey"` or `"oauth2"`.',
33+
},
34+
targetSpecs: OpenAPI2,
2135
},
2236
{
2337
label: 'type',
@@ -47,6 +61,19 @@ const completion: ApidomCompletionItem[] = [
4761
},
4862
targetSpecs: OpenAPI31,
4963
},
64+
{
65+
label: 'description',
66+
insertText: 'description',
67+
kind: 14,
68+
format: CompletionFormat.QUOTED,
69+
type: CompletionType.PROPERTY,
70+
insertTextFormat: 2,
71+
documentation: {
72+
kind: 'markdown',
73+
value: 'A short description for security scheme.',
74+
},
75+
targetSpecs: OpenAPI2,
76+
},
5077
{
5178
label: 'description',
5279
insertText: 'description',
@@ -71,7 +98,21 @@ const completion: ApidomCompletionItem[] = [
7198
documentation: {
7299
kind: 'markdown',
73100
value:
74-
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
101+
'Valid for `apiKey`. **Required**. The name of the header or query parameter to be used.',
102+
},
103+
targetSpecs: OpenAPI3,
104+
},
105+
{
106+
label: 'name',
107+
insertText: 'name',
108+
kind: 14,
109+
format: CompletionFormat.QUOTED,
110+
type: CompletionType.PROPERTY,
111+
insertTextFormat: 2,
112+
documentation: {
113+
kind: 'markdown',
114+
value:
115+
'Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
75116
},
76117
targetSpecs: OpenAPI3,
77118
},
@@ -85,7 +126,21 @@ const completion: ApidomCompletionItem[] = [
85126
documentation: {
86127
kind: 'markdown',
87128
value:
88-
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
129+
'Valid for `apiKey`. **Required**. The location of the API key. Valid values are `"query"` or `"header"`.',
130+
},
131+
targetSpecs: OpenAPI2,
132+
},
133+
{
134+
label: 'in',
135+
insertText: 'in',
136+
kind: 14,
137+
format: CompletionFormat.QUOTED,
138+
type: CompletionType.PROPERTY,
139+
insertTextFormat: 2,
140+
documentation: {
141+
kind: 'markdown',
142+
value:
143+
'Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
89144
},
90145
targetSpecs: OpenAPI3,
91146
},
@@ -117,6 +172,20 @@ const completion: ApidomCompletionItem[] = [
117172
},
118173
targetSpecs: OpenAPI3,
119174
},
175+
{
176+
label: 'flow',
177+
insertText: 'flow',
178+
kind: 14,
179+
format: CompletionFormat.QUOTED,
180+
type: CompletionType.PROPERTY,
181+
insertTextFormat: 2,
182+
documentation: {
183+
kind: 'markdown',
184+
value:
185+
'Valid for `oauth2`. **Required**. The flow used by the OAuth2 security scheme. Valid values are `"implicit"`, `"password"`, `"application"` or `"accessCode"`.',
186+
},
187+
targetSpecs: OpenAPI2,
188+
},
120189
{
121190
label: 'flows',
122191
insertText: 'flows',
@@ -145,6 +214,34 @@ const completion: ApidomCompletionItem[] = [
145214
},
146215
targetSpecs: OpenAPI31,
147216
},
217+
{
218+
label: 'authorizationUrl',
219+
insertText: 'authorizationUrl',
220+
kind: 14,
221+
format: CompletionFormat.QUOTED,
222+
type: CompletionType.PROPERTY,
223+
insertTextFormat: 2,
224+
documentation: {
225+
kind: 'markdown',
226+
value:
227+
'Valid for oauth2 (`"implicit"`, `"accessCode"`). **Required**. The authorization URL to be used for this flow. This SHOULD be in the form of a URL.',
228+
},
229+
targetSpecs: OpenAPI2,
230+
},
231+
{
232+
label: 'tokenUrl',
233+
insertText: 'tokenUrl',
234+
kind: 14,
235+
format: CompletionFormat.QUOTED,
236+
type: CompletionType.PROPERTY,
237+
insertTextFormat: 2,
238+
documentation: {
239+
kind: 'markdown',
240+
value:
241+
'Valid for oauth2 (`"password"`, `"application"`, `"accessCode"`). **Required**. The token URL to be used for this flow. This SHOULD be in the form of a URL.',
242+
},
243+
targetSpecs: OpenAPI2,
244+
},
148245
{
149246
label: 'openIdConnectUrl',
150247
insertText: 'openIdConnectUrl',
@@ -155,7 +252,7 @@ const completion: ApidomCompletionItem[] = [
155252
documentation: {
156253
kind: 'markdown',
157254
value:
158-
'**REQUIRED**. Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
255+
'Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
159256
},
160257
targetSpecs: OpenAPI30,
161258
},
@@ -169,10 +266,34 @@ const completion: ApidomCompletionItem[] = [
169266
documentation: {
170267
kind: 'markdown',
171268
value:
172-
'**REQUIRED**. Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL. The OpenID Connect standard requires the use of TLS.',
269+
'Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL. The OpenID Connect standard requires the use of TLS.',
173270
},
174271
targetSpecs: OpenAPI31,
175272
},
273+
{
274+
label: 'scopes',
275+
insertText: 'scopes',
276+
kind: 14,
277+
format: CompletionFormat.OBJECT,
278+
type: CompletionType.PROPERTY,
279+
insertTextFormat: 2,
280+
documentation: {
281+
kind: 'markdown',
282+
value:
283+
'[Scopes Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#scopes-object)\n\\\n\\\nValid for `oauth2`. **Required**. The available scopes for the OAuth2 security scheme.',
284+
},
285+
targetSpecs: OpenAPI2,
286+
},
287+
{
288+
target: 'type',
289+
label: 'basic',
290+
insertText: 'basic',
291+
kind: 12,
292+
format: CompletionFormat.QUOTED,
293+
type: CompletionType.VALUE,
294+
insertTextFormat: 2,
295+
targetSpecs: OpenAPI2,
296+
},
176297
{
177298
target: 'type',
178299
label: 'apiKey',
@@ -181,7 +302,7 @@ const completion: ApidomCompletionItem[] = [
181302
format: CompletionFormat.QUOTED,
182303
type: CompletionType.VALUE,
183304
insertTextFormat: 2,
184-
targetSpecs: OpenAPI3,
305+
targetSpecs: [...OpenAPI2, ...OpenAPI3],
185306
},
186307
{
187308
target: 'type',
@@ -201,7 +322,7 @@ const completion: ApidomCompletionItem[] = [
201322
format: CompletionFormat.QUOTED,
202323
type: CompletionType.VALUE,
203324
insertTextFormat: 2,
204-
targetSpecs: OpenAPI3,
325+
targetSpecs: [...OpenAPI2, ...OpenAPI3],
205326
},
206327
{
207328
target: 'type',
@@ -221,7 +342,7 @@ const completion: ApidomCompletionItem[] = [
221342
format: CompletionFormat.QUOTED,
222343
type: CompletionType.VALUE,
223344
insertTextFormat: 2,
224-
targetSpecs: OpenAPI3,
345+
targetSpecs: [...OpenAPI2, ...OpenAPI3],
225346
},
226347
{
227348
target: 'in',
@@ -231,7 +352,7 @@ const completion: ApidomCompletionItem[] = [
231352
format: CompletionFormat.QUOTED,
232353
type: CompletionType.VALUE,
233354
insertTextFormat: 2,
234-
targetSpecs: OpenAPI3,
355+
targetSpecs: [...OpenAPI2, ...OpenAPI3],
235356
},
236357
{
237358
target: 'in',
@@ -243,6 +364,46 @@ const completion: ApidomCompletionItem[] = [
243364
insertTextFormat: 2,
244365
targetSpecs: OpenAPI3,
245366
},
367+
{
368+
target: 'flow',
369+
label: 'implicit',
370+
insertText: 'implicit',
371+
kind: 12,
372+
format: CompletionFormat.QUOTED,
373+
type: CompletionType.VALUE,
374+
insertTextFormat: 2,
375+
targetSpecs: OpenAPI2,
376+
},
377+
{
378+
target: 'flow',
379+
label: 'password',
380+
insertText: 'password',
381+
kind: 12,
382+
format: CompletionFormat.QUOTED,
383+
type: CompletionType.VALUE,
384+
insertTextFormat: 2,
385+
targetSpecs: OpenAPI2,
386+
},
387+
{
388+
target: 'flow',
389+
label: 'application',
390+
insertText: 'application',
391+
kind: 12,
392+
format: CompletionFormat.QUOTED,
393+
type: CompletionType.VALUE,
394+
insertTextFormat: 2,
395+
targetSpecs: OpenAPI2,
396+
},
397+
{
398+
target: 'flow',
399+
label: 'accessCode',
400+
insertText: 'accessCode',
401+
kind: 12,
402+
format: CompletionFormat.QUOTED,
403+
type: CompletionType.VALUE,
404+
insertTextFormat: 2,
405+
targetSpecs: OpenAPI2,
406+
},
246407
];
247408

248409
export default completion;

0 commit comments

Comments
 (0)