@asyncapi/parser
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -34,3 +34,3 @@ const path = require('path'); | ||
* | ||
* @param {String} asyncapiYAMLorJSON An AsyncAPI document in JSON or YAML format. | ||
* @param {(String | Object)} asyncapiYAMLorJSON An AsyncAPI document in JSON or YAML format. | ||
* @param {Object} [options] Configuration options. | ||
@@ -37,0 +37,0 @@ * @param {String} [options.path] Path to the AsyncAPI document. It will be used to resolve relative references. Defaults to current working dir. |
{ | ||
"name": "@asyncapi/parser", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "JavaScript AsyncAPI parser.", | ||
@@ -44,3 +44,3 @@ "main": "lib/index.js", | ||
"@semantic-release/commit-analyzer": "^8.0.1", | ||
"@semantic-release/github": "^7.0.4", | ||
"@semantic-release/github": "7.2.3", | ||
"@semantic-release/npm": "^7.0.3", | ||
@@ -53,3 +53,3 @@ "@semantic-release/release-notes-generator": "^9.0.1", | ||
"conventional-changelog-conventionalcommits": "^4.2.3", | ||
"eslint": "^7.0.0", | ||
"eslint": "^7.27.0", | ||
"eslint-plugin-mocha": "^7.0.1", | ||
@@ -65,3 +65,3 @@ "eslint-plugin-security": "^1.4.0", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.0.4", | ||
"semantic-release": "17.4.3", | ||
"shx": "^0.3.3", | ||
@@ -93,3 +93,7 @@ "start-server-and-test": "^1.11.3", | ||
"branches": [ | ||
"master" | ||
"master", | ||
{ | ||
"name": "2021-06-release", | ||
"prerelease": true | ||
} | ||
], | ||
@@ -96,0 +100,0 @@ "plugins": [ |
@@ -27,4 +27,6 @@ <h5 align="center"> | ||
- [API documentation](#api-documentation) | ||
- [Using in the browser](#using-in-the-browser) | ||
- [Custom message parsers](#custom-message-parsers) | ||
- [Error types](#error-types) | ||
- [Custom extensions](#custom-extensions) | ||
- [Circular references](#circular-references) | ||
@@ -99,2 +101,3 @@ - [Develop](#develop) | ||
## API documentation | ||
The parser API is generally structured the same way as the AsyncAPI specification, with additional support functions such as `has<Something>()`. The parser uses wrapped functions to get the properties stored in JSON. This means in order to get the info object you would use the function `doc.info()` and to get the title inside the info object you call `doc.info().title()`. | ||
@@ -104,2 +107,30 @@ | ||
## Using in the browser | ||
The package contains a built-in version of the parser, which is created via [`browserify`](https://github.com/browserify/browserify). To use it, you need to import the parser into the HTML file as below: | ||
```html | ||
<script src="https://unpkg.com/@asyncapi/parser@latest/dist/bundle.js"></script> | ||
<script> | ||
const parser = window['AsyncAPIParser']; | ||
... | ||
</script> | ||
``` | ||
Or, if you want to use a parser in a JS application of the SPA kind, import the parser as shown below: | ||
```js | ||
import '@asyncapi/parser/dist/bundle'; | ||
const parser = window['AsyncAPIParser']; | ||
... | ||
``` | ||
Otherwise, if your application is bundled via bundlers like `webpack`, you can import the parser like a regular package: | ||
```js | ||
import parser from '@asyncapi/parser'; | ||
``` | ||
## Custom message parsers | ||
@@ -110,2 +141,3 @@ | ||
1. Create custom parser module that exports two functions: | ||
```js | ||
@@ -129,3 +161,5 @@ module.exports = { | ||
``` | ||
2. Before parsing an AsyncAPI document with a parser, register the additional custom schema parser: | ||
```js | ||
@@ -159,2 +193,15 @@ const myCustomParser = require('mycustomParser'); | ||
## Custom extensions | ||
The parser uses custom extensions to define additional information about the spec. Each has a different purpose but all of them are there to make it much easier to work with the AsyncAPI document. These extensions are prefixed with `x-parser-`. The following extensions are used : | ||
- `x-parser-spec-parsed` is used to specify if the AsyncAPI document is already parsed by the parser. Property `x-parser-spec-parsed` is added to the root of the document with the `true` value. | ||
- `x-parser-message-parsed` is used to specify if the message is already parsed by the message parser. Property `x-parser-message-parsed` is added to the root of the document with the `true` value. | ||
- `x-parser-message-name` is used to specify the name of the message if it is not provided. For messages without names, the parser generates anonymous names. Property `x-parser-message-name` is added to a message object with a value that follows this pattern: `<anonymous-message-${number}>`. This value is returned by `message.uid()` when regular `name` property is not present. | ||
- `x-parser-schema-id` is used to specify the ID of the schema if it is not provided. For schemas without IDs, the parser generates anonymous names. Property `x-parser-schema-id` is added to every object of a schema with a value that follows this pattern: `<anonymous-schema-${number}>`. This value is returned by `schema.uid()` when regular `$id` property is not present. | ||
- `x-parser-original-traits` is where traits are stored after they are applied on the AsyncAPI document. The reason is because the original `traits` property is removed. | ||
- `x-parser-original-schema-format` holds information about the original schema format of the payload. You can use different schema formats with the AsyncAPI documents and the parser converts them to AsyncAPI schema. This is why different schema format is set, and the original one is preserved in the extension. | ||
- `x-parser-original-payload` holds the original payload of the message. You can use different formats for payloads with the AsyncAPI documents and the parser converts them to. For example, it converts payload described with Avro schema to AsyncAPI schema. The original payload is preserved in the extension. | ||
- [`x-parser-circular`](#circular-references) | ||
- [`x-parser-circular-props`](#circular-references) | ||
## Circular references | ||
@@ -215,2 +262,2 @@ | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! |
@@ -1076,3 +1076,3 @@ /** | ||
*/ | ||
function parse(asyncapiYAMLorJSON: string, options?: { | ||
function parse(asyncapiYAMLorJSON: string | any, options?: { | ||
path?: string; | ||
@@ -1079,0 +1079,0 @@ parse?: any; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1151128
257