diff --git a/package-lock.json b/package-lock.json index 0f9091774..a5cbe3f12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "Apache-2.0", "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", @@ -88,12 +88,8 @@ }, "node_modules/@asyncapi/specs": { "version": "3.1.0", - "resolved": "file:../asyncapi-node/asyncapi-specs-3.1.0.tgz", - "integrity": "sha512-6DQZRiBjnPDngKrL1IID4hKpKtFkDZyuUaJIyGBaZqVqXMI4mqd3VES7w8aqibomwg4ecOmGUo70WiWRW6JuYw==", - "license": "Apache-2.0", - "dependencies": { - "@types/json-schema": "^7.0.11" - } + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.1.0.tgz", + "integrity": "sha512-6xFvzDd54+M9g6EM259Y4a4iiFb2VzPr6eoxA/ttwTu7NRxaGScocXskXtuz53ZWx9BWZWuzwDYKfM3KBkDfiQ==" }, "node_modules/@babel/code-frame": { "version": "7.16.7", @@ -17716,11 +17712,9 @@ } }, "@asyncapi/specs": { - "version": "file:../asyncapi-node/asyncapi-specs-3.1.0.tgz", - "integrity": "sha512-6DQZRiBjnPDngKrL1IID4hKpKtFkDZyuUaJIyGBaZqVqXMI4mqd3VES7w8aqibomwg4ecOmGUo70WiWRW6JuYw==", - "requires": { - "@types/json-schema": "^7.0.11" - } + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.1.0.tgz", + "integrity": "sha512-6xFvzDd54+M9g6EM259Y4a4iiFb2VzPr6eoxA/ttwTu7NRxaGScocXskXtuz53ZWx9BWZWuzwDYKfM3KBkDfiQ==" }, "@babel/code-frame": { "version": "7.16.7", diff --git a/package.json b/package.json index ab4ab309f..4e385d85f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/constants.ts b/src/constants.ts index 4defc221c..54256868e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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'; @@ -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]; diff --git a/src/schema-parser/asyncapi-schema-parser.ts b/src/schema-parser/asyncapi-schema-parser.ts index b540473bc..07ffb61d4 100644 --- a/src/schema-parser/asyncapi-schema-parser.ts +++ b/src/schema-parser/asyncapi-schema-parser.ts @@ -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'; @@ -23,7 +24,7 @@ export function AsyncAPISchemaParser(): SchemaParser { } async function validate(input: ValidateSchemaInput): Promise { - const version = input.asyncapi.semver.version as keyof typeof specs; + const version = input.asyncapi.semver.version; const validator = getSchemaValidator(version); let result: SchemaValidateResult[] = []; @@ -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);