Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Security Scheme Object (#3670)
Browse files Browse the repository at this point in the history
Refs #3619
  • Loading branch information
char0n committed Jan 12, 2024
1 parent 37e773f commit e8ba3bc
Show file tree
Hide file tree
Showing 20 changed files with 575 additions and 35 deletions.
16 changes: 16 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Expand Up @@ -794,6 +794,22 @@ enum ApilintCodes {
OPENAPI2_SECURITY_REQUIREMENT = 3210000,
OPENAPI2_SECURITY_REQUIREMENT_KEYS_DEFINED,

OPENAPI2_SECURITY_SCHEME = 3220000,
OPENAPI2_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 3220100,
OPENAPI2_SECURITY_SCHEME_FIELD_DESCRIPTION_TYPE = 3220200,
OPENAPI2_SECURITY_SCHEME_FIELD_NAME_TYPE = 3220300,
OPENAPI2_SECURITY_SCHEME_FIELD_NAME_REQUIRED,
OPENAPI2_SECURITY_SCHEME_FIELD_IN_EQUALS = 3220400,
OPENAPI2_SECURITY_SCHEME_FIELD_IN_REQUIRED,
OPENAPI2_SECURITY_SCHEME_FIELD_FLOW_EQUALS = 3220500,
OPENAPI2_SECURITY_SCHEME_FIELD_FLOW_REQUIRED,
OPENAPI2_SECURITY_SCHEME_FIELD_AUTHORIZATION_URL_FORMAT_URI = 3220600,
OPENAPI2_SECURITY_SCHEME_FIELD_AUTHORIZATION_URL_REQUIRED,
OPENAPI2_SECURITY_SCHEME_FIELD_TOKEN_URL_FORMAT_URI = 3220700,
OPENAPI2_SECURITY_SCHEME_FIELD_TOKEN_URL_REQUIRED,
OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_TYPE = 3220800,
OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_REQUIRED,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
181 changes: 171 additions & 10 deletions packages/apidom-ls/src/config/openapi/security-scheme/completion.ts
Expand Up @@ -3,7 +3,7 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
Expand All @@ -17,7 +17,21 @@ const completion: ApidomCompletionItem[] = [
kind: 'markdown',
value: 'A reference to a Security Scheme.',
},
targetSpecs: OpenAPI3,
targetSpecs: OpenAPI2,
},
{
label: 'type',
insertText: 'type',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required.** The type of the security scheme. Valid values are `"basic"`, `"apiKey"` or `"oauth2"`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'type',
Expand Down Expand Up @@ -47,6 +61,19 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'description',
insertText: 'description',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: 'A short description for security scheme.',
},
targetSpecs: OpenAPI2,
},
{
label: 'description',
insertText: 'description',
Expand All @@ -71,7 +98,21 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
'Valid for `apiKey`. **Required**. The name of the header or query parameter to be used.',
},
targetSpecs: OpenAPI3,
},
{
label: 'name',
insertText: 'name',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Applies to `apiKey`. **REQUIRED**. The name of the header, query or cookie parameter to be used.',
},
targetSpecs: OpenAPI3,
},
Expand All @@ -85,7 +126,21 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'**REQUIRED**. Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
'Valid for `apiKey`. **Required**. The location of the API key. Valid values are `"query"` or `"header"`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'in',
insertText: 'in',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Applies to `apiKey`. **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.',
},
targetSpecs: OpenAPI3,
},
Expand Down Expand Up @@ -117,6 +172,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'flow',
insertText: 'flow',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Valid for `oauth2`. **Required**. The flow used by the OAuth2 security scheme. Valid values are `"implicit"`, `"password"`, `"application"` or `"accessCode"`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'flows',
insertText: 'flows',
Expand Down Expand Up @@ -145,6 +214,34 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'authorizationUrl',
insertText: 'authorizationUrl',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Valid for oauth2 (`"implicit"`, `"accessCode"`). **Required**. The authorization URL to be used for this flow. This SHOULD be in the form of a URL.',
},
targetSpecs: OpenAPI2,
},
{
label: 'tokenUrl',
insertText: 'tokenUrl',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'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.',
},
targetSpecs: OpenAPI2,
},
{
label: 'openIdConnectUrl',
insertText: 'openIdConnectUrl',
Expand All @@ -155,7 +252,7 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'**REQUIRED**. Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
'Applies to `openIdConnect`. **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.',
},
targetSpecs: OpenAPI30,
},
Expand All @@ -169,10 +266,34 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'**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.',
'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.',
},
targetSpecs: OpenAPI31,
},
{
label: 'scopes',
insertText: 'scopes',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[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.',
},
targetSpecs: OpenAPI2,
},
{
target: 'type',
label: 'basic',
insertText: 'basic',
kind: 12,
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI2,
},
{
target: 'type',
label: 'apiKey',
Expand All @@ -181,7 +302,7 @@ const completion: ApidomCompletionItem[] = [
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
target: 'type',
Expand All @@ -201,7 +322,7 @@ const completion: ApidomCompletionItem[] = [
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
target: 'type',
Expand All @@ -221,7 +342,7 @@ const completion: ApidomCompletionItem[] = [
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
target: 'in',
Expand All @@ -231,7 +352,7 @@ const completion: ApidomCompletionItem[] = [
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
target: 'in',
Expand All @@ -243,6 +364,46 @@ const completion: ApidomCompletionItem[] = [
insertTextFormat: 2,
targetSpecs: OpenAPI3,
},
{
target: 'flow',
label: 'implicit',
insertText: 'implicit',
kind: 12,
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI2,
},
{
target: 'flow',
label: 'password',
insertText: 'password',
kind: 12,
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI2,
},
{
target: 'flow',
label: 'application',
insertText: 'application',
kind: 12,
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI2,
},
{
target: 'flow',
label: 'accessCode',
insertText: 'accessCode',
kind: 12,
format: CompletionFormat.QUOTED,
type: CompletionType.VALUE,
insertTextFormat: 2,
targetSpecs: OpenAPI2,
},
];

export default completion;

0 comments on commit e8ba3bc

Please sign in to comment.