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

refactor: integrate custom schemas with parser and spectral #579

Merged

Conversation

magicmatatjahu
Copy link
Member

@magicmatatjahu magicmatatjahu commented Aug 24, 2022

Description

  • integrate custom schemas with parser and Spectral:
    • write custom Spectral rule to validate schemas
    • write logic to parse schemas
    • write unit tests

cc @smoya

Related issue(s)
Part of #482

@magicmatatjahu magicmatatjahu added the enhancement New feature or request label Aug 25, 2022
@magicmatatjahu magicmatatjahu marked this pull request as ready for review August 25, 2022 14:17
@@ -62,6 +67,6 @@ export async function parseSchemasV2(parser: Parser, detailed: DetailedAsyncAPI)
}

async function parseSchemaV2(parser: Parser, item: ToParseItem) {
item.value[xParserOriginalSchemaFormat] = item.input.schemaFormat;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you are removing it but I can't see where we add xParserOriginalSchemaFormat value back.

Copy link
Member Author

@magicmatatjahu magicmatatjahu Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't remove schemaFormat from message in custom parsers so we don't need to set it the extension. Is it clear?

Copy link
Member

@smoya smoya Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need remember to modify the README as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change it! :)

if (spectral instanceof Spectral) {
this.spectral = spectral;
} else {
this.spectral = new Spectral(spectral);
}

// TODO: fix type
this.spectral.setRuleset(aasRuleset as any);
this.registerSchemaParser(AsyncAPISchemaParser());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now register the other ones as all have been merged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. As current solution, people need to register given format manually. For example, RAML works only on nodejs, so register RAML here will break browser compability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's right! 👍 thanks

@sonarcloud
Copy link

sonarcloud bot commented Aug 29, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

recommended: true,
given: [
// operations
'$.channels.*.[publish,subscribe].message',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized all those paths are tied to AsyncAPI Spec v2.x.x. How would we make it happen for v3.x.x ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By separate function, we can use different "formats" for rules in this same rulesets - one function for v2, another one for v3. Don't worry :)

Copy link
Member

@smoya smoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great job @magicmatatjahu 💯 🚀 🌔

@magicmatatjahu
Copy link
Member Author

/rtm

@asyncapi-bot asyncapi-bot merged commit 1764391 into asyncapi:next-major Aug 29, 2022
@magicmatatjahu magicmatatjahu deleted the next/integrate-custom-parsers branch August 29, 2022 10:51
@magicmatatjahu magicmatatjahu mentioned this pull request Aug 31, 2022
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready-to-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants