Skip to content

Commit 1eb3259

Browse files
committed
feat(ls): provide OpenAPI 3.0.x Security Scheme completion rules
Refs #2032
1 parent f383838 commit 1eb3259

File tree

3 files changed

+225
-4
lines changed

3 files changed

+225
-4
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
import {
2+
ApidomCompletionItem,
3+
CompletionFormat,
4+
CompletionType,
5+
} from '../../../apidom-language-types';
6+
7+
const completion: ApidomCompletionItem[] = [
8+
{
9+
label: 'type',
10+
insertText: 'type',
11+
kind: 14,
12+
format: CompletionFormat.QUOTED,
13+
type: CompletionType.PROPERTY,
14+
insertTextFormat: 2,
15+
documentation: {
16+
kind: 'markdown',
17+
value:
18+
'**REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`.',
19+
},
20+
targetSpecs: [
21+
{ namespace: 'openapi', version: '3.0.0' },
22+
{ namespace: 'openapi', version: '3.0.1' },
23+
{ namespace: 'openapi', version: '3.0.2' },
24+
{ namespace: 'openapi', version: '3.0.3' },
25+
],
26+
},
27+
{
28+
label: 'description',
29+
insertText: 'description',
30+
kind: 14,
31+
format: CompletionFormat.QUOTED,
32+
type: CompletionType.PROPERTY,
33+
insertTextFormat: 2,
34+
documentation: {
35+
kind: 'markdown',
36+
value:
37+
'A description for security scheme. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
38+
},
39+
},
40+
{
41+
label: 'name',
42+
insertText: 'name',
43+
kind: 14,
44+
format: CompletionFormat.QUOTED,
45+
type: CompletionType.PROPERTY,
46+
insertTextFormat: 2,
47+
documentation: {
48+
kind: 'markdown',
49+
value:
50+
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
51+
},
52+
},
53+
{
54+
label: 'in',
55+
insertText: 'in',
56+
kind: 14,
57+
format: CompletionFormat.QUOTED,
58+
type: CompletionType.PROPERTY,
59+
insertTextFormat: 2,
60+
documentation: {
61+
kind: 'markdown',
62+
value:
63+
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
64+
},
65+
},
66+
{
67+
label: 'scheme',
68+
insertText: 'scheme',
69+
kind: 14,
70+
format: CompletionFormat.QUOTED,
71+
type: CompletionType.PROPERTY,
72+
insertTextFormat: 2,
73+
documentation: {
74+
kind: 'markdown',
75+
value:
76+
'**REQUIRED**. Applies to `http`. **REQUIRED**. The name of the HTTP Authorization scheme to be used in the [Authorization header as defined in RFC7235](https://tools.ietf.org/html/rfc7235#section-5.1). The values used SHOULD be registered in the [IANA Authentication Scheme registry](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml).',
77+
},
78+
},
79+
{
80+
label: 'bearerFormat',
81+
insertText: 'bearerFormat',
82+
kind: 14,
83+
format: CompletionFormat.QUOTED,
84+
type: CompletionType.PROPERTY,
85+
insertTextFormat: 2,
86+
documentation: {
87+
kind: 'markdown',
88+
value:
89+
'Applies to `http` (`"bearer"`). A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes.',
90+
},
91+
},
92+
{
93+
label: 'flows',
94+
insertText: 'flows',
95+
kind: 14,
96+
format: CompletionFormat.OBJECT,
97+
type: CompletionType.PROPERTY,
98+
insertTextFormat: 2,
99+
documentation: {
100+
kind: 'markdown',
101+
value:
102+
'#### [OAuth Flows Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowsObject)\\n\\nApplies to `oauth2`. **REQUIRED**. An object containing configuration information for the flow types supported.',
103+
},
104+
targetSpecs: [
105+
{ namespace: 'openapi', version: '3.0.0' },
106+
{ namespace: 'openapi', version: '3.0.1' },
107+
{ namespace: 'openapi', version: '3.0.2' },
108+
{ namespace: 'openapi', version: '3.0.3' },
109+
],
110+
},
111+
{
112+
label: 'openIdConnectUrl',
113+
insertText: 'openIdConnectUrl',
114+
kind: 14,
115+
format: CompletionFormat.QUOTED,
116+
type: CompletionType.PROPERTY,
117+
insertTextFormat: 2,
118+
documentation: {
119+
kind: 'markdown',
120+
value:
121+
'**REQUIRED**. Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
122+
},
123+
targetSpecs: [
124+
{ namespace: 'openapi', version: '3.0.0' },
125+
{ namespace: 'openapi', version: '3.0.1' },
126+
{ namespace: 'openapi', version: '3.0.2' },
127+
{ namespace: 'openapi', version: '3.0.3' },
128+
],
129+
},
130+
{
131+
label: 'openIdConnectUrl',
132+
insertText: 'openIdConnectUrl',
133+
kind: 14,
134+
format: CompletionFormat.QUOTED,
135+
type: CompletionType.PROPERTY,
136+
insertTextFormat: 2,
137+
documentation: {
138+
kind: 'markdown',
139+
value:
140+
'**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.',
141+
},
142+
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
143+
},
144+
{
145+
target: 'type',
146+
label: 'apiKey',
147+
insertText: 'apiKey',
148+
kind: 12,
149+
format: CompletionFormat.QUOTED,
150+
type: CompletionType.VALUE,
151+
insertTextFormat: 2,
152+
},
153+
{
154+
target: 'type',
155+
label: 'http',
156+
insertText: 'http',
157+
kind: 12,
158+
format: CompletionFormat.QUOTED,
159+
type: CompletionType.VALUE,
160+
insertTextFormat: 2,
161+
},
162+
{
163+
target: 'type',
164+
label: 'oauth2',
165+
insertText: 'oauth2',
166+
kind: 12,
167+
format: CompletionFormat.QUOTED,
168+
type: CompletionType.VALUE,
169+
insertTextFormat: 2,
170+
},
171+
{
172+
target: 'type',
173+
label: 'openIdConnect',
174+
insertText: 'openIdConnect',
175+
kind: 12,
176+
format: CompletionFormat.QUOTED,
177+
type: CompletionType.VALUE,
178+
insertTextFormat: 2,
179+
},
180+
{
181+
target: 'in',
182+
label: 'query',
183+
insertText: 'query',
184+
kind: 12,
185+
format: CompletionFormat.QUOTED,
186+
type: CompletionType.VALUE,
187+
insertTextFormat: 2,
188+
},
189+
{
190+
target: 'in',
191+
label: 'header',
192+
insertText: 'header',
193+
kind: 12,
194+
format: CompletionFormat.QUOTED,
195+
type: CompletionType.VALUE,
196+
insertTextFormat: 2,
197+
},
198+
{
199+
target: 'in',
200+
label: 'cookie',
201+
insertText: 'cookie',
202+
kind: 12,
203+
format: CompletionFormat.QUOTED,
204+
type: CompletionType.VALUE,
205+
insertTextFormat: 2,
206+
},
207+
];
208+
209+
export default completion;

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ const documentation = [
2020
},
2121
{
2222
target: 'name',
23-
docs: 'Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
23+
docs: '**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
2424
},
2525
{
2626
target: 'in',
27-
docs: 'Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
27+
docs: '**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
2828
},
2929
{
3030
target: 'scheme',
31-
docs: 'Applies to `http`. **REQUIRED**. The name of the HTTP Authorization scheme to be used in the [Authorization header as defined in RFC7235](https://tools.ietf.org/html/rfc7235#section-5.1). The values used SHOULD be registered in the [IANA Authentication Scheme registry](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml).',
31+
docs: '**REQUIRED**. Applies to `http`. **REQUIRED**. The name of the HTTP Authorization scheme to be used in the [Authorization header as defined in RFC7235](https://tools.ietf.org/html/rfc7235#section-5.1). The values used SHOULD be registered in the [IANA Authentication Scheme registry](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml).',
3232
},
3333
{
3434
target: 'bearerFormat',
@@ -51,7 +51,17 @@ const documentation = [
5151
},
5252
{
5353
target: 'openIdConnectUrl',
54-
docs: '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.',
54+
docs: '**REQUIRED**. Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
55+
targetSpecs: [
56+
{ namespace: 'openapi', version: '3.0.0' },
57+
{ namespace: 'openapi', version: '3.0.1' },
58+
{ namespace: 'openapi', version: '3.0.2' },
59+
{ namespace: 'openapi', version: '3.0.3' },
60+
],
61+
},
62+
{
63+
target: 'openIdConnectUrl',
64+
docs: '**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.',
5565
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
5666
},
5767
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import completion from './completion';
12
import documentation from './documentation';
23
import { FormatMeta } from '../../../apidom-language-types';
34

45
const meta: FormatMeta = {
6+
completion,
57
documentation,
68
};
79

0 commit comments

Comments
 (0)