From 6a458a7bfe26a02e7ee95af7553d9742311e8912 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 25 Oct 2022 14:09:06 -0700 Subject: [PATCH 1/3] feat(ls): provide OpenAPI 3.1.0 lint rules for Security Scheme object --- packages/apidom-ls/src/config/codes.ts | 2 ++ .../openapi/security-scheme/completion.ts | 28 ++++++++++++++++++ .../lint/allowed-fields-3-1.ts | 29 +++++++++++++++++++ .../openapi/security-scheme/lint/index.ts | 4 +++ .../security-scheme/lint/type--equals-3-0.ts | 6 ++++ .../security-scheme/lint/type--equals-3-1.ts | 17 +++++++++++ 6 files changed, 86 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts create mode 100644 packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-1.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index bd31e6e8f6..4e16493dc4 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -848,6 +848,8 @@ enum ApilintCodes { OPENAPI3_1_REFERENCE = 7040000, OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS = 7040100, + OPENAPI3_1_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 7240100, + ADS = 8000000, ADS_INFO = 8010000, ADS_INFO_REQUIRED = 8010010, diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/completion.ts b/packages/apidom-ls/src/config/openapi/security-scheme/completion.ts index 3c9ca8af7c..5df249cd7a 100644 --- a/packages/apidom-ls/src/config/openapi/security-scheme/completion.ts +++ b/packages/apidom-ls/src/config/openapi/security-scheme/completion.ts @@ -24,6 +24,20 @@ const completion: ApidomCompletionItem[] = [ { namespace: 'openapi', version: '3.0.3' }, ], }, + { + 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 `"apiKey"`, `"http"`, `"mutualTLS"`, `"oauth2"`, `"openIdConnect"`.', + }, + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], + }, { label: 'description', insertText: 'description', @@ -108,6 +122,20 @@ const completion: ApidomCompletionItem[] = [ { namespace: 'openapi', version: '3.0.3' }, ], }, + { + label: 'flows', + insertText: 'flows', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[OAuth Flows Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowsObject)\n\\\nApplies to `oauth2`. **REQUIRED**. An object containing configuration information for the flow types supported.', + }, + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], + }, { label: 'openIdConnectUrl', insertText: 'openIdConnectUrl', diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts new file mode 100644 index 0000000000..ce337e2af3 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts @@ -0,0 +1,29 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_1Lint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: 1, + linterFunction: 'allowedFields', + linterParams: [ + [ + 'type', + 'description', + 'name', + 'in', + 'scheme', + 'bearerFormat', + 'flows', + 'openIdConnectUrl', + '$ref', + ], + 'x-', + ], + marker: 'key', + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default allowedFields3_1Lint; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts index 2266219c12..1f1097da60 100644 --- a/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/index.ts @@ -1,5 +1,7 @@ import allowedFields3_0Lint from './allowed-fields-3-0'; +import allowedFields3_1Lint from './allowed-fields-3-1'; import typeEquals3_0Lint from './type--equals-3-0'; +import typeEquals3_1Lint from './type--equals-3-1'; import descriptionTypeLint from './description--type'; import nameTypeLint from './name--type'; import nameRequiredLint from './name--required'; @@ -15,6 +17,7 @@ import openIdConnectUrlRequiredLint from './open-id-connect-url--required'; const lints = [ typeEquals3_0Lint, + typeEquals3_1Lint, descriptionTypeLint, nameTypeLint, nameRequiredLint, @@ -28,6 +31,7 @@ const lints = [ openIdConnectUrlFormatURILint, openIdConnectUrlRequiredLint, allowedFields3_0Lint, + allowedFields3_1Lint, ]; export default lints; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-0.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-0.ts index b93d06cbbf..99b1034670 100644 --- a/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-0.ts +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-0.ts @@ -11,6 +11,12 @@ const typeEquals3_0Lint: LinterMeta = { linterParams: [['apiKey', 'http', 'oauth2', 'openIdConnect']], marker: 'value', target: 'type', + targetSpecs: [ + { namespace: 'openapi', version: '3.0.0' }, + { namespace: 'openapi', version: '3.0.1' }, + { namespace: 'openapi', version: '3.0.2' }, + { namespace: 'openapi', version: '3.0.3' }, + ], }; export default typeEquals3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-1.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-1.ts new file mode 100644 index 0000000000..f133b0a193 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/type--equals-3-1.ts @@ -0,0 +1,17 @@ +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const typeEquals3_1Lint: LinterMeta = { + code: ApilintCodes.OPENAPI3_1_SECURITY_SCHEME_FIELD_TYPE_EQUALS, + source: 'apilint', + message: 'type must be one of allowed values', + severity: 1, + linterFunction: 'apilintValueOrArray', + linterParams: [['apiKey', 'http', 'mutualTLS', 'oauth2', 'openIdConnect']], + marker: 'value', + target: 'type', + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], +}; + +export default typeEquals3_1Lint; From 9f462711b7ca1847c58600be5f09671ad241cb32 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 26 Oct 2022 10:25:29 -0700 Subject: [PATCH 2/3] feat(ls): OpenAPI3.1.0 security scheme consistency with rule --- .../security-scheme/lint/allowed-fields-3-1.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts index ce337e2af3..22b86b178c 100644 --- a/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts +++ b/packages/apidom-ls/src/config/openapi/security-scheme/lint/allowed-fields-3-1.ts @@ -9,20 +9,16 @@ const allowedFields3_1Lint: LinterMeta = { severity: 1, linterFunction: 'allowedFields', linterParams: [ - [ - 'type', - 'description', - 'name', - 'in', - 'scheme', - 'bearerFormat', - 'flows', - 'openIdConnectUrl', - '$ref', - ], + ['type', 'description', 'name', 'in', 'scheme', 'bearerFormat', 'flows', 'openIdConnectUrl'], 'x-', ], marker: 'key', + conditions: [ + { + function: 'missingField', + params: ['$ref'], + }, + ], targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], }; From 62f902608ec1bf63706035dfd1ba824ddc4bb276 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Wed, 26 Oct 2022 10:34:23 -0700 Subject: [PATCH 3/3] refactor(ls): update codes for OpenApi 3.1.0 security scheme --- packages/apidom-ls/src/config/codes.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 4e16493dc4..1c415e3274 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -848,7 +848,8 @@ enum ApilintCodes { OPENAPI3_1_REFERENCE = 7040000, OPENAPI3_1_REFERENCE_FIELD_$REF_ALLOWED_SIBLINGS = 7040100, - OPENAPI3_1_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 7240100, + OPENAPI3_1_SECURITY_SCHEME = 7050000, + OPENAPI3_1_SECURITY_SCHEME_FIELD_TYPE_EQUALS = 7050100, ADS = 8000000, ADS_INFO = 8010000,