-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ls): process schema 'null' / 'nullable' depending on spec version
- Loading branch information
Showing
9 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/apidom-ls/src/config/common/schema/lint/nullable--not-recommended.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const nullableNotRecommendedLint: LinterMeta = { | ||
code: ApilintCodes.SCHEMA_NULLABLE_NOT_RECOMMENDED, | ||
source: 'apilint', | ||
message: 'nullable has no special meaning, if not set on purpose use `type="null"` instead', | ||
severity: DiagnosticSeverity.Hint, | ||
linterFunction: 'missingField', | ||
linterParams: ['nullable'], | ||
marker: 'key', | ||
markerTarget: 'nullable', | ||
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' }, | ||
{ namespace: 'openapi', version: '3.1.0' }, | ||
], | ||
data: { | ||
quickFix: [ | ||
{ | ||
message: 'remove nullable', | ||
action: 'removeChild', | ||
functionParams: ['nullable'], | ||
target: 'parent', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default nullableNotRecommendedLint; |
58 changes: 58 additions & 0 deletions
58
packages/apidom-ls/src/config/common/schema/lint/type--type-openapi-3-0.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const typeTypeOpenAPI3_0Lint: LinterMeta = { | ||
code: ApilintCodes.SCHEMA_TYPE, | ||
source: 'apilint', | ||
message: 'type must be one of allowed values', | ||
severity: DiagnosticSeverity.Error, | ||
linterFunction: 'apilintValueOrArray', | ||
linterParams: [['boolean', 'object', 'array', 'number', 'string', 'integer'], true], | ||
marker: 'value', | ||
target: 'type', | ||
targetSpecs: [ | ||
{ namespace: 'openapi', version: '3.0.0' }, | ||
{ namespace: 'openapi', version: '3.0.1' }, | ||
{ namespace: 'openapi', version: '3.0.2' }, | ||
{ namespace: 'openapi', version: '3.0.3' }, | ||
], | ||
data: { | ||
quickFix: [ | ||
{ | ||
message: "update to 'boolean'", | ||
action: 'updateValue', | ||
functionParams: ['boolean'], | ||
}, | ||
{ | ||
message: "update to 'object'", | ||
action: 'updateValue', | ||
functionParams: ['object'], | ||
}, | ||
{ | ||
message: "update to 'array'", | ||
action: 'updateValue', | ||
functionParams: ['array'], | ||
}, | ||
{ | ||
message: "update to 'number'", | ||
action: 'updateValue', | ||
functionParams: ['null'], | ||
}, | ||
{ | ||
message: "update to 'string'", | ||
action: 'updateValue', | ||
functionParams: ['string'], | ||
}, | ||
{ | ||
message: "update to 'integer'", | ||
action: 'updateValue', | ||
functionParams: ['integer'], | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default typeTypeOpenAPI3_0Lint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/apidom-ls/test/fixtures/validation/oas/nullable-oas31.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: test | ||
version: 1.0.0 | ||
paths: | ||
/a: | ||
get: | ||
operationId: aget | ||
components: | ||
schemas: | ||
foo: | ||
type: string | ||
nullable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters