diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index e9fb3d95e4..f84c4a740d 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -63,6 +63,7 @@ enum ApilintCodes { SCHEMA_WRITEONLY, SCHEMA_EXAMPLES, SCHEMA_EXTERNAL_DOCS, + SCHEMA_EXAMPLE_DEPRECATED, DUPLICATE_KEYS = 14999, NOT_ALLOWED_FIELDS = 15000, diff --git a/packages/apidom-ls/src/config/common/schema/lint/index.ts b/packages/apidom-ls/src/config/common/schema/lint/index.ts index 76982f93f2..a399f5b7cf 100644 --- a/packages/apidom-ls/src/config/common/schema/lint/index.ts +++ b/packages/apidom-ls/src/config/common/schema/lint/index.ts @@ -59,6 +59,7 @@ import typeTypeLint from './type--type'; import uniqueItemsNonArrayLint from './unique-items--non-array'; import uniqueItemsTypeLint from './unique-items--type'; import writeOnlyTypeLint from './write-only--type'; +import exampleDeprecatedLint from '../../../openapi/components/lint/example--deprecated'; const schemaLints = [ $idFormatURILint, @@ -122,6 +123,7 @@ const schemaLints = [ uniqueItemsNonArrayLint, uniqueItemsTypeLint, writeOnlyTypeLint, + exampleDeprecatedLint, ]; export default schemaLints; diff --git a/packages/apidom-ls/src/config/openapi/components/lint/example--deprecated.ts b/packages/apidom-ls/src/config/openapi/components/lint/example--deprecated.ts new file mode 100644 index 0000000000..709e4e20d0 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/components/lint/example--deprecated.ts @@ -0,0 +1,34 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; + +const exampleDeprecatedLint: LinterMeta = { + code: ApilintCodes.SCHEMA_EXAMPLE_DEPRECATED, + source: 'apilint', + message: 'property "example" is deprecated, use "examples" instead', + severity: DiagnosticSeverity.Warning, + linterFunction: 'missingField', + linterParams: ['example'], + marker: 'key', + markerTarget: 'example', + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], + data: { + quickFix: [ + { + message: 'remove example', + action: 'removeChild', + functionParams: ['example'], + target: 'parent', + }, + { + message: "add 'examples' field", + action: 'addChild', + snippetYaml: 'examples: \n ', + snippetJson: '"examples": ,\n ', + }, + ], + }, +}; + +export default exampleDeprecatedLint; diff --git a/packages/apidom-ls/test/fixtures/validation/oas/issue2141.yaml b/packages/apidom-ls/test/fixtures/validation/oas/issue2141.yaml index 560407152f..670ec8717c 100644 --- a/packages/apidom-ls/test/fixtures/validation/oas/issue2141.yaml +++ b/packages/apidom-ls/test/fixtures/validation/oas/issue2141.yaml @@ -17,6 +17,7 @@ paths: application/json: schema: type: object + example: 'foo' examples: confirmation-success: summary: short confirmation success @@ -24,9 +25,9 @@ paths: externalValue: outsideLink confirmation-error: summary: short confirmation success - value: + value: test: object - externalValue: outsideLink + externalValue: outsideLink confirmation-errors: summary: short confirmation success value: diff --git a/packages/apidom-ls/test/validate.ts b/packages/apidom-ls/test/validate.ts index d10c49e213..fa90335451 100644 --- a/packages/apidom-ls/test/validate.ts +++ b/packages/apidom-ls/test/validate.ts @@ -2915,11 +2915,43 @@ describe('apidom-ls-validate', function () { { range: { start: { - line: 22, + line: 19, + character: 16, + }, + end: { + line: 19, + character: 23, + }, + }, + message: 'property "example" is deprecated, use "examples" instead', + severity: 2, + code: 10069, + source: 'apilint', + data: { + quickFix: [ + { + message: 'remove example', + action: 'removeChild', + functionParams: ['example'], + target: 'parent', + }, + { + message: "add 'examples' field", + action: 'addChild', + snippetYaml: 'examples: \n ', + snippetJson: '"examples": ,\n ', + }, + ], + }, + }, + { + range: { + start: { + line: 23, character: 18, }, end: { - line: 22, + line: 23, character: 23, }, }, @@ -2931,11 +2963,11 @@ describe('apidom-ls-validate', function () { { range: { start: { - line: 26, + line: 27, character: 18, }, end: { - line: 26, + line: 27, character: 23, }, }, @@ -2947,11 +2979,11 @@ describe('apidom-ls-validate', function () { { range: { start: { - line: 31, + line: 32, character: 18, }, end: { - line: 31, + line: 32, character: 23, }, },