Skip to content

Commit

Permalink
fix(ls): fix linting referenced AsyncAPI 2.x Security Scheme Object (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Aug 5, 2024
1 parent f367183 commit 88368be
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const $refNoSiblingsLint: LinterMeta = {
code: ApilintCodes.ASYNCAPI2_SECURITY_SCHEME_$REF_NO_SIBLINGS,
source: 'apilint',
message: 'All other properties in a "$ref" object are ignored',
severity: DiagnosticSeverity.Warning,
linterFunction: 'allowedFields',
linterParams: [['$ref']],
marker: 'key',
conditions: [
{
function: 'existFields',
params: [['$ref']],
},
],
data: {
quickFix: [
{
message: 'remove $ref',
action: 'removeChild',
functionParams: ['$ref'],
target: 'parent',
},
],
},
};

export default $refNoSiblingsLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const $refValidLint: LinterMeta = {
code: ApilintCodes.ASYNCAPI2_SECURITY_SCHEME_FIELD_$REF_VALID,
source: 'apilint',
message: "'$ref' value must be a valid URI-reference",
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintValidURI',
marker: 'value',
target: '$ref',
data: {},
};

export default $refValidLint;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ const allowedFieldsLint: LinterMeta = {
severity: DiagnosticSeverity.Error,
linterFunction: 'allowedFields',
linterParams: [
['type', 'description', 'name', 'in', 'scheme', 'bearerFormat', 'flows', 'openIdConnectUrl'],
[
'type',
'description',
'name',
'in',
'scheme',
'bearerFormat',
'flows',
'openIdConnectUrl',
'$ref',
],
'x-',
],
marker: 'key',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import flowsTypeLint from './flows--type';
import flowsRequiredLint from './flows--required';
import openIdConnectUrlRequiredLint from './open-id-connect-url--required';
import openIdConnectUrlFormatURILint from './open-id-connect-url--format-uri';
import $refNoSiblingsLint from './$ref--no-siblings';
import $refValidLint from './$ref--valid';

const lints = [
typeRequiredLint,
Expand All @@ -35,6 +37,8 @@ const lints = [
flowsRequiredLint,
openIdConnectUrlRequiredLint,
openIdConnectUrlFormatURILint,
$refNoSiblingsLint,
$refValidLint,
allowedFieldsLint,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const typeRequiredLint: LinterMeta = {
linterFunction: 'hasRequiredField',
linterParams: ['type'],
marker: 'key',
conditions: [
{
function: 'missingField',
params: ['$ref'],
},
],
data: {
quickFix: [
{
Expand Down
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 @@ -377,6 +377,8 @@ enum ApilintCodes {
ASYNCAPI2_SECURITY_SCHEME_FIELD_FLOWS_REQUIRED,
ASYNCAPI2_SECURITY_SCHEME_FIELD_OPEN_ID_CONNECT_URL_TYPE = 270800,
ASYNCAPI2_SECURITY_SCHEME_FIELD_OPEN_ID_CONNECT_URL_REQUIRED,
ASYNCAPI2_SECURITY_SCHEME_FIELD_$REF_VALID = 270900,
ASYNCAPI2_SECURITY_SCHEME_$REF_NO_SIBLINGS,

ASYNCAPI2_OAUTH_FLOWS = 280000,
ASYNCAPI2_OAUTH_FLOWS_FIELD_IMPLICIT_TYPE = 280100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ components:
format: date-time
description: Date and time when the message was sent.
securitySchemes:
test:
$ref: '#/components/securitySchemes/certs'
saslScram:
type: scramSha256
description: Provide your username and password for SASL/SCRAM authentication
Expand Down

0 comments on commit 88368be

Please sign in to comment.