-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apidom-ls): create schema rule for missing core keywords
Fix #3549
- Loading branch information
Showing
10 changed files
with
276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const AsyncAPI200 = [{ namespace: 'asyncapi', version: '2.0.0' }]; | ||
export const AsyncAPI210 = [{ namespace: 'asyncapi', version: '2.1.0' }]; | ||
export const AsyncAPI220 = [{ namespace: 'asyncapi', version: '2.2.0' }]; | ||
export const AsyncAPI230 = [{ namespace: 'asyncapi', version: '2.3.0' }]; | ||
export const AsyncAPI240 = [{ namespace: 'asyncapi', version: '2.4.0' }]; | ||
export const AsyncAPI250 = [{ namespace: 'asyncapi', version: '2.5.0' }]; | ||
export const AsyncAPI260 = [{ namespace: 'asyncapi', version: '2.6.0' }]; | ||
|
||
export const AsyncAPI2 = [ | ||
...AsyncAPI200, | ||
...AsyncAPI210, | ||
...AsyncAPI220, | ||
...AsyncAPI230, | ||
...AsyncAPI240, | ||
...AsyncAPI250, | ||
...AsyncAPI260, | ||
]; | ||
export const AsyncAPI = [...AsyncAPI2]; |
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
91 changes: 91 additions & 0 deletions
91
packages/apidom-ls/src/config/common/schema/lint/missing-core-fields-oas-3-0-asyncapi.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,91 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
import { OpenAPI3 } from '../../../openapi/target-specs'; | ||
import { AsyncAPI } from '../../../asyncapi/target-specs'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const missingCoreFieldsOpenAPI3_0AndAsyncAPILint: LinterMeta = { | ||
code: ApilintCodes.SCHEMA_MISSING_CORE_FIELDS, | ||
source: 'apilint', | ||
message: 'Schema does not include any JSON Schema core keywords', | ||
severity: DiagnosticSeverity.Hint, | ||
linterFunction: 'existAnyOfFields', | ||
linterParams: [ | ||
[ | ||
'$anchor', | ||
'$comment', | ||
'$dynamicAnchor', | ||
'$id', | ||
'$ref', | ||
'$schema', | ||
'$vocabulary', | ||
'additionalItems', | ||
'additionalProperties', | ||
'allOf', | ||
'anyOf', | ||
'booleanSchemaValue', | ||
'const', | ||
'contains', | ||
'contentEncoding', | ||
'contentMediaType', | ||
'contentSchema', | ||
'default', | ||
'dependentSchemas', | ||
'deprecated', | ||
'description', | ||
'discriminator', | ||
'else', | ||
'examples', | ||
'exclusiveMaximum', | ||
'exclusiveMaximumValue', | ||
'exclusiveMinimum', | ||
'exclusiveMinimumValue', | ||
'externalDocs', | ||
'format', | ||
'if', | ||
'items', | ||
'dependentRequired', | ||
'maxContains', | ||
'maximum', | ||
'maxItems', | ||
'maxLength', | ||
'maxProperties', | ||
'minContains', | ||
'minimum', | ||
'minItems', | ||
'minLength', | ||
'minProperties', | ||
'multipleOf', | ||
'name', | ||
'not', | ||
'nullable', | ||
'extensions', | ||
'oneOf', | ||
'pattern', | ||
'patternProperties', | ||
'prefixItems', | ||
'properties', | ||
'propertyNames', | ||
'enum', | ||
'example', | ||
'readOnly', | ||
'required', | ||
'then', | ||
'title', | ||
'type', | ||
'unevaluatedItems', | ||
'unevaluatedProperties', | ||
'uniqueItems', | ||
'writeOnly', | ||
'xml', | ||
], | ||
true, | ||
'boolean', | ||
], | ||
marker: 'key', | ||
targetSpecs: [...OpenAPI3, ...AsyncAPI], | ||
}; | ||
|
||
export default missingCoreFieldsOpenAPI3_0AndAsyncAPILint; |
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
44 changes: 44 additions & 0 deletions
44
packages/apidom-ls/test/fixtures/validation/asyncapi/issue3549.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,44 @@ | ||
asyncapi: 2.1.0 | ||
info: | ||
version: '1.0.0' | ||
title: missing schema keywords | ||
description: 'desc' | ||
license: | ||
name: Apache 2.0 | ||
url: https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
servers: | ||
production: | ||
url: mqtt://test.mosquitto.org | ||
protocol: mqtt | ||
description: Test MQTT broker | ||
|
||
channels: | ||
user/signedup: | ||
publish: | ||
operationId: onUserSignUp | ||
message: | ||
$ref : '#/components/messages/UserSignedUp' | ||
|
||
components: | ||
messages: | ||
UserSignedUp: | ||
name: userSignedUp | ||
title: User signed up event | ||
summary: Inform about a new user registration in the system | ||
contentType: application/json | ||
payload: | ||
$ref: '#/components/schemas/userSignedUpPayload' | ||
|
||
schemas: | ||
userSignedUpPayload: | ||
type: object | ||
properties: | ||
anyOf: | ||
otherKey: foo | ||
good: | ||
otherKey: foo | ||
$dynamicAnchor: good | ||
boolFalse: false | ||
boolTrue: true | ||
emptyObject: {} |
24 changes: 24 additions & 0 deletions
24
packages/apidom-ls/test/fixtures/validation/oas/issue3549.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,24 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: missing schema keywords | ||
version: 1.0.0 | ||
paths: | ||
/a: | ||
get: | ||
operationId: aget | ||
responses: | ||
'200': | ||
description: aget | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
anyOf: | ||
otherKey: foo | ||
good: | ||
otherKey: foo | ||
$dynamicAnchor: good | ||
boolFalse: false | ||
boolTrue: true | ||
emptyObject: {} |
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