Skip to content

Commit e41d6e4

Browse files
authored
feat: add resolution of $refs in subdirectories (#181)
1 parent 7d70682 commit e41d6e4

File tree

30 files changed

+964
-139
lines changed

30 files changed

+964
-139
lines changed

API.md

+4-21
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
<dd></dd>
66
</dl>
77

8-
## Members
9-
10-
<dl>
11-
<dt><a href="#resolve">resolve</a> ⇒ <code>boolean</code></dt>
12-
<dd></dd>
13-
</dl>
14-
158
## Functions
169

1710
<dl>
@@ -25,23 +18,22 @@
2518
**Kind**: global class
2619

2720
* [Document](#Document)
28-
* [new Document(parsedJSONList, base)](#new_Document_new)
21+
* [new Document(AsyncAPIObject)](#new_Document_new)
2922
* [.json()](#Document+json) ⇒ <code>Object</code>
3023
* [.yml()](#Document+yml) ⇒ <code>string</code>
3124
* [.string()](#Document+string) ⇒ <code>string</code>
3225

3326
<a name="new_Document_new"></a>
3427

35-
### new Document(parsedJSONList, base)
28+
### new Document(AsyncAPIObject)
3629

3730
| Param | Type |
3831
| --- | --- |
39-
| parsedJSONList | <code>Array.&lt;Object&gt;</code> |
40-
| base | <code>Object</code> |
32+
| AsyncAPIObject | <code>Object</code> |
4133

4234
**Example**
4335
```js
44-
const document = new Document(parsedJSONList, base);
36+
const document = new Document(bundledDocument);
4537

4638
console.log(document.json()); // get JSON object
4739
console.log(document.yml()); // get YAML string
@@ -59,15 +51,6 @@ console.log(document.string()); // get JSON string
5951

6052
### document.string() ⇒ <code>string</code>
6153
**Kind**: instance method of [<code>Document</code>](#Document)
62-
<a name="resolve"></a>
63-
64-
## resolve ⇒ <code>boolean</code>
65-
**Kind**: global variable
66-
67-
| Param | Type |
68-
| --- | --- |
69-
| asyncapiDocument | <code>AsyncAPIObject</code> |
70-
7154
<a name="bundle"></a>
7255

7356
## bundle(files, [options]) ⇒ [<code>Document</code>](#Document)

example/bundle-esm.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ import { writeFileSync } from 'fs';
1111
import bundle from '@asyncapi/bundler';
1212

1313
async function main() {
14-
const document = await bundle(['./main.yaml'], {
15-
xOrigin: true,
14+
const files = [
15+
'send/lightTurnOn/asyncapi.yaml',
16+
'send/lightTurnOff/asyncapi.yaml',
17+
'receive/lightingMeasured/asyncapi.yaml',
18+
];
19+
20+
const document = await bundle(files, {
21+
base: 'index.yaml',
22+
baseDir: 'example-with-nested-dirs/asyncapi',
23+
xOrigin: false,
1624
});
1725
if (document.yml()) {
18-
writeFileSync('asyncapi.yaml', document.yml());
26+
writeFileSync('bundled.yaml', document.yml());
1927
}
2028
}
2129

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Streetlights MQTT API
4+
version: 1.0.0
5+
description: "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n### Check out its awesome features:\n\n* Turn a specific streetlight on/off \U0001F303\n* Dim a specific streetlight \U0001F60E\n* Receive real-time information about environmental lighting conditions \U0001F4C8\n"
6+
license:
7+
name: Apache 2.0
8+
url: 'https://www.apache.org/licenses/LICENSE-2.0'
9+
defaultContentType: application/json
10+
servers:
11+
production:
12+
host: 'test.mosquitto.org:{port}'
13+
protocol: mqtt
14+
description: Test broker
15+
variables:
16+
port:
17+
description: Secure connection (TLS) is available through port 8883.
18+
default: '1883'
19+
enum:
20+
- '1883'
21+
- '8883'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Lighting Measured 1.0.0 documentation
2+
3+
4+
## Operations
5+
6+
### RECEIVE `smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured` Operation
7+
8+
*Inform about environmental lighting conditions of a particular streetlight.*
9+
10+
* Operation ID: `receiveLightMeasurement`
11+
12+
The topic on which measured values may be produced and consumed.
13+
14+
#### Parameters
15+
16+
| Name | Type | Description | Value | Constraints | Notes |
17+
|---|---|---|---|---|---|
18+
| streetlightId | string | The ID of the streetlight. | - | - | **required** |
19+
20+
21+
#### Message Light measured `lightMeasured`
22+
23+
*Inform about environmental lighting conditions of a particular streetlight.*
24+
25+
* Message ID: `lightMeasured`
26+
* Content type: [application/json](https://www.iana.org/assignments/media-types/application/json)
27+
28+
##### Payload
29+
30+
| Name | Type | Description | Value | Constraints | Notes |
31+
|---|---|---|---|---|---|
32+
| (root) | object | - | - | - | **additional properties are allowed** |
33+
| lumens | integer | Light intensity measured in lumens. | - | >= 0 | - |
34+
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |
35+
36+
> Examples of payload _(generated)_
37+
38+
```json
39+
{
40+
"lumens": 0,
41+
"sentAt": "2019-08-24T14:15:22Z"
42+
}
43+
```
44+
45+
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Lighting Measured
4+
version: 1.0.0
5+
channels:
6+
lightingMeasured:
7+
address: 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
8+
messages:
9+
lightMeasured:
10+
$ref: '#/components/messages/lightMeasured'
11+
description: The topic on which measured values may be produced and consumed.
12+
parameters:
13+
streetlightId:
14+
description: The ID of the streetlight.
15+
operations:
16+
receiveLightMeasurement:
17+
action: receive
18+
channel:
19+
$ref: '#/channels/lightingMeasured'
20+
summary: >-
21+
Inform about environmental lighting conditions of a particular
22+
streetlight.
23+
messages:
24+
- $ref: '#/channels/lightingMeasured/messages/lightMeasured'
25+
components:
26+
messages:
27+
lightMeasured:
28+
name: lightMeasured
29+
title: Light measured
30+
summary: >-
31+
Inform about environmental lighting conditions of a particular
32+
streetlight.
33+
contentType: application/json
34+
payload:
35+
$ref: ./schema.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"lumens": {
6+
"type": "integer",
7+
"minimum": 0,
8+
"description": "Light intensity measured in lumens."
9+
},
10+
"sentAt": {
11+
"type": "string",
12+
"format": "date-time",
13+
"description": "Date and time when the message was sent."
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Light Turn Off 1.0.0 documentation
2+
3+
4+
## Operations
5+
6+
### SEND `smartylighting/streetlights/1/0/action/{streetlightId}/turn/off` Operation
7+
8+
* Operation ID: `turnOff`
9+
10+
#### Message Turn on/off `turnOnOff`
11+
12+
*Command a particular streetlight to turn the lights on or off.*
13+
14+
##### Payload
15+
16+
| Name | Type | Description | Value | Constraints | Notes |
17+
|---|---|---|---|---|---|
18+
| (root) | object | - | - | - | **additional properties are allowed** |
19+
| command | string | Whether to turn on or off the light. | allowed (`"on"`, `"off"`) | - | - |
20+
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |
21+
22+
> Examples of payload _(generated)_
23+
24+
```json
25+
{
26+
"command": "on",
27+
"sentAt": "2019-08-24T14:15:22Z"
28+
}
29+
```
30+
31+
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Light Turn Off
4+
version: 1.0.0
5+
channels:
6+
lightTurnOff:
7+
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off'
8+
messages:
9+
turnOff:
10+
$ref: '#/components/messages/turnOnOff'
11+
operations:
12+
turnOff:
13+
action: send
14+
channel:
15+
$ref: '#/channels/lightTurnOff'
16+
messages:
17+
- $ref: '#/channels/lightTurnOff/messages/turnOff'
18+
components:
19+
messages:
20+
turnOnOff:
21+
name: turnOnOff
22+
title: Turn on/off
23+
summary: Command a particular streetlight to turn the lights on or off.
24+
payload:
25+
$ref: ./schema.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"command": {
6+
"type": "string",
7+
"enum": [
8+
"on",
9+
"off"
10+
],
11+
"description": "Whether to turn on or off the light."
12+
},
13+
"sentAt": {
14+
"type": "string",
15+
"format": "date-time",
16+
"description": "Date and time when the message was sent."
17+
}
18+
}
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Light Turn On 1.0.0 documentation
2+
3+
4+
## Operations
5+
6+
### SEND `smartylighting/streetlights/1/0/action/{streetlightId}/turn/on` Operation
7+
8+
* Operation ID: `turnOn`
9+
10+
#### Message Turn on/off `turnOnOff`
11+
12+
*Command a particular streetlight to turn the lights on or off.*
13+
14+
##### Payload
15+
16+
| Name | Type | Description | Value | Constraints | Notes |
17+
|---|---|---|---|---|---|
18+
| (root) | object | - | - | - | **additional properties are allowed** |
19+
| command | string | Whether to turn on or off the light. | allowed (`"on"`, `"off"`) | - | - |
20+
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |
21+
22+
> Examples of payload _(generated)_
23+
24+
```json
25+
{
26+
"command": "on",
27+
"sentAt": "2019-08-24T14:15:22Z"
28+
}
29+
```
30+
31+
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Light Turn On
4+
version: 1.0.0
5+
channels:
6+
lightTurnOn:
7+
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on'
8+
messages:
9+
turnOn:
10+
$ref: '#/components/messages/turnOnOff'
11+
operations:
12+
turnOn:
13+
action: send
14+
channel:
15+
$ref: '#/channels/lightTurnOn'
16+
messages:
17+
- $ref: '#/channels/lightTurnOn/messages/turnOn'
18+
components:
19+
messages:
20+
turnOnOff:
21+
name: turnOnOff
22+
title: Turn on/off
23+
summary: Command a particular streetlight to turn the lights on or off.
24+
payload:
25+
$ref: ./schema.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"command": {
6+
"type": "string",
7+
"enum": [
8+
"on",
9+
"off"
10+
],
11+
"description": "Whether to turn on or off the light."
12+
},
13+
"sentAt": {
14+
"type": "string",
15+
"format": "date-time",
16+
"description": "Date and time when the message was sent."
17+
}
18+
}
19+
}

example/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
78
"start": "npm run start:cjs && npm run start:esm && npm run start:ts",
89
"start:cjs": "node bundle-cjs.cjs",

0 commit comments

Comments
 (0)