Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ls): provide OpenAPI 3.1.0 lint rules for Security Scheme object #2192

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
tim-lai marked this conversation as resolved.
Show resolved Hide resolved

ADS = 8000000,
ADS_INFO = 8010000,
ADS_INFO_REQUIRED = 8010010,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
tim-lai marked this conversation as resolved.
Show resolved Hide resolved
],
'x-',
],
marker: 'key',
tim-lai marked this conversation as resolved.
Show resolved Hide resolved
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
};

export default allowedFields3_1Lint;
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,6 +17,7 @@ import openIdConnectUrlRequiredLint from './open-id-connect-url--required';

const lints = [
typeEquals3_0Lint,
typeEquals3_1Lint,
descriptionTypeLint,
nameTypeLint,
nameRequiredLint,
Expand All @@ -28,6 +31,7 @@ const lints = [
openIdConnectUrlFormatURILint,
openIdConnectUrlRequiredLint,
allowedFields3_0Lint,
allowedFields3_1Lint,
];

export default lints;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const typeEquals3_0Lint: LinterMeta = {
linterParams: [['apiKey', 'http', 'oauth2', 'openIdConnect']],
marker: 'value',
target: 'type',
targetSpecs: [
tim-lai marked this conversation as resolved.
Show resolved Hide resolved
{ 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;
Original file line number Diff line number Diff line change
@@ -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;