Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@asyncapi/parser

Package Overview
Dependencies
Maintainers
3
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/parser - npm Package Compare versions

Comparing version 1.0.0-rc.1 to 1.0.0-rc.2

17

lib/models/asyncapi.js

@@ -12,2 +12,3 @@ const { createMapOfType, getMapValueOfType, addExtensions } = require('../utils');

const xParserCircle = 'x-parser-circular';
const xParserCircleProps = 'x-parser-circular-props';

@@ -302,4 +303,8 @@ /**

*/
function markCircular(schema) {
schema.json()[String(xParserCircle)] = true;
function markCircular(schema, prop) {
if (schema.type() === 'array') return schema.json()[String(xParserCircle)] = true;
const circPropsList = schema.json()[String(xParserCircleProps)] || [];
circPropsList.push(prop);
schema.json()[String(xParserCircleProps)] = circPropsList;
}

@@ -338,4 +343,4 @@

function crawl(schema, seenObj, callback) {
if (schema.isCircular() || isCircular(schema, seenObj)) return true;
if (isCircular(schema, seenObj)) return true;
seenObj.push(schema.json());

@@ -434,4 +439,4 @@ callback(schema);

const props = schema.properties();
for (const [, propertySchema] of Object.entries(props)) {
if (crawl(propertySchema, seenObj, callback)) markCircular(schema);
for (const [prop, propertySchema] of Object.entries(props)) {
if (crawl(propertySchema, seenObj, callback)) markCircular(schema, prop);
}

@@ -438,0 +443,0 @@ }

@@ -372,4 +372,18 @@ const { createMapOfType, addExtensions } = require('../utils');

}
/**
* @returns {boolean}
*/
hasCircularProps() {
return !!this.ext('x-parser-circular-props');
}
/**
* @returns {string[]}
*/
circularProps() {
return this.ext('x-parser-circular-props');
}
}
module.exports = addExtensions(Schema);
{
"name": "@asyncapi/parser",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "JavaScript AsyncAPI parser.",

@@ -18,3 +18,4 @@ "main": "lib/index.js",

"get-version": "echo $npm_package_version",
"lint": "eslint --max-warnings 0 --config .eslintrc ."
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"gen-readme-toc": "markdown-toc -i README.md"
},

@@ -53,3 +54,4 @@ "bugs": {

"tsd-jsdoc": "^2.5.0",
"uglify-es": "^3.3.9"
"uglify-es": "^3.3.9",
"markdown-toc": "^1.2.0"
},

@@ -56,0 +58,0 @@ "dependencies": {

@@ -5,19 +5,34 @@ <h5 align="center">

<br>
JS Parser
JavaScript Parser
</h5>
<h4 align="center">Parse and validate AsyncAPI documents</h4>
<p align="center">
<em>Use this package to parse and validate AsyncAPI documents โ€”either YAML or JSONโ€” in your Node.js or browser application. Updated bundle for the browser is always attached to the GitHub Release.</em>
</p>
---
![npm](https://img.shields.io/npm/v/@asyncapi/parser?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/parser?style=for-the-badge)
## :loudspeaker: ATTENTION:
> :warning: This package doesn't support AsyncAPI 1.x anymore. We recommend to upgrade to the latest AsyncAPI version using the [AsyncAPI converter](https://github.com/asyncapi/converter-js). If you need to convert documents on the fly, you may use the [Node.js](https://github.com/asyncapi/converter-js) or [Go](https://github.com/asyncapi/converter-go) converters.
This package is under development and it has not reached version 1.0.0 yet, what means its API might change without prior notice. Once it reaches its first stable version, we'll follow semantic versioning.
<!-- toc is generated with GitHub Actions do not remove toc markers -->
---
<!-- toc -->
Use this package to parse and validate AsyncAPI documents โ€”either YAML or JSONโ€” in your Node.js or browser application. Updated bundle for the browser is always attached to the GitHub Release.
- [Install](#install)
- [Examples](#examples)
* [Example passing inline AsyncAPI](#example-passing-inline-asyncapi)
* [Example passing a URL](#example-passing-a-url)
* [Example using Avro schemas](#example-using-avro-schemas)
* [Example using OpenAPI schemas](#example-using-openapi-schemas)
* [Example using RAML data types](#example-using-raml-data-types)
- [API documentation](#api-documentation)
- [Custom message parsers](#custom-message-parsers)
- [Error types](#error-types)
- [Circular references](#circular-references)
- [Develop](#develop)
- [Contributing](#contributing)
- [Contributors](#contributors)
> This package doesn't support AsyncAPI 1.x.
<!-- tocstop -->
### Install
## Install

@@ -28,10 +43,6 @@ ```

### API
## Examples
[Check out the API page](./API.md).
### Example passing inline AsyncAPI
### Examples
##### Example passing inline AsyncAPI
```js

@@ -65,3 +76,3 @@ const parser = require('@asyncapi/parser');

##### Example passing a URL
### Example passing a URL

@@ -77,12 +88,20 @@ ```js

##### Example using OpenAPI schemas
### Example using Avro schemas
Head over to [asyncapi/avro-schema-parser](https://www.github.com/asyncapi/avro-schema-parser) for more information.
### Example using OpenAPI schemas
Head over to [asyncapi/openapi-schema-parser](https://www.github.com/asyncapi/openapi-schema-parser) for more information.
##### Example using RAML data types
### Example using RAML data types
Head over to [asyncapi/raml-dt-schema-parser](https://www.github.com/asyncapi/raml-dt-schema-parser) for more information.
### Custom message parsers
## API documentation
See [API documentation](/API.md) for more example and full API reference information.
## Custom message parsers
AsyncAPI doesn't enforce one schema format for messages. You can have payload of your messages described with OpenAPI, Avro, etc. This parser by default parses only AsyncAPI schema format. You can extend it by creating a custom parser and registering it withing the parser:

@@ -110,3 +129,3 @@

2. Before parsing an AsyncAPI document with a parser, register the additional custom schema parser:
```
```js
const myCustomParser = require('mycustomParser');

@@ -117,3 +136,3 @@

### Error types
## Error types

@@ -139,13 +158,14 @@ This package throws a bunch of different error types. All errors contain a `type` (prefixed by this repo URL) and a `title` field. The following table describes all the errors and the extra fields they include:

### Circular references
## Circular references
Parser dereferences all circular references by default. In addition, to simplify interactions with the parser, the following is added:
- `x-parser-circular` property is added to the root of the AsyncAPI document to indicate that the document contains circular references. Tooling developer that doesn't want to support circular references can use the `hasCircular` method to check the document and provide a proper message to the user.
- `x-parser-circular` property is added to every schema where circular reference starts. You should use `isCircular` method on a Schema model like `document.components().schema('RecursiveSelf').properties()['selfChildren'].isCircular()`.
- `x-parser-circular` property is added to the root of the AsyncAPI document to indicate that the document contains circular references. Tooling developer that doesn't want to support circular references can use the `hasCircular()` function to check the document and provide a proper message to the user.
- `x-parser-circular` property is added to every schema of array type that is circular. To check if schema is circular or not, you should use `isCircular()` function on a Schema model like `document.components().schema('RecursiveSelf').properties()['selfChildren'].isCircular()`.
- `x-parser-circular-props` property is added to every schema of object type with a list of properties that are circular. To check if a schema has properties with circular references, you should use `hasCircularProps()` function. To get a list of properties with circular references, you should use `circularProps()` function.
### Develop
## Develop
1. Run tests with `npm test`
1. Write code and tests.
1. Make sure all tests pass `npm test`
1. Make sure code is well formatted and secure `npm run lint`

@@ -156,2 +176,29 @@ Release regenerates API documentation and browser bundle, so you do not have to regenerate it manually with `npm run docs` and `npm run prepublishOnly`.

Read [CONTRIBUTING](CONTRIBUTING.md) guide.
Read [CONTRIBUTING](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md) guide.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="http://www.fmvilas.com/"><img src="https://avatars3.githubusercontent.com/u/242119?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fran Mรฉndez</b></sub></a><br /><a href="#question-fmvilas" title="Answering Questions">๐Ÿ’ฌ</a> <a href="https://github.com/asyncapi/@asyncapi/parser/issues?q=author%3Afmvilas" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=fmvilas" title="Code">๐Ÿ’ป</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=fmvilas" title="Documentation">๐Ÿ“–</a> <a href="#ideas-fmvilas" title="Ideas, Planning, & Feedback">๐Ÿค”</a> <a href="#maintenance-fmvilas" title="Maintenance">๐Ÿšง</a> <a href="#plugin-fmvilas" title="Plugin/utility libraries">๐Ÿ”Œ</a> <a href="https://github.com/asyncapi/@asyncapi/parser/pulls?q=is%3Apr+reviewed-by%3Afmvilas" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=fmvilas" title="Tests">โš ๏ธ</a></td>
<td align="center"><a href="https://resume.github.io/?derberg"><img src="https://avatars1.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="#question-derberg" title="Answering Questions">๐Ÿ’ฌ</a> <a href="https://github.com/asyncapi/@asyncapi/parser/issues?q=author%3Aderberg" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=derberg" title="Code">๐Ÿ’ป</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=derberg" title="Documentation">๐Ÿ“–</a> <a href="#ideas-derberg" title="Ideas, Planning, & Feedback">๐Ÿค”</a> <a href="#maintenance-derberg" title="Maintenance">๐Ÿšง</a> <a href="https://github.com/asyncapi/@asyncapi/parser/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=derberg" title="Tests">โš ๏ธ</a></td>
<td align="center"><a href="https://github.com/jonaslagoni"><img src="https://avatars1.githubusercontent.com/u/13396189?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Lagoni</b></sub></a><br /><a href="#question-jonaslagoni" title="Answering Questions">๐Ÿ’ฌ</a> <a href="https://github.com/asyncapi/@asyncapi/parser/issues?q=author%3Ajonaslagoni" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=jonaslagoni" title="Code">๐Ÿ’ป</a> <a href="#ideas-jonaslagoni" title="Ideas, Planning, & Feedback">๐Ÿค”</a> <a href="https://github.com/asyncapi/@asyncapi/parser/pulls?q=is%3Apr+reviewed-by%3Ajonaslagoni" title="Reviewed Pull Requests">๐Ÿ‘€</a></td>
<td align="center"><a href="https://github.com/magicmatatjahu"><img src="https://avatars2.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maciej Urbaล„czyk</b></sub></a><br /><a href="https://github.com/asyncapi/@asyncapi/parser/issues?q=author%3Amagicmatatjahu" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=magicmatatjahu" title="Code">๐Ÿ’ป</a> <a href="https://github.com/asyncapi/@asyncapi/parser/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests">๐Ÿ‘€</a></td>
</tr>
<tr>
<td align="center"><a href="https://www.inmensia.com/"><img src="https://avatars2.githubusercontent.com/u/6494060?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juan Mellado</b></sub></a><br /><a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=jcmellado" title="Code">๐Ÿ’ป</a></td>
<td align="center"><a href="https://www.jamescrowley.net/"><img src="https://avatars1.githubusercontent.com/u/509533?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Crowley</b></sub></a><br /><a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=jamescrowley" title="Code">๐Ÿ’ป</a></td>
<td align="center"><a href="https://github.com/rmelian"><img src="https://avatars3.githubusercontent.com/u/4565267?v=4?s=100" width="100px;" alt=""/><br /><sub><b>raisel melian</b></sub></a><br /><a href="https://github.com/asyncapi/@asyncapi/parser/commits?author=rmelian" title="Code">๐Ÿ’ป</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

@@ -352,2 +352,4 @@ declare module "@asyncapi/parser" {

isCircular(): boolean;
hasCircularProps(): boolean;
circularProps(): string[];
}

@@ -354,0 +356,0 @@ /**

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc