Skip to content

Commit 9788515

Browse files
authored
docs: docs generation and modify readme (#31)
1 parent d7443c9 commit 9788515

13 files changed

+1409
-17
lines changed

API.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## Classes
2+
3+
<dl>
4+
<dt><a href="#AsyncAPIDiff">AsyncAPIDiff</a></dt>
5+
<dd><p>Implements methods to deal with diff output.</p>
6+
</dd>
7+
</dl>
8+
9+
## Functions
10+
11+
<dl>
12+
<dt><a href="#diff">diff(firstDocument, secondDocument, config)</a> ⇒ <code><a href="#AsyncAPIDiff">AsyncAPIDiff</a></code></dt>
13+
<dd><p>Generates diff between two AsyncAPI documents</p>
14+
</dd>
15+
</dl>
16+
17+
<a name="AsyncAPIDiff"></a>
18+
19+
## AsyncAPIDiff
20+
Implements methods to deal with diff output.
21+
22+
**Kind**: global class
23+
24+
* [AsyncAPIDiff](#AsyncAPIDiff)
25+
* [.breaking()](#AsyncAPIDiff+breaking) ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
26+
* [.nonBreaking()](#AsyncAPIDiff+nonBreaking) ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
27+
* [.unclassified()](#AsyncAPIDiff+unclassified) ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
28+
* [.getOutput()](#AsyncAPIDiff+getOutput) ⇒ <code>Output</code>
29+
30+
<a name="AsyncAPIDiff+breaking"></a>
31+
32+
### asyncAPIDiff.breaking() ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
33+
**Kind**: instance method of [<code>AsyncAPIDiff</code>](#AsyncAPIDiff)
34+
**Returns**: <code>Array.&lt;DiffOutputItem&gt;</code> - All the breaking changes
35+
<a name="AsyncAPIDiff+nonBreaking"></a>
36+
37+
### asyncAPIDiff.nonBreaking() ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
38+
**Kind**: instance method of [<code>AsyncAPIDiff</code>](#AsyncAPIDiff)
39+
**Returns**: <code>Array.&lt;DiffOutputItem&gt;</code> - All the non-breaking changes
40+
<a name="AsyncAPIDiff+unclassified"></a>
41+
42+
### asyncAPIDiff.unclassified() ⇒ <code>Array.&lt;DiffOutputItem&gt;</code>
43+
**Kind**: instance method of [<code>AsyncAPIDiff</code>](#AsyncAPIDiff)
44+
**Returns**: <code>Array.&lt;DiffOutputItem&gt;</code> - All the unclassified changes
45+
<a name="AsyncAPIDiff+getOutput"></a>
46+
47+
### asyncAPIDiff.getOutput() ⇒ <code>Output</code>
48+
**Kind**: instance method of [<code>AsyncAPIDiff</code>](#AsyncAPIDiff)
49+
**Returns**: <code>Output</code> - The JSON output
50+
<a name="diff"></a>
51+
52+
## diff(firstDocument, secondDocument, config) ⇒ [<code>AsyncAPIDiff</code>](#AsyncAPIDiff)
53+
Generates diff between two AsyncAPI documents
54+
55+
**Kind**: global function
56+
**Returns**: [<code>AsyncAPIDiff</code>](#AsyncAPIDiff) - The diff data
57+
58+
| Param | Type | Description |
59+
| --- | --- | --- |
60+
| firstDocument | | The parsed AsyncAPI document |
61+
| secondDocument | | The parsed AsyncAPI document |
62+
| config | <code>Object</code> | Configuration options |
63+
| [config.override] | <code>Object</code> | Object to override the standard |
64+
65+
**Example**
66+
```js
67+
const output = diff(firstDocument, secondDocument, {
68+
override: {
69+
'/servers': {
70+
add: 'non-breaking', // when a property has been added in the AsyncAPI document
71+
remove: 'breaking', // when a property has been removed from the AsyncAPI document
72+
edit: 'unclassified' // when a property has been edited in the AsyncAPI document
73+
}
74+
}
75+
})
76+
```

README.md

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,112 @@
1-
# diff
1+
<h5 align="center">
2+
<a href="https://www.asyncapi.org"><img src="https://github.com/asyncapi/parser-nodejs/raw/master/assets/logo.png" alt="AsyncAPI logo" width="200"></a>
3+
<br>
4+
Diff
5+
</h5>
6+
<p align="center">
7+
<em>
8+
AsyncDiff is a library that compares two AsyncAPI files and provides information about the differences by pointing out explicitly information like breaking changes.
9+
</em>
10+
</p>
211

3-
AsyncDiff is a library which compares two AsyncAPI Documents and provides information about the differences by pointing out explicitly informations like breaking changes.
12+
![npm](https://img.shields.io/npm/v/@asyncapi/diff?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/diff?style=for-the-badge)
413

5-
## Note
14+
<!-- toc is generated with GitHub Actions do not remove toc markers -->
615

7-
The library doesn't have a built-in parser to parse the given AsyncAPI document. Thus, users have to make sure they provide the valid & dereferenced AsyncAPI document as the input.
16+
<!-- toc -->
817

9-
Users can use the [AsyncAPI parser](https://github.com/asyncapi/parser-js) to parse the document, or they can use other tools. Though they **must** make sure that the document is valid & dereferenced in case they use other tools to parse the documents.
18+
- [Installation](#installation)
19+
- [Usage](#usage)
20+
- [Standard object](#standard-object)
21+
- [Overriding the standard](#overriding-the-standard)
22+
- [Example](#example)
23+
- [API](#api)
24+
- [Develop](#develop)
25+
- [Contributing](#contributing)
26+
27+
<!-- tocstop -->
28+
29+
## Installation
30+
31+
```
32+
npm install @asyncapi/diff
33+
```
34+
35+
## Usage
36+
37+
**NOTE:** The library doesn't have a built-in parser to parse the given AsyncAPI document. Thus, you have to make sure they provide the valid & dereferenced AsyncAPI document as an input. You can use the [AsyncAPI parser](https://github.com/asyncapi/parser-js) to parse and validate the AsyncAPI file first. You can use other tools, but you **must** make sure that the document is valid and dereferenced.
38+
39+
```js
40+
import { diff } from '@asyncapi/diff'; // const { diff } = require('@asyncapi/diff');
41+
42+
const output = diff(firstDocument, secondDocument, {
43+
overrides: {
44+
// object to override the standard
45+
},
46+
});
47+
```
48+
49+
## Standard object
50+
51+
This library has a pre-configured standard which marks a change as `breaking`, `non-breaking` or `unclassified`. This standard data is stored as an object inside the [`standard.ts`](https://github.com/asyncapi/diff/blob/master/src/standard.ts) file.
52+
53+
The format of this standard object is explained in [this](standard-format.md) document.
54+
55+
### Overriding the standard
56+
57+
To understand the format of overriding object, take a look at [this](standard-format.md) document.
58+
59+
The overrides object must be passed in the following format:
60+
61+
```
62+
{
63+
[jsonPointer]: {
64+
add: 'breaking' | 'non-breaking' | 'unclassified'
65+
remove: 'breaking' | 'non-breaking' | 'unclassified'
66+
edit: 'breaking' | 'non-breaking' | 'unclassified'
67+
}
68+
}
69+
```
70+
71+
## Example
72+
73+
See the [API](API.md) document to get all the helper methods this library offers.
74+
75+
1. Without any overrides
76+
77+
```js
78+
const output = diff(firstDocument, secondDocument);
79+
80+
output.getOutput(); // the whole output data
81+
output.breaking(); // the breaking changes
82+
output.nonBreaking(); // the non-breaking changes
83+
output.unclassified(); // the unclassified changes
84+
```
85+
86+
2. With overrides
87+
88+
```js
89+
const output = diff(firstDocument, secondDocument, {
90+
overrides: {
91+
'/servers/*/protocol': {
92+
add: 'non-breaking',
93+
remove: 'breaking',
94+
edit: 'unclassified',
95+
},
96+
},
97+
});
98+
```
99+
100+
## API
101+
102+
Checkout the [API](API.md) document to see all the APIs this library offers.
103+
104+
## Develop
105+
106+
1. Write code and tests
107+
2. Make sure all tests pass `npm run test`
108+
3. Make sure code is well formatted and secure `npm run lint`
109+
110+
## Contributing
111+
112+
Help us make this library more robust. Read [CONTRIBUTING](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md) guide & start contributing.

0 commit comments

Comments
 (0)