diff --git a/README.md b/README.md index 3d7423dc..afd19ea2 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,37 @@ channels: const { document } = await parser.parse(asyncapiWithOpenAPI); ``` +```js +const { Parser } = require('@asyncapi/parser'); +const { OpenAPISchemaParser } = require('@asyncapi/openapi-schema-parser'); + +const parser = new Parser(); +parser.registerSchemaParser(OpenAPISchemaParser()); + +const asyncapiWithOpenAPI = ` +asyncapi: 2.0.0 +info: + title: Example with OpenAPI + version: 0.1.0 +channels: + example: + publish: + message: + schemaFormat: 'application/vnd.oai.openapi;version=3.0.0' + payload: # The following is an OpenAPI schema + type: object + properties: + title: + type: string + nullable: true + author: + type: string + example: Jack Johnson +`; + +const { document } = await parser.parse(asyncapiWithOpenAPI); +``` + It also supports referencing remote OpenAPI schemas: ```ts diff --git a/package-lock.json b/package-lock.json index e21ab21f..5730276b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.1", "license": "Apache-2.0", "dependencies": { - "@asyncapi/parser": "^2.0.0-next-major.6", + "@asyncapi/parser": "^2.0.0-next-major.7", "@openapi-contrib/openapi-schema-to-json-schema": "^3.2.0", "ajv": "^8.11.0", "ajv-errors": "^3.0.0", @@ -52,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", @@ -14444,9 +14444,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 edec33fc..d9ec1034 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,7 +49,7 @@ "README.md" ], "dependencies": { - "@asyncapi/parser": "^2.0.0-next-major.6", + "@asyncapi/parser": "^2.0.0-next-major.7", "@openapi-contrib/openapi-schema-to-json-schema": "^3.2.0", "ajv": "^8.11.0", "ajv-errors": "^3.0.0", diff --git a/src/index.ts b/src/index.ts index 50a0a313..614ce0d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ - import Ajv from 'ajv'; import addFormats from 'ajv-formats'; import ajvErrors from 'ajv-errors'; @@ -6,8 +5,7 @@ import { jsonSchemaV3 } from './json-schema-v3'; // eslint-disable-next-line @typescript-eslint/no-var-requires const toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema'); -import type { SchemaParser, ValidateSchemaInput, ParseSchemaInput, SchemaValidateResult } from '@asyncapi/parser'; -import type { v2 } from '@asyncapi/parser/esm/spec-types'; +import type { SchemaParser, ValidateSchemaInput, ParseSchemaInput, SchemaValidateResult, SpecTypesV2 } from '@asyncapi/parser'; import type { ValidateFunction, ErrorObject } from 'ajv'; export function OpenAPISchemaParser(): SchemaParser { @@ -31,7 +29,7 @@ async function validate(input: ValidateSchemaInput): Promise): Promise { +async function parse(input: ParseSchemaInput): Promise { const transformed = toJsonSchema(input.data, { cloneSchema: true, keepNotSupported: [