Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu committed Sep 12, 2022
1 parent ab5d833 commit 46b0819
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
18 changes: 6 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"release": "semantic-release"
},
"dependencies": {
"@asyncapi/specs": "file:../asyncapi-node/asyncapi-specs-3.1.0.tgz",
"@asyncapi/specs": "^3.1.0",
"@openapi-contrib/openapi-schema-to-json-schema": "^3.2.0",
"@stoplight/spectral-core": "^1.14.1",
"@stoplight/spectral-functions": "^1.7.1",
Expand Down
6 changes: 4 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import specs from '@asyncapi/specs/supported';
// @ts-ignore
import specs from '@asyncapi/specs';

export const xParserSpecParsed = 'x-parser-spec-parsed';
export const xParserSpecStringified = 'x-parser-spec-stringified';
Expand All @@ -15,5 +16,6 @@ export const xParserCircularProps = 'x-parser-circular-props';

export const EXTENSION_REGEX = /^x-[\w\d.\-_]+$/;

export const specVersions = Object.keys(specs);
// Only >=2.0.0 versions are supported
export const specVersions = Object.keys(specs).filter((version: string) => !['1.0.0', '1.1.0', '1.2.0', '2.0.0-rc1', '2.0.0-rc2'].includes(version));
export const lastVersion = specVersions[specVersions.length - 1];
7 changes: 4 additions & 3 deletions src/schema-parser/asyncapi-schema-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ajv from 'ajv';
import specs from '@asyncapi/specs/supported';
// @ts-ignore
import specs from '@asyncapi/specs';

import { specVersions } from '../constants';

Expand All @@ -23,7 +24,7 @@ export function AsyncAPISchemaParser(): SchemaParser {
}

async function validate(input: ValidateSchemaInput<unknown, unknown>): Promise<SchemaValidateResult[]> {
const version = input.asyncapi.semver.version as keyof typeof specs;
const version = input.asyncapi.semver.version;
const validator = getSchemaValidator(version);

let result: SchemaValidateResult[] = [];
Expand Down Expand Up @@ -65,7 +66,7 @@ function ajvToSpectralResult(errors: ErrorObject[]): SchemaValidateResult[] {
});
}

function getSchemaValidator(version: keyof typeof specs): ValidateFunction {
function getSchemaValidator(version: string): ValidateFunction {
let validator = ajv.getSchema(version);
if (!validator) {
const schema = preparePayloadSchema(specs[version], version);
Expand Down

0 comments on commit 46b0819

Please sign in to comment.