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

fix(apidom-ls): add deprecated warning for example property #2909

Merged
merged 1 commit into from
Jul 6, 2023
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 @@ -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