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): add lint rules for OpenAPI 2.0 Schema Object #3706

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum ApilintCodes {
SCHEMA_TYPE_OPENAPI_3_0,
SCHEMA_NULLABLE_NOT_RECOMMENDED,
SCHEMA_MISSING_CORE_FIELDS,
SCHEMA_NULLABLE,

DUPLICATE_KEYS = 14999,
NOT_ALLOWED_FIELDS = 15000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI3 } from '../../../openapi/target-specs';

const $idFormatURILint: LinterMeta = {
code: ApilintCodes.SCHEMA_ID,
Expand All @@ -12,6 +14,7 @@ const $idFormatURILint: LinterMeta = {
marker: 'value',
target: '$id',
data: {},
targetSpecs: [...AsyncAPI2, ...OpenAPI3],
};

export default $idFormatURILint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2 } from '../../../openapi/target-specs';

const $refNoSiblingsLint: LinterMeta = {
code: ApilintCodes.SCHEMA_REF_NOSIBLINGS,
Expand All @@ -11,15 +13,6 @@ const $refNoSiblingsLint: LinterMeta = {
linterFunction: 'allowedFields',
linterParams: [['$ref']],
marker: 'key',
targetSpecs: [
{ namespace: 'asyncapi', version: '2.0.0' },
{ namespace: 'asyncapi', version: '2.1.0' },
{ namespace: 'asyncapi', version: '2.2.0' },
{ namespace: 'asyncapi', version: '2.3.0' },
{ namespace: 'asyncapi', version: '2.4.0' },
{ namespace: 'asyncapi', version: '2.5.0' },
{ namespace: 'asyncapi', version: '2.6.0' },
],
conditions: [
{
function: 'existFields',
Expand All @@ -36,6 +29,7 @@ const $refNoSiblingsLint: LinterMeta = {
},
],
},
targetSpecs: [...AsyncAPI2, ...OpenAPI2],
};

export default $refNoSiblingsLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2, OpenAPI3 } from '../../../openapi/target-specs';

const $refValidLint: LinterMeta = {
code: ApilintCodes.SCHEMA_REF,
Expand All @@ -12,6 +14,7 @@ const $refValidLint: LinterMeta = {
marker: 'value',
target: '$ref',
data: {},
targetSpecs: [...AsyncAPI2, ...OpenAPI2, ...OpenAPI3],
};

export default $refValidLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI3 } from '../../../openapi/target-specs';

const additionalItemsNonArrayLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ADDITIONALITEMS_NONARRAY,
Expand Down Expand Up @@ -30,6 +32,7 @@ const additionalItemsNonArrayLint: LinterMeta = {
},
],
},
targetSpecs: [...AsyncAPI2, ...OpenAPI3],
};

export default additionalItemsNonArrayLint;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI31 } from '../../../openapi/target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const additionalItemsTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
const additionalItemsTypeOpenAPI3_1__AsyncAPI2Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_ADDITIONALITEMS,
source: 'apilint',
message: 'additionalItems must be a schema object or a boolean JSON schema',
Expand All @@ -19,4 +19,4 @@ const additionalItemsTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
targetSpecs: [...OpenAPI31, ...AsyncAPI2],
};

export default additionalItemsTypeOpenAPI3_1_AsyncAPI2Lint;
export default additionalItemsTypeOpenAPI3_1__AsyncAPI2Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2, OpenAPI30 } from '../../../openapi/target-specs';
import { OpenAPI30 } from '../../../openapi/target-specs';

const additionalItemsTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ADDITIONALITEMS,
Expand All @@ -14,7 +14,7 @@ const additionalItemsTypeLint: LinterMeta = {
marker: 'value',
target: 'additionalItems',
data: {},
targetSpecs: [...OpenAPI2, ...OpenAPI30],
targetSpecs: OpenAPI30,
};

export default additionalItemsTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2, OpenAPI3 } from '../../../openapi/target-specs';

const additionalPropertiesNonObjectLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ADDITIONALPROPERTIES_NONOBJECT,
Expand Down Expand Up @@ -30,6 +32,7 @@ const additionalPropertiesNonObjectLint: LinterMeta = {
},
],
},
targetSpecs: [...AsyncAPI2, ...OpenAPI2, ...OpenAPI3],
};

export default additionalPropertiesNonObjectLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2, OpenAPI3 } from '../../../openapi/target-specs';

const additionalPropertiesTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ADDITIONALPROPERTIES,
Expand All @@ -13,6 +15,7 @@ const additionalPropertiesTypeLint: LinterMeta = {
marker: 'value',
target: 'additionalProperties',
data: {},
targetSpecs: [...AsyncAPI2, ...OpenAPI2, ...OpenAPI3],
};

export default additionalPropertiesTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI31 } from '../../../openapi/target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const allOfTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
const allOfTypeOpenAPI3_1__AsyncAPI2Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_ALLOF,
source: 'apilint',
message: 'allOf must be a non-empty array of schema objects or boolean JSON schemas',
Expand All @@ -19,4 +19,4 @@ const allOfTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
targetSpecs: [...OpenAPI31, ...AsyncAPI2],
};

export default allOfTypeOpenAPI3_1_AsyncAPI2Lint;
export default allOfTypeOpenAPI3_1__AsyncAPI2Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI31 } from '../../../openapi/target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const anyOfTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
const anyOfTypeOpenAPI3_1__AsyncAPI2Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_ANYOF,
source: 'apilint',
message: 'anyOf must be a non-empty array of schema objects or boolean JSON schemas',
Expand All @@ -19,4 +19,4 @@ const anyOfTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
targetSpecs: [...OpenAPI31, ...AsyncAPI2],
};

export default anyOfTypeOpenAPI3_1_AsyncAPI2Lint;
export default anyOfTypeOpenAPI3_1__AsyncAPI2Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2, OpenAPI30 } from '../../../openapi/target-specs';
import { OpenAPI30 } from '../../../openapi/target-specs';

const anyOfTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ANYOF,
Expand All @@ -14,7 +14,7 @@ const anyOfTypeLint: LinterMeta = {
marker: 'key',
target: 'anyOf',
data: {},
targetSpecs: [...OpenAPI2, ...OpenAPI30],
targetSpecs: OpenAPI30,
};

export default anyOfTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../../openapi/target-specs';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';

const containsNonArrayLint: LinterMeta = {
code: ApilintCodes.SCHEMA_CONTAINS_NONARRAY,
Expand Down Expand Up @@ -30,6 +32,7 @@ const containsNonArrayLint: LinterMeta = {
},
],
},
targetSpecs: [...AsyncAPI2, ...OpenAPI3],
};

export default containsNonArrayLint;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI31 } from '../../../openapi/target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const containsTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
const containsTypeOpenAPI3_1__AsyncAPI2Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_CONTAINS,
source: 'apilint',
message: 'contains must be a schema object or a boolean JSON schema',
Expand All @@ -19,4 +19,4 @@ const containsTypeOpenAPI3_1_AsyncAPI2Lint: LinterMeta = {
targetSpecs: [...OpenAPI31, ...AsyncAPI2],
};

export default containsTypeOpenAPI3_1_AsyncAPI2Lint;
export default containsTypeOpenAPI3_1__AsyncAPI2Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2, OpenAPI30 } from '../../../openapi/target-specs';
import { OpenAPI30 } from '../../../openapi/target-specs';

const containsTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_CONTAINS,
Expand All @@ -14,7 +14,7 @@ const containsTypeLint: LinterMeta = {
marker: 'value',
target: 'contains',
data: {},
targetSpecs: [...OpenAPI2, ...OpenAPI30],
targetSpecs: OpenAPI30,
};

export default containsTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI3 } from '../../../openapi/target-specs';

const deprecatedTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_READONLY,
Expand All @@ -12,15 +14,7 @@ const deprecatedTypeLint: LinterMeta = {
linterParams: ['boolean'],
marker: 'value',
target: 'deprecated',
targetSpecs: [
{ namespace: 'asyncapi', version: '2.0.0' },
{ namespace: 'asyncapi', version: '2.1.0' },
{ namespace: 'asyncapi', version: '2.2.0' },
{ namespace: 'asyncapi', version: '2.3.0' },
{ namespace: 'asyncapi', version: '2.4.0' },
{ namespace: 'asyncapi', version: '2.5.0' },
{ namespace: 'asyncapi', version: '2.6.0' },
],
targetSpecs: [...AsyncAPI2, ...OpenAPI3],
data: {},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2, OpenAPI3 } from '../../../openapi/target-specs';

const descriptionTypeLint: LinterMeta = {
code: ApilintCodes.SCHEMA_DESCRIPTION,
Expand All @@ -13,6 +15,7 @@ const descriptionTypeLint: LinterMeta = {
marker: 'value',
target: 'description',
data: {},
targetSpecs: [...AsyncAPI2, ...OpenAPI2, ...OpenAPI3],
};

export default descriptionTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';

const discriminatorExistInRequiredLint: LinterMeta = {
code: ApilintCodes.SCHEMA_DISCRIMINATOR_EXIST,
Expand All @@ -11,15 +12,7 @@ const discriminatorExistInRequiredLint: LinterMeta = {
linterFunction: 'apilintDiscriminator',
marker: 'value',
target: 'discriminator',
targetSpecs: [
{ namespace: 'asyncapi', version: '2.0.0' },
{ namespace: 'asyncapi', version: '2.1.0' },
{ namespace: 'asyncapi', version: '2.2.0' },
{ namespace: 'asyncapi', version: '2.3.0' },
{ namespace: 'asyncapi', version: '2.4.0' },
{ namespace: 'asyncapi', version: '2.5.0' },
{ namespace: 'asyncapi', version: '2.6.0' },
],
targetSpecs: AsyncAPI2,
data: {},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI2 } from '../../../openapi/target-specs';

const discriminatorTypeLint: LinterMeta = {
// eslint-disable-next-line @typescript-eslint/naming-convention
const discriminatorTypeOpenAPI2__AsyncAPI2Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_DISCRIMINATOR,
source: 'apilint',
message: "'discriminator' value must be a string",
Expand All @@ -13,15 +16,7 @@ const discriminatorTypeLint: LinterMeta = {
marker: 'value',
target: 'discriminator',
data: {},
targetSpecs: [
{ namespace: 'asyncapi', version: '2.0.0' },
{ namespace: 'asyncapi', version: '2.1.0' },
{ namespace: 'asyncapi', version: '2.2.0' },
{ namespace: 'asyncapi', version: '2.3.0' },
{ namespace: 'asyncapi', version: '2.4.0' },
{ namespace: 'asyncapi', version: '2.5.0' },
{ namespace: 'asyncapi', version: '2.6.0' },
],
targetSpecs: [...AsyncAPI2, ...OpenAPI2],
};

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

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../../openapi/target-specs';

const discriminatorTypeOpenAPI3Lint: LinterMeta = {
code: ApilintCodes.SCHEMA_DISCRIMINATOR,
source: 'apilint',
message: "'discriminator' value must be an object",
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintType',
linterParams: ['discriminator'],
marker: 'value',
target: 'discriminator',
data: {},
targetSpecs: OpenAPI3,
};

export default discriminatorTypeOpenAPI3Lint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { AsyncAPI2 } from '../../../asyncapi/target-specs';
import { OpenAPI31 } from '../../../openapi/target-specs';

const elseNonIfLint: LinterMeta = {
code: ApilintCodes.SCHEMA_ELSE_NONIF,
Expand All @@ -28,6 +30,7 @@ const elseNonIfLint: LinterMeta = {
},
],
},
targetSpecs: [...AsyncAPI2, ...OpenAPI31],
};

export default elseNonIfLint;
Loading