Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resolution of $refs in subdirectories #181

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
<dd></dd>
</dl>

## Members

<dl>
<dt><a href="#resolve">resolve</a> ⇒ <code>boolean</code></dt>
<dd></dd>
</dl>

## Functions

<dl>
Expand All @@ -25,23 +18,22 @@
**Kind**: global class

* [Document](#Document)
* [new Document(parsedJSONList, base)](#new_Document_new)
* [new Document(AsyncAPIObject)](#new_Document_new)
* [.json()](#Document+json) ⇒ <code>Object</code>
* [.yml()](#Document+yml) ⇒ <code>string</code>
* [.string()](#Document+string) ⇒ <code>string</code>

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

### new Document(parsedJSONList, base)
### new Document(AsyncAPIObject)

| Param | Type |
| --- | --- |
| parsedJSONList | <code>Array.&lt;Object&gt;</code> |
| base | <code>Object</code> |
| AsyncAPIObject | <code>Object</code> |

**Example**
```js
const document = new Document(parsedJSONList, base);
const document = new Document(bundledDocument);

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

### document.string() ⇒ <code>string</code>
**Kind**: instance method of [<code>Document</code>](#Document)
<a name="resolve"></a>

## resolve ⇒ <code>boolean</code>
**Kind**: global variable

| Param | Type |
| --- | --- |
| asyncapiDocument | <code>AsyncAPIObject</code> |

<a name="bundle"></a>

## bundle(files, [options]) ⇒ [<code>Document</code>](#Document)
Expand Down
14 changes: 11 additions & 3 deletions example/bundle-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ import { writeFileSync } from 'fs';
import bundle from '@asyncapi/bundler';

async function main() {
const document = await bundle(['./main.yaml'], {
xOrigin: true,
const files = [
'send/lightTurnOn/asyncapi.yaml',
'send/lightTurnOff/asyncapi.yaml',
'receive/lightingMeasured/asyncapi.yaml',
];

const document = await bundle(files, {
base: 'index.yaml',
baseDir: 'example-with-nested-dirs/asyncapi',
xOrigin: false,
});
if (document.yml()) {
writeFileSync('asyncapi.yaml', document.yml());
writeFileSync('bundled.yaml', document.yml());
}
}

Expand Down
21 changes: 21 additions & 0 deletions example/example-with-nested-dirs/asyncapi/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
asyncapi: 3.0.0
info:
title: Streetlights MQTT API
version: 1.0.0
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"
license:
name: Apache 2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0'
defaultContentType: application/json
servers:
production:
host: 'test.mosquitto.org:{port}'
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Lighting Measured 1.0.0 documentation


## Operations

### RECEIVE `smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured` Operation

*Inform about environmental lighting conditions of a particular streetlight.*

* Operation ID: `receiveLightMeasurement`

The topic on which measured values may be produced and consumed.

#### Parameters

| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| streetlightId | string | The ID of the streetlight. | - | - | **required** |


#### Message Light measured `lightMeasured`

*Inform about environmental lighting conditions of a particular streetlight.*

* Message ID: `lightMeasured`
* Content type: [application/json](https://www.iana.org/assignments/media-types/application/json)

##### Payload

| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | object | - | - | - | **additional properties are allowed** |
| lumens | integer | Light intensity measured in lumens. | - | >= 0 | - |
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |

> Examples of payload _(generated)_

```json
{
"lumens": 0,
"sentAt": "2019-08-24T14:15:22Z"
}
```



Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
asyncapi: 3.0.0
info:
title: Lighting Measured
version: 1.0.0
channels:
lightingMeasured:
address: 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
messages:
lightMeasured:
$ref: '#/components/messages/lightMeasured'
description: The topic on which measured values may be produced and consumed.
parameters:
streetlightId:
description: The ID of the streetlight.
operations:
receiveLightMeasurement:
action: receive
channel:
$ref: '#/channels/lightingMeasured'
summary: >-
Inform about environmental lighting conditions of a particular
streetlight.
messages:
- $ref: '#/channels/lightingMeasured/messages/lightMeasured'
components:
messages:
lightMeasured:
name: lightMeasured
title: Light measured
summary: >-
Inform about environmental lighting conditions of a particular
streetlight.
contentType: application/json
payload:
$ref: ./schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"lumens": {
"type": "integer",
"minimum": 0,
"description": "Light intensity measured in lumens."
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Light Turn Off 1.0.0 documentation


## Operations

### SEND `smartylighting/streetlights/1/0/action/{streetlightId}/turn/off` Operation

* Operation ID: `turnOff`

#### Message Turn on/off `turnOnOff`

*Command a particular streetlight to turn the lights on or off.*

##### Payload

| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | object | - | - | - | **additional properties are allowed** |
| command | string | Whether to turn on or off the light. | allowed (`"on"`, `"off"`) | - | - |
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |

> Examples of payload _(generated)_

```json
{
"command": "on",
"sentAt": "2019-08-24T14:15:22Z"
}
```



Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
asyncapi: 3.0.0
info:
title: Light Turn Off
version: 1.0.0
channels:
lightTurnOff:
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off'
messages:
turnOff:
$ref: '#/components/messages/turnOnOff'
operations:
turnOff:
action: send
channel:
$ref: '#/channels/lightTurnOff'
messages:
- $ref: '#/channels/lightTurnOff/messages/turnOff'
components:
messages:
turnOnOff:
name: turnOnOff
title: Turn on/off
summary: Command a particular streetlight to turn the lights on or off.
payload:
$ref: ./schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"command": {
"type": "string",
"enum": [
"on",
"off"
],
"description": "Whether to turn on or off the light."
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Light Turn On 1.0.0 documentation


## Operations

### SEND `smartylighting/streetlights/1/0/action/{streetlightId}/turn/on` Operation

* Operation ID: `turnOn`

#### Message Turn on/off `turnOnOff`

*Command a particular streetlight to turn the lights on or off.*

##### Payload

| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | object | - | - | - | **additional properties are allowed** |
| command | string | Whether to turn on or off the light. | allowed (`"on"`, `"off"`) | - | - |
| sentAt | string | Date and time when the message was sent. | - | format (`date-time`) | - |

> Examples of payload _(generated)_

```json
{
"command": "on",
"sentAt": "2019-08-24T14:15:22Z"
}
```



Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
asyncapi: 3.0.0
info:
title: Light Turn On
version: 1.0.0
channels:
lightTurnOn:
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on'
messages:
turnOn:
$ref: '#/components/messages/turnOnOff'
operations:
turnOn:
action: send
channel:
$ref: '#/channels/lightTurnOn'
messages:
- $ref: '#/channels/lightTurnOn/messages/turnOn'
components:
messages:
turnOnOff:
name: turnOnOff
title: Turn on/off
summary: Command a particular streetlight to turn the lights on or off.
payload:
$ref: ./schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"command": {
"type": "string",
"enum": [
"on",
"off"
],
"description": "Whether to turn on or off the light."
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "npm run start:cjs && npm run start:esm && npm run start:ts",
"start:cjs": "node bundle-cjs.cjs",
Expand Down
Loading
Loading