-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat(rulesets): support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions #2067
feat(rulesets): support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions #2067
Conversation
ca8f87b
to
78885c5
Compare
Thanks a bunch for the PR. I truly appreciate it.
Hmmm, that is odd. It did work on the CI though, so everything's good. |
@@ -17,6 +17,13 @@ __metadata: | |||
languageName: node | |||
linkType: hard | |||
|
|||
"@asyncapi/specs@npm:^2.13.0": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so good to see that schema.asyncapi2.json disappear ❤️
@P0lip Thanks for quick response!
No problem, no rush :) If something will be wrong (like duplicated functions) please comment and I will handle that.
I see that on CI it pass so probably it's env problems. |
How to test that? It wasn't working for me. I tried: A rules file: extends: "spectral:asyncapi" I just copied the sample from https://studio.asyncapi.com/: asyncapi: '2.3.0'
info:
title: Streetlights Kafka API
version: '1.0.0'
description: |
The Smartylighting Streetlights API allows you to remotely manage the city lights.
... Then I get the error:
A simple solution is to correct the file |
@muenchhausen Hello! I tested in this way (you need to checkout to this branch):
I have these errors for simple AsyncAPI file (based on
I also tested this https://raw.githubusercontent.com/asyncapi/spec/master/examples/streetlights-kafka.yml and it also works :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks a lot.
I'll merge it tomorrow, there's one change I'll need to introduce to make sure the release goes smoothly, but I'll handle that.
function shouldIgnoreError(error: ErrorObject): boolean { | ||
return ( | ||
// oneOf is a fairly error as we have 2 options to choose from for most of the time. | ||
error.keyword === 'oneOf' || | ||
// the required $ref is entirely useless, since aas-schema rules operate on resolved content, so there won't be any $refs in the document | ||
(error.keyword === 'required' && error.params.missingProperty === '$ref') | ||
); | ||
} | ||
|
||
// this is supposed to cover edge cases we need to cover manually, when it's impossible to detect the most appropriate error, i.e. oneOf consisting of more than 3 members, etc. | ||
// note, more errors can be included if certain messages reported by AJV are not quite meaningful | ||
const ERROR_MAP = [ | ||
{ | ||
path: /^components\/securitySchemes\/[^/]+$/, | ||
message: 'Invalid security scheme', | ||
}, | ||
]; | ||
|
||
// The function removes irrelevant (aka misleading, confusing, useless, whatever you call it) errors. | ||
// There are a few exceptions, i.e. security components I covered manually, | ||
// yet apart from them we usually deal with a relatively simple scenario that can be literally expressed as: "either proper value of $ref property". | ||
// The $ref part is never going to be interesting for us, because both aas-schema rules operate on resolved content, so we won't have any $refs left. | ||
// As you can see, what we deal here wit is actually not really oneOf anymore - it's always the first member of oneOf we match against. | ||
// That being said, we always strip both oneOf and $ref, since we are always interested in the first error. | ||
export function prepareResults(errors: ErrorObject[]): void { | ||
// Update additionalProperties errors to make them more precise and prevent them from being treated as duplicates | ||
for (const error of errors) { | ||
if (error.keyword === 'additionalProperties') { | ||
error.instancePath = `${error.instancePath}/${String(error.params['additionalProperty'])}`; | ||
} | ||
} | ||
|
||
for (let i = 0; i < errors.length; i++) { | ||
const error = errors[i]; | ||
|
||
if (i + 1 < errors.length && errors[i + 1].instancePath === error.instancePath) { | ||
errors.splice(i + 1, 1); | ||
i--; | ||
} else if (i > 0 && shouldIgnoreError(error) && errors[i - 1].instancePath.startsWith(error.instancePath)) { | ||
errors.splice(i, 1); | ||
i--; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of that stuff could be indeed shared with the OAS ruleset, but we can do it later.
It's not a big deal for now.
@P0lip Thanks a lot! If there will be problems/bugs, please ping me in this thread :) We at AsyncAPI are thinking about moving (if you don't mind) all the rules related to AsyncAPI to our organization on github. That way, people could use the up-to-date ruleset for AsyncAPI and you wouldn't have to worry about maintaning AsyncAPI on your side. Here is the issue I created asyncapi/parser-js#477. Of course I don't give a word that we will do such a thing, we have to discuss it at our place first, but if we decided to do such a thing, would Stoplight have something against it? By the way, I'm currently testing a custom rules for more complex validations like binding validations, extensions etc and I'm delighted. Super project! |
@magicmatatjahu I'll let you know soon. I reached out to folks internally to see what their take on it is and will try to provide an update as soon as I learn anything.
Thanks! ❤️ We're really glad you like the project. |
# [@stoplight/spectral-formats-v1.1.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formats-v1.0.2...@stoplight/spectral-formats-v1.1.0) (2022-02-24) ### Features * **formats:** support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions ([#2067](#2067)) ([b0b008d](b0b008d))
# [@stoplight/spectral-rulesets-v1.5.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-v1.4.3...@stoplight/spectral-rulesets-v1.5.0) (2022-02-24) ### Features * **rulesets:** support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions ([#2067](#2067)) ([2f1d7bf](2f1d7bf))
After stoplightio#2067 I think this change was missed 🙂
## [1.1.3](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-runtime-v1.1.2...@stoplight/spectral-runtime-1.1.3) (2024-11-13) ### Bug Fixes * **cli:** choose proxy agent based on requester protocol ([#2521](#2521)) ([056f2e1](056f2e1)) * **cli:** clarify usage of --format ([#2575](#2575)) ([96eee89](96eee89)) * **cli:** do not show 'or higher' if severity equals error ([#2172](#2172)) ([f31ec63](f31ec63)) * **cli:** missing line break ([#2251](#2251)) ([d16bf9a](d16bf9a)) * **cli:** output to stdout not working with multiple output formatters ([#2044](#2044)) ([77dfe3b](77dfe3b)) * **cli:** peer dependency incorrectly met ([#2268](#2268)) ([1b70398](1b70398)) * **cli:** Trigger cli release ([#2695](#2695)) ([c48a929](c48a929)) * **cli:** trigger docker release ([920f7b5](920f7b5)) * **cli:** update dependencies and trigger docker release ([c87eacf](c87eacf)) * **core:** async functions have undefined paths ([#2304](#2304)) ([df257b3](df257b3)) * **core:** bump @stoplight/better-ajv-errors from 1.0.1 to 1.0.3 ([7f9bcba](7f9bcba)) * **core:** bump nimma from 0.1.7 to 0.1.8 ([#2058](#2058)) ([fb756f2](fb756f2)) * **core:** bump nimma from 0.1.8 to 0.2.0 ([#2088](#2088)) ([36ec40e](36ec40e)) * **core:** bump nimma from 0.2.0 to 0.2.1 ([#2157](#2157)) ([4d5ebeb](4d5ebeb)) * **core:** bump nimma from 0.2.1 to 0.2.2 ([#2173](#2173)) ([65ba74f](65ba74f)) * **core:** consider `message` when de-duplicating results ([#2052](#2052)) ([b07cc7b](b07cc7b)) * **core:** dedupe paths containing special characters correctly ([758de21](758de21)) * **core:** fix 'resolved vs unresolved' json path mapping ([#2202](#2202)) ([157ec59](157ec59)) * **core:** fix for TypeError "this.formats.has is not a function" ([#2664](#2664)) ([75d642d](75d642d)) * **core:** improve deep ruleset inheritance ([#2326](#2326)) ([378b4b8](378b4b8)) * **core:** invalid then produced by Rule#toJSON ([#2496](#2496)) ([db91553](db91553)) * **core:** more accurate ruleset error paths ([66b3ca7](66b3ca7)) * **core:** pointer in overrides are applied too broadly ([#2511](#2511)) ([69403c1](69403c1)) * **core:** redeclared rules should always be re-enabled ([#2138](#2138)) ([6def6be](6def6be)) * **core:** require new formats version ([#2725](#2725)) ([8ec328f](8ec328f)) * **core:** reset path in fn context ([#2389](#2389)) ([3d47ec4](3d47ec4)) * **core:** support utf8 surrogates ([#2267](#2267)) ([a1bd6d2](a1bd6d2)) * **deps:** fix package.json ([0161072](0161072)) * **formats:** update spectral core version ([6b196da](6b196da)) * **formatters:** update spectral core to latest version ([8a382f4](8a382f4)) * **functions:** __importDefault undefined ([609ecb1](609ecb1)) * **functions:** bump stoplight/better-ajv-errors ([bd0c5fb](bd0c5fb)) * **functions:** handle percent encoded in unreferencedReusableObject([#2212](#2212)) ([d16b5a6](d16b5a6)) * **functions:** reset RegExp.lastIndex to zero when using cached RegExp objects ([#2079](#2079)) ([4839527](4839527)) * **functions:** update spectral core to latest ([ede60f3](ede60f3)) * **parsers:** update @stoplight/* dependencies ([a68c255](a68c255)) * **parsers:** update @stoplight/json from ~3.20.1 to ~3.21.0 ([e906d20](e906d20)) * **parsers:** update @stoplight/yaml from ~4.2.3 to ~4.3.0 ([91fdded](91fdded)) * **ref-resolver:** bump @stoplight/json-ref-resolver from ~3.1.4 to ~3.1.5 ([#3635](https://github.com/stoplightio/spectral/issues/3635)) ([215ae93](215ae93)) * **ref-resolver:** update @stoplight/json-ref-resolver from ~3.1.5 to ~3.1.6 ([6f73151](6f73151)) * **ref-resolver:** update @stoplight/json-ref-resolver from 3.1.3 to ~3.1.4 ([dc97f24](dc97f24)) * **repo:** remove discord link and fix typo in github bug template ([#2642](#2642)) ([048924d](048924d)) * **repo:** update yarn lock ([362cdb4](362cdb4)) * **ruleset-bundler:** __importDefault undefined ([874a80e](874a80e)) * **ruleset-bundler:** address Rollup.js warning ([1e36673](1e36673)) * **ruleset-bundler:** builtins plugin should create a new instance for each module ([b06903c](b06903c)) * **ruleset-bundler:** defaults should be last one ([#2403](#2403)) ([8780cfa](8780cfa)) * **ruleset-bundler:** never externalize builtins ([#2174](#2174)) ([fb1bbe6](fb1bbe6)) * **ruleset-bundler:** remove extraneous 'external dependency' warnings ([#2475](#2475)) ([e791534](e791534)) * **ruleset-bundler:** virtualFs plugin incompatible with commonjs plugin ([a48381b](a48381b)) * **ruleset-bundler:** virtualFs plugin not recognizing files ([#2271](#2271)) ([4bc38b3](4bc38b3)) * **ruleset-migrator:** avoid positive lookbehinds ([#2349](#2349)) ([455c324](455c324)) * **ruleset-migrator:** correct package.json's browser field ([#2497](#2497)) ([89a6a67](89a6a67)) * **ruleset-migrator:** http/https uris not followed correctly ([#2247](#2247)) ([573e112](573e112)) * **ruleset-migrator:** transform functions under overrides ([#2459](#2459)) ([45e817f](45e817f)) * **ruleset-migrator:** update @stoplight/json from ~3.20.1 to ~3.21.0 ([3f7eebc](3f7eebc)) * **ruleset-migrator:** use module for require.resolve ([#2405](#2405)) ([d7c0fa4](d7c0fa4)) * **ruleset-migrator:** validate aliases correctly ([#2085](#2085)) ([1f4ab20](1f4ab20)) * **rulesets:** __importDefault undefined ([fdd647b](fdd647b)) * **rulesets:** __importDefault undefined ([c123bdf](c123bdf)) * **rulesets:** __importDefault undefined ([#2243](#2243)) ([660f090](660f090)) * **rulesets:** always allow string examples in asyncapi schema ([#2625](#2625)) ([4e2f797](4e2f797)) * **rulesets:** avoid false errors from ajv ([#2408](#2408)) ([92dab78](92dab78)) * **rulesets:** bump @stoplight/better-ajv-errors from 1.0.1 to 1.0.3 ([4f55c4f](4f55c4f)) * **rulesets:** example validation for required readOnly and writeOnly properties ([#2573](#2573)) ([ae1fea5](ae1fea5)) * **rulesets:** fixed array-items type property selector ([#2638](#2638)) ([0845fb5](0845fb5)) * **rulesets:** handle empty payload and headers in AsyncAPI message's examples validation ([#2284](#2284)) ([4068221](4068221)) * **rulesets:** length.min said "must not be longer than" ([#2355](#2355)) ([df3b6f9](df3b6f9)) * **rulesets:** oasExample should clean id fields from non-schema objects ([#2561](#2561)) ([7f7583e](7f7583e)) * **rulesets:** operation-tags should fail on empty array ([#2050](#2050)) ([a4c421f](a4c421f)) * **rulesets:** remove step summary rule ([#2692](#2692)) ([d5a566f](d5a566f)) * **rulesets:** simplify schema used in duplicated-entry-in-enum ([#2055](#2055)) ([8451774](8451774)) * **rulesets:** tweak server variables function ([#2533](#2533)) ([244cbda](244cbda)) * **rulesets:** update spectral core to latest ([d74c2b0](d74c2b0)) * **rulesets:** use uri-reference for oauth security schemes ([#2652](#2652)) ([c411e63](c411e63)) ### Features * **cli:** add sarif formatter ([#2532](#2532)) ([959a86a](959a86a)) * **cli:** improve error logging ([#2071](#2071)) ([b194368](b194368)) * **cli:** require new stoplight dependencies ([#2726](#2726)) ([8a736b5](8a736b5)) * **cli:** require newer version of all Spectral dependencies ([10ddd97](10ddd97)) * **cli:** sort linting results alphabetically ([#2147](#2147)) ([84d48cf](84d48cf)) * **cli:** trigger release ([87a90b3](87a90b3)) * **cli:** use Content-Type header to detect ruleset format ([#2272](#2272)) ([b4c3c11](b4c3c11)) * **cli:** use hpagent ([#2513](#2513)) ([9b2d347](9b2d347)) * **core:** improve alias validation ([#2164](#2164)) ([a15150a](a15150a)) * **core:** improve validation ([#2026](#2026)) ([8315162](8315162)) * **core:** include error codes in RulesetValidationError ([c01c6b5](c01c6b5)) * **core:** relax formats validation ([#2151](#2151)) ([de16b4c](de16b4c)) * **core:** support end-user extensions in the rule definitions ([#2345](#2345)) ([365fced](365fced)) * **core:** support JSON ruleset validation ([#2062](#2062)) ([aeb7d5b](aeb7d5b)) * **core:** support x- extensions in the ruleset ([#2440](#2440)) ([964151e](964151e)) * **core:** trigger release ([b73d5e8](b73d5e8)) * **formats:** add arazzo format ([#2663](#2663)) ([dc1a8ef](dc1a8ef)) * **formats:** add support for 2.5.0 AsyncAPI ([#2292](#2292)) ([a7f9fa7](a7f9fa7)) * **formats:** jsonSchemaLoose format should search for enum keyword ([#2551](#2551)) ([0835545](0835545)) * **formats:** support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions ([#2067](#2067)) ([b0b008d](b0b008d)) * **formats:** support AsyncAPI 2.4 ([#2146](#2146)) ([8b5d6b3](8b5d6b3)) * **formats:** support AsyncAPI 2.6.0 ([#2391](#2391)) ([b8e51b4](b8e51b4)) * **formatters:** add code climate (GitLab) formatter ([#2648](#2648)) ([41eca61](41eca61)) * **formatters:** add export entrypoint for utils ([#2482](#2482)) ([d4b883c](d4b883c)) * **formatters:** add GitHub Actions formatter ([#2508](#2508)) ([6904927](6904927)) * **formatters:** add markdown formatter ([#2662](#2662)) ([b5edf5e](b5edf5e)) * **formatters:** add sarif formatter ([#2532](#2532)) ([908c308](908c308)) * **formatters:** move formatters to a separate package ([#2468](#2468)) ([664e259](664e259)) * **ruleset-bundler:** add fullOutput option to bundleRuleset ([#2194](#2194)) ([a31d34c](a31d34c)) * **ruleset-bundler:** expose commonjs plugin ([91a4b80](91a4b80)) * **ruleset-bundler:** plugins should be easy to override ([0263bf0](0263bf0)) * **ruleset-bundler:** skypack plugin accepts ignore list ([#2318](#2318)) ([6e6d0de](6e6d0de)) * **ruleset-migrator:** relax validation ([#2307](#2307)) ([d5ce09e](d5ce09e)) * **ruleset-migrator:** use Content-Type header to detect ruleset format ([#2317](#2317)) ([7abbe95](7abbe95)) * **rulesets:** add AsyncAPI v3 support ([#2697](#2697)) ([3d69be7](3d69be7)) * **rulesets:** add multiple xor ([#2614](#2614)) ([af9c742](af9c742)) * **rulesets:** add new rule that requires sibling items field for type array ([#2632](#2632)) ([24198bc](24198bc)) * **rulesets:** add oas3_1-servers-in-webhook and oas3_1-callbacks-in… ([#2581](#2581)) ([7a8cc0e](7a8cc0e)) * **rulesets:** add oas3-server-variables rule ([#2526](#2526)) ([4c4de85](4c4de85)) * **rulesets:** add rule to check if the AsyncAPI document is using the latest version ([#2282](#2282)) ([366779f](366779f)) * **rulesets:** add rule to validate AsyncAPI message's examples ([#2126](#2126)) ([87ef046](87ef046)) * **rulesets:** add rules for validation of server variables and channel parameters ([#2101](#2101)) ([9acc633](9acc633)) * **rulesets:** add rules for validation uniqueness of tag names ([#2104](#2104)) ([4447d81](4447d81)) * **rulesets:** add scope validation to oas{2,3}-operation-security-defined rules ([#2538](#2538)) ([68aacd6](68aacd6)) * **rulesets:** add support for 2.5.0 AsyncAPI ([#2292](#2292)) ([0cb2e85](0cb2e85)) * **rulesets:** add traits array path to headers rule ([#2460](#2460)) ([9ceabca](9ceabca)) * **rulesets:** add unused components server rule ([#2097](#2097)) ([71b312e](71b312e)) * **rulesets:** check uniqueness of AsyncAPI messages ([#2224](#2224)) ([297531b](297531b)) * **rulesets:** check uniqueness of AsyncAPI operations ([#2121](#2121)) ([8b3cce4](8b3cce4)) * **rulesets:** improve {oas2,oas3}-valid-schema rule ([#2574](#2574)) ([8df2c36](8df2c36)) * **rulesets:** initial rulesets for the Arazzo Specification ([#2672](#2672)) ([8443232](8443232)) * **rulesets:** support 2.1.0, 2.2.0, 2.3.0 AsyncAPI versions ([#2067](#2067)) ([2f1d7bf](2f1d7bf)) * **rulesets:** support AsyncAPI 2.4 ([#2146](#2146)) ([7364b2d](7364b2d)) * **rulesets:** support AsyncAPI 2.6.0 ([#2391](#2391)) ([94a7801](94a7801)) * **rulesets:** validate API security in oas-operation-security-defined ([#2046](#2046)) ([5540250](5540250)) * **rulesets:** validate channel servers, server securities and operation securities ([#2122](#2122)) ([9accd31](9accd31)) ### Performance Improvements * **core:** bump jsonpath-plus to 7.1.0 ([#2259](#2259)) ([aacdcd7](aacdcd7))
Fixes #1759.
Checklist
Does this PR introduce a breaking change?
There're not a breaking changes but are some backward compatible named exports.
Additional context
This is my first contribution to this project (btw. awesome project!), so if I forgot something please let me know. I don't know if I should describe somewhere in the documentation the support for the latest versions of AsyncAPI, if so please let me know where.
Changes:
@asyncapi/specs
package where there are always up-to-date JSON Schemas.aas2_0
,aas2_1
etc.asyncApi2DocumentSchema
rule identical as for OpenAPI to validate the document using the appropriate JSON Schema version - I know about duplicated code so please let me know if I should create something likecommon.ts
file with reusable functions for AsyncAPI and OpenAPI in therulesets
package.NOTE:
I cannot run all tests locally, because I have several failed tests related to the
spectral-functions
package like:Is a known issue, or perhaps it's related to my environment? 🤷🏼