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: add AsyncAPI Schema Parser #573

Merged
merged 7 commits into from
Jul 27, 2022

Conversation

smoya
Copy link
Member

@smoya smoya commented Jul 21, 2022

Description

This PR adds the AsyncAPI Schema Parser, which is compatible with Spectral validation functions.

Related issue(s)
#480

@smoya smoya marked this pull request as ready for review July 22, 2022 10:13
src/types.ts Outdated
@@ -16,4 +17,5 @@ export interface DetailedAsyncAPI {
}

export type Diagnostic = ISpectralDiagnostic;
export type SchemaValidateResult = IFunctionResult;
export type SchemaValidateError = IFunctionResult;
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the name to be more explicit about what it is in fact... just an error.

Copy link
Member

Choose a reason for hiding this comment

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

It's not always an error, because from spectral you can also return info or warning severity, by this spectral team called it IFunctionResult not IFunctionError. Please change to the previous one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Rollbacked the rename! thanks for the catch

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Good, but we need some improvements :)

package.json Outdated Show resolved Hide resolved
src/types.ts Outdated
@@ -16,4 +17,5 @@ export interface DetailedAsyncAPI {
}

export type Diagnostic = ISpectralDiagnostic;
export type SchemaValidateResult = IFunctionResult;
export type SchemaValidateError = IFunctionResult;
Copy link
Member

Choose a reason for hiding this comment

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

It's not always an error, because from spectral you can also return info or warning severity, by this spectral team called it IFunctionResult not IFunctionError. Please change to the previous one.

src/schema-parser/asyncapi-schema-parser.ts Outdated Show resolved Hide resolved
src/types.ts Outdated
@@ -1,4 +1,5 @@
import type { ISpectralDiagnostic, IFunctionResult } from '@stoplight/spectral-core';
import { JSONSchema7 }from "json-schema"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { JSONSchema7 }from "json-schema"
import type { JSONSchema7 }from "json-schema"

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, didn't commit. It is now, please check again.

@smoya smoya force-pushed the feat/schemaParser branch from ec38404 to 30c0cb3 Compare July 27, 2022 10:50
* @param {Object} version AsyncAPI version.
* @returns {Object} valid JSON Schema document describing format of AsyncAPI-valid schema for message payload
*/
function preparePayloadSchema2(asyncapiSchema: AsyncAPISchema, version: string) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Comes from #423

@@ -22,7 +94,8 @@ function getMimeTypes() {
'application/schema+json;version=draft-07',
'application/schema+yaml;version=draft-07',
];
['2.0.0', '2.1.0', '2.2.0', '2.3.0'].forEach(version => {

specVersions.forEach((version: string) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the need for adding a new version every time a new spec version is out...

@smoya smoya requested a review from magicmatatjahu July 27, 2022 10:53
Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Good, but we need some additional improvements :)

src/schema-parser/asyncapi-schema-parser.ts Outdated Show resolved Hide resolved
src/schema-parser/asyncapi-schema-parser.ts Outdated Show resolved Hide resolved
src/schema-parser/asyncapi-schema-parser.ts Outdated Show resolved Hide resolved
src/schema-parser/asyncapi-schema-parser.ts Outdated Show resolved Hide resolved
test/schema-parser/asyncapi-schema-parser.spec.ts Outdated Show resolved Hide resolved
@smoya smoya requested a review from magicmatatjahu July 27, 2022 13:28
@sonarcloud
Copy link

sonarcloud bot commented Jul 27, 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

@magicmatatjahu
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit d65e484 into asyncapi:next-major Jul 27, 2022
@smoya smoya mentioned this pull request Jul 27, 2022
20 tasks
@smoya smoya deleted the feat/schemaParser branch August 25, 2022 09:08
magicmatatjahu pushed a commit to magicmatatjahu/parser-js that referenced this pull request Oct 3, 2022
derberg pushed a commit that referenced this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants