diff --git a/README.md b/README.md index 58c6344b..dd9cf24b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ yarn add @asyncapi/raml-dt-schema-parser ## Usage -```js +```ts import { Parser } from '@asyncapi/parser'; import { RamlDTSchemaParser } from '@asyncapi/raml-dt-schema-parser'; @@ -57,6 +57,36 @@ channels: const { document } = await parser.parse(asyncapiWithRAML); ``` +```js +const { Parser } = require('@asyncapi/parser'); +const { RamlDTSchemaParser } = require('@asyncapi/raml-dt-schema-parser'); + +const parser = new Parser(); +parser.registerSchemaParser(RamlDTSchemaParser()); + +const asyncapiWithRAML = ` +asyncapi: 2.0.0 +info: + title: Example with RAML + version: 0.1.0 +channels: + example: + publish: + message: + schemaFormat: 'application/raml+yaml;version=1.0' + payload: # The following is a RAML data type + type: object + properties: + title: string + author: + type: string + examples: + anExample: Jack Johnson +`; + +const { document } = await parser.parse(asyncapiWithRAML); +``` + It also supports referencing remote RAML data types: ```js diff --git a/package-lock.json b/package-lock.json index b04b64f6..3af50d3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,7 @@ "version": "2.0.1", "license": "Apache-2.0", "dependencies": { - "@asyncapi/parser": "^2.0.0-next-major.6", - "ajv": "^8.11.0", - "ajv-errors": "^3.0.0", - "ajv-formats": "^2.1.1", + "@asyncapi/parser": "^2.0.0-next-major.7", "js-yaml": "^4.1.0", "ramldt2jsonschema": "^1.2.3", "webapi-parser": "^0.5.0" @@ -55,9 +52,9 @@ } }, "node_modules/@asyncapi/parser": { - "version": "2.0.0-next-major.6", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.0.0-next-major.6.tgz", - "integrity": "sha512-d7IKBIYz6h1v2HKVmoegfy4bIcZhT6ApALtvtRdoRjRGa2SIldMeOwZoCT6s2rMO/Z5L9700VkXH6DrZiysQOg==", + "version": "2.0.0-next-major.7", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.0.0-next-major.7.tgz", + "integrity": "sha512-NVL0hGg10zWBn553ntVPgmj9ZeNYV0Ym6eKR4HlUDT/g1rUyWN1KhxvMrNL6YV2l866kRc2NROk0rF3IAqnRbA==", "dependencies": { "@asyncapi/specs": "^3.2.1", "@openapi-contrib/openapi-schema-to-json-schema": "^3.2.0", @@ -12421,9 +12418,9 @@ } }, "@asyncapi/parser": { - "version": "2.0.0-next-major.6", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.0.0-next-major.6.tgz", - "integrity": "sha512-d7IKBIYz6h1v2HKVmoegfy4bIcZhT6ApALtvtRdoRjRGa2SIldMeOwZoCT6s2rMO/Z5L9700VkXH6DrZiysQOg==", + "version": "2.0.0-next-major.7", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.0.0-next-major.7.tgz", + "integrity": "sha512-NVL0hGg10zWBn553ntVPgmj9ZeNYV0Ym6eKR4HlUDT/g1rUyWN1KhxvMrNL6YV2l866kRc2NROk0rF3IAqnRbA==", "requires": { "@asyncapi/specs": "^3.2.1", "@openapi-contrib/openapi-schema-to-json-schema": "^3.2.0", diff --git a/package.json b/package.json index d491701f..f6fffba0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,10 @@ "schema", "parser" ], - "author": "Fran Mendez (fmvilas.com)", + "author": { + "name": "The AsyncAPI maintainers", + "url": "https://www.asyncapi.com" + }, "publishConfig": { "access": "public" }, @@ -46,10 +49,7 @@ "README.md" ], "dependencies": { - "@asyncapi/parser": "^2.0.0-next-major.6", - "ajv": "^8.11.0", - "ajv-errors": "^3.0.0", - "ajv-formats": "^2.1.1", + "@asyncapi/parser": "^2.0.0-next-major.7", "js-yaml": "^4.1.0", "ramldt2jsonschema": "^1.2.3", "webapi-parser": "^0.5.0" diff --git a/src/index.ts b/src/index.ts index cbeeb15a..4c64d5d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,7 @@ const wap = lib.WebApiParser; const r2j = require('ramldt2jsonschema'); /* eslint-enable */ -import type { SchemaParser, ParseSchemaInput, ValidateSchemaInput, SchemaValidateResult } from '@asyncapi/parser'; -import type { v2 } from '@asyncapi/parser/esm/spec-types'; +import type { SchemaParser, ParseSchemaInput, ValidateSchemaInput, SchemaValidateResult, SpecTypesV2 } from '@asyncapi/parser'; export function RamlDTSchemaParser(): SchemaParser { return { @@ -39,7 +38,7 @@ async function validate(input: ValidateSchemaInput): Promise): Promise { +async function parse(input: ParseSchemaInput): Promise { const payload = formatPayload(input.data); // Draft 6 is compatible with 7.