-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrate schema rule with spectral ruleset
- Loading branch information
1 parent
32f7b44
commit 75472a0
Showing
5 changed files
with
78 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { RulesetDefinition } from "@stoplight/spectral-core"; | ||
import { asyncapi as aasRuleset } from "@stoplight/spectral-rulesets"; | ||
|
||
import { aas2schemaParserRule } from './schema-parser/spectral-rule-v2'; | ||
|
||
import type { Parser } from "./parser"; | ||
|
||
export function configureSpectral(parser: Parser) { | ||
const ruleset = configureRuleset(parser); | ||
parser.spectral.setRuleset(ruleset); | ||
} | ||
|
||
function configureRuleset(parser: Parser): RulesetDefinition { | ||
// We do not use these two given rules from the official ruleset due to the fact that the given rules validate only AsyncAPI Schemas and prevent defining schemas in other formats | ||
const rules = { | ||
...aasRuleset.rules, | ||
'asyncapi-schemas-v2': aas2schemaParserRule(parser), | ||
'asyncapi-payload-unsupported-schemaFormat': undefined, | ||
'asyncapi-payload': undefined, | ||
}; | ||
delete rules['asyncapi-payload-unsupported-schemaFormat']; | ||
delete rules['asyncapi-payload']; | ||
|
||
// official type for RulesetDefinition needs `extends` so we need to convert first to any and then to RulesetDefinition - bug on Spectral side | ||
return { | ||
...aasRuleset, | ||
rules, | ||
} as any as RulesetDefinition; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Parser } from '../../src/parser'; | ||
import { validate } from '../../src/lint'; | ||
import { AsyncAPISchemaParser } from '../../src/schema-parser/asyncapi-schema-parser'; | ||
|
||
describe('aas2schemaParserRule', function() { | ||
const parser = new Parser(); | ||
parser.registerSchemaParser(AsyncAPISchemaParser()); | ||
|
||
it('should validate invalid AsyncAPI Schema with invalid schema', async function() { | ||
const document = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel1: { | ||
publish: { | ||
message: { | ||
payload: { | ||
oneOf: "this should be an array", | ||
properties: { | ||
name: { | ||
if: "this should be an if" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const { diagnostics } = await validate(parser, document); | ||
|
||
// expect(parsed).toBeInstanceOf(AsyncAPIDocumentV2); | ||
// expect(diagnostics.length > 0).toEqual(true); | ||
// console.log(diagnostics); | ||
}); | ||
}); |