Skip to content

Commit

Permalink
fix(apidom-ls): add deprecated warning for example (#2909)
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalczyk-krzysztof committed Jul 6, 2023
1 parent 6a24536 commit 564d185
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
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 @@ -63,6 +63,7 @@ enum ApilintCodes {
SCHEMA_WRITEONLY,
SCHEMA_EXAMPLES,
SCHEMA_EXTERNAL_DOCS,
SCHEMA_EXAMPLE_DEPRECATED,

DUPLICATE_KEYS = 14999,
NOT_ALLOWED_FIELDS = 15000,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/common/schema/lint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 './example--deprecated';

const schemaLints = [
$idFormatURILint,
Expand Down Expand Up @@ -122,6 +123,7 @@ const schemaLints = [
uniqueItemsNonArrayLint,
uniqueItemsTypeLint,
writeOnlyTypeLint,
exampleDeprecatedLint,
];

export default schemaLints;
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ paths:
application/json:
schema:
type: object
example: 'foo'
examples:
confirmation-success:
summary: short confirmation success
value: testString
externalValue: outsideLink
confirmation-error:
summary: short confirmation success
value:
value:
test: object
externalValue: outsideLink
externalValue: outsideLink
confirmation-errors:
summary: short confirmation success
value:
Expand Down
44 changes: 38 additions & 6 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand All @@ -2931,11 +2963,11 @@ describe('apidom-ls-validate', function () {
{
range: {
start: {
line: 26,
line: 27,
character: 18,
},
end: {
line: 26,
line: 27,
character: 23,
},
},
Expand All @@ -2947,11 +2979,11 @@ describe('apidom-ls-validate', function () {
{
range: {
start: {
line: 31,
line: 32,
character: 18,
},
end: {
line: 31,
line: 32,
character: 23,
},
},
Expand Down

0 comments on commit 564d185

Please sign in to comment.